goto.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // menu彈跳視窗
  2. $("#menu-box2").hide();
  3. $("#menu-box").hide();
  4. $("#menu-btn1").click(function () {
  5. $("#menu-box").slideToggle("slow");
  6. $("#menu-box2").slideToggle("slow");
  7. });
  8. $(".link").click(function () {
  9. $("#menu-box").slideUp("slow", function () {
  10. $("#menu-box2").slideUp("slow");
  11. // Animation complete.
  12. });
  13. });
  14. $(".feedback-slider1").slick({
  15. dots: true,
  16. dotsClass: 'slick-dots',
  17. speed: 1000,
  18. swipe: true,
  19. });
  20. $(".banner-slider").slick({
  21. dots: true,
  22. dotsClass: 'slick-dots',
  23. speed: 1000,
  24. swipe: true,
  25. });
  26. $.fn.serializeObject = function () {
  27. var o = {};
  28. var a = this.serializeArray();
  29. o["id"] = 0;
  30. o["time_stamp"] = "";
  31. $.each(a, function () {
  32. if (o[this.name]) {
  33. if (!o[this.name].push) {
  34. o[this.name] = [o[this.name]];
  35. }
  36. o[this.name].push(this.value || '');
  37. } else {
  38. o[this.name] = this.value || '';
  39. }
  40. });
  41. return o;
  42. };
  43. // email 格式檢查
  44. $(document).ready(function () {
  45. //E-MAIL格式檢查
  46. $("body").on("change", "#email", function () {
  47. $Emailchecking = IsEmail($("#email").val());
  48. if ($Emailchecking == false) {
  49. alert("請填寫正確的E-MAIL格式");
  50. // $("#email").blur(); //離開焦點
  51. }
  52. })
  53. function IsEmail(email) {
  54. var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  55. if (!regex.test(email)) {
  56. return false;
  57. } else {
  58. return true;
  59. }
  60. }
  61. });
  62. // phone 格式檢查
  63. $(document).ready(function () {
  64. //phone格式檢查
  65. $("body").on("change", "#phone", function () {
  66. $Phonechecking = IsPhone($("#phone").val());
  67. if ($Phonechecking == false) {
  68. alert("請填寫正確的手機格式");
  69. // $("#email").blur(); //離開焦點
  70. }
  71. })
  72. function IsPhone(phone) {
  73. var regex = /^[0-9]+$/;
  74. if (!regex.test(phone)) {
  75. return false;
  76. } else {
  77. return true;
  78. }
  79. }
  80. });
  81. $(".contact-form1").submit(function (e) {
  82. /* var formRef = $('#form1').serializeArray();
  83. var jsonString = JSON.stringify(formRef);*/
  84. var jsonInfo = $('.contact-form1').serializeObject();
  85. var jsonString = JSON.stringify(jsonInfo);
  86. console.log(jsonString);
  87. $.ajax({
  88. type: 'POST',
  89. url: 'https://go.hhh.com.tw:8001/deco_request_detail',
  90. data: jsonString,
  91. dataType: 'json',
  92. success: function (data) {
  93. console.log('送出成功: ' + data);
  94. if (data == 0) {
  95. alert("送出成功");
  96. } else if (data == 1) {
  97. alert("此email已填過表單");
  98. } else if (data == 2) {
  99. alert("此phone已填過表單");
  100. } else if (data == 3) {
  101. alert("此email、phone已填過表單");
  102. }
  103. },
  104. beforeSend: function () {
  105. console.log('beforeSend');
  106. },
  107. complete: function () {
  108. console.log('complete');
  109. },
  110. error: function (jqXHR, textStatus, errorThrown) {
  111. console.log(JSON.stringify(jqXHR));
  112. console.log("AJAX errr: " + textStatus + ' : ' + errorThrown);
  113. console.log('送出失敗: ' + jqXHR.responseText);
  114. }
  115. });
  116. return false;
  117. });
  118. $("*").each(function (index, element) {
  119. // 此元素被點選後執行
  120. $(this).click(function (e) {
  121. // 取得被點選元素的屬性:data-gt-target
  122. var target = $(this).attr("data-gt-target");
  123. var duration = $(this).attr("data-gt-duration");
  124. var offset = $(this).attr("data-gt-offset");
  125. // JS 語法:判斷式
  126. // if (條件) {程式區塊}
  127. // 當條件成立,會執行程式區塊
  128. // 如果 目標有資料 才會執行 { } 內的程式
  129. // 避免出現 undefine (未定義 - 不存在的資料)
  130. if (target) {
  131. //console.log("目標:" + target);
  132. //console.log("時間:" + duration);
  133. //console.log("位移:" + offset);
  134. // 上方位置 = 目標區塊.位移().上方位置
  135. var top = $(target).offset().top;
  136. //console.log("要前往元素的上方位置:" + top);
  137. // 網頁元素.停止().動畫({ 上方捲動:指定元素 - 位移},持續時間)
  138. // parseInt() 將文字轉為數字
  139. $("html").stop().animate({
  140. scrollTop: top - offset
  141. }, parseInt(duration));
  142. }
  143. });
  144. });
  145. // 避免動畫與使用者滾輪衝突
  146. // html 在滾動滾輪時 停止 html 所有效果
  147. $("html").on("mousewheel", function () {
  148. $("html").stop();
  149. });
  150. $(document).ready(function () {
  151. $("#date").datepicker();
  152. });
  153. // // gototop 下滑效果
  154. $(".arrow").hide();
  155. $(window).scroll(function(){
  156. var y = window.scrollY;
  157. if(y>10){
  158. $(".arrow").show();
  159. }else{
  160. $(".arrow").hide();
  161. }
  162. });
  163. function statusChangeCallback(response) {
  164. console.log('statusChangeCallback');
  165. console.log(response);
  166. // The response object is returned with a status field that lets the
  167. // app know the current login status of the persopren.
  168. // Full docs on the response object can be found in the documentation
  169. // for FB.getLoginStatus().
  170. if (response.status === 'connected') {
  171. // Logged into your app and Facebook.
  172. login(response.authResponse.accessToken);
  173. } else if (response.status === 'not_authorized') {
  174. // The person is logged into Facebook, but not your app.
  175. console.log('The person is logged into Facebook, but not your app');
  176. } else {
  177. // The person is not logged into Facebook, so we're not sure if
  178. // they are logged into this app or not.
  179. console.log("The person is not logged into Facebook");
  180. }
  181. }
  182. // This function is called when someone finishes with the Login
  183. // Button. See the onlogin handler attached to it in the sample
  184. // code below.
  185. function checkLoginState() {
  186. FB.getLoginStatus(function (response) {
  187. statusChangeCallback(response);
  188. });
  189. }
  190. window.fbAsyncInit = function () {
  191. FB.init({
  192. appId: '1388696554848391',
  193. cookie: true, // enable cookies to allow the server to access
  194. // the session
  195. xfbml: true, // parse social plugins on this page
  196. version: 'v11.0' // use version 2.2
  197. });
  198. };
  199. // Now that we've initialized the JavaScript SDK, we call
  200. // FB.getLoginStatus(). This function gets the state of the
  201. // person visiting this page and can return one of three states to
  202. // the callback you provide. They can be:
  203. //
  204. // 1. Logged into your app ('connected')
  205. // 2. Logged into Facebook, but not your app ('not_authorized')
  206. // 3. Not logged into Facebook and can't tell if they are logged into
  207. // your app or not.
  208. //
  209. // These three cases are handled in the callback function.
  210. // Load the SDK asynchronously
  211. (function (d, s, id) {
  212. var js, fjs = d.getElementsByTagName(s)[0];
  213. if (d.getElementById(id)) return;
  214. js = d.createElement(s); js.id = id;
  215. js.src = "//connect.facebook.net/en_US/sdk.js";
  216. fjs.parentNode.insertBefore(js, fjs);
  217. }(document, "script", "facebook-jssdk"));
  218. // Here we run a very simple test of the Graph API after login is
  219. // successful. See statusChangeCallback() for when this call is made.
  220. function loginNEMI(token) {
  221. // 把 access_token 傳至後端再做資料拿取
  222. console.log("Welcome! Fetching your information.... ");
  223. var xhr = new XMLHttpRequest();
  224. xhr.open("POST", "/login", true);
  225. xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  226. xhr.onreadystatechange = function () {
  227. if (xhr.readyState === 4 && xhr.status === 200) {
  228. if (JSON.parse(xhr.responseText).status === "ok")
  229. location.href = "/index";
  230. else
  231. alert("something wrong!");
  232. }
  233. };
  234. xhr.send("token=" + token);
  235. }
  236. // custom fb login button
  237. function fb_login() {
  238. // FB 第三方登入,要求公開資料與email
  239. FB.login(function (response) {
  240. statusChangeCallback(response);
  241. console.log(response);
  242. }, { scope: 'public_profile,email' });
  243. }