goto.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. $(".banner-slider").slick({
  2. speed: 1000,
  3. swipe: true,
  4. arrows: false,
  5. });
  6. $(".content1-right").slick({
  7. dotsClass: 'slick-dots',
  8. dots: true,
  9. speed: 1000,
  10. arrows: false,
  11. });
  12. // // gototop 下滑效果
  13. $(".arrow").hide();
  14. $(window).scroll(function () {
  15. var y = window.scrollY;
  16. if (y > 10) {
  17. $(".arrow").show();
  18. } else {
  19. $(".arrow").hide();
  20. }
  21. });
  22. // content輪播圖片偵測效果
  23. $(".text-1").addClass("contant-toggle");
  24. $(".content1-right").on('beforeChange', function (event, slick, currentSlide, nextSlide) {
  25. console.log('beforeChangeEvent: currenSlide=' + currentSlide + ', nextSlide= ' + nextSlide);
  26. if (nextSlide == 1) {
  27. $(".text-1").removeClass("contant-toggle");
  28. $(".text-2").addClass("contant-toggle");
  29. $(".text-3").removeClass("contant-toggle");
  30. } else if (nextSlide == 2) {
  31. $(".text-2").removeClass("contant-toggle");
  32. $(".text-1").removeClass("contant-toggle");
  33. $(".text-3").addClass("contant-toggle");
  34. } else if (nextSlide == 0) {
  35. $(".text-2").removeClass("contant-toggle");
  36. $(".text-1").addClass("contant-toggle");
  37. $(".text-3").removeClass("contant-toggle");
  38. }
  39. });
  40. $.fn.serializeObject = function () {
  41. var o = {};
  42. var a = this.serializeArray();
  43. o["id"] = 0;
  44. o["time_stamp"] = "";
  45. $.each(a, function () {
  46. if (o[this.name]) {
  47. if (!o[this.name].push) {
  48. o[this.name] = [o[this.name]];
  49. }
  50. o[this.name].push(this.value || '');
  51. } else {
  52. o[this.name] = this.value || '';
  53. }
  54. });
  55. return o;
  56. };
  57. // email 格式檢查
  58. $(document).ready(function () {
  59. //E-MAIL格式檢查
  60. $("body").on("change", "#email", function () {
  61. $Emailchecking = IsEmail($("#email").val());
  62. if ($Emailchecking == false) {
  63. alert("請填寫正確的E-MAIL格式");
  64. // $("#email").blur(); //離開焦點
  65. }
  66. })
  67. function IsEmail(email) {
  68. var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  69. if (!regex.test(email)) {
  70. return false;
  71. } else {
  72. // return true;
  73. }
  74. }
  75. });
  76. // phone 格式檢查
  77. $(document).ready(function () {
  78. // phone格式檢查
  79. $("body").on("change", "#phone", function () {
  80. $Phonechecking = IsPhone($("#phone").val());
  81. if ($Phonechecking == false) {
  82. alert("請填寫正確的手機格式");
  83. // $("#email").blur(); //離開焦點
  84. }
  85. })
  86. function IsPhone(phone) {
  87. var regex = /^[09]{2}[0-9]{8}$/;
  88. if (!regex.test(phone)) {
  89. return false;
  90. } else {
  91. // return true;
  92. }
  93. }
  94. });
  95. $(".contact-form1").submit(function (e) {
  96. /* var formRef = $('#form1').serializeArray();
  97. var jsonString = JSON.stringify(formRef);*/
  98. var jsonInfo = $('.contact-form1').serializeObject();
  99. var jsonString = JSON.stringify(jsonInfo);
  100. console.log(jsonString);
  101. $.ajax({
  102. type: 'POST',
  103. url: 'https://go.hhh.com.tw:8001/deco_request_detail',
  104. data: jsonString,
  105. dataType: 'json',
  106. success: function (data) {
  107. console.log('送出成功: ' + data);
  108. if (data == 0) {
  109. alert("送出成功");
  110. } else if (data == 1) {
  111. alert("此email已填過表單");
  112. } else if (data == 2) {
  113. alert("此phone已填過表單");
  114. } else if (data == 3) {
  115. alert("此email、phone已填過表單");
  116. }
  117. location.reload();
  118. },
  119. beforeSend: function () {
  120. console.log('beforeSend');
  121. },
  122. complete: function () {
  123. console.log('complete');
  124. },
  125. error: function (jqXHR, textStatus, errorThrown) {
  126. console.log(JSON.stringify(jqXHR));
  127. console.log("AJAX errr: " + textStatus + ' : ' + errorThrown);
  128. console.log('送出失敗: ' + jqXHR.responseText);
  129. alert("送出失敗");
  130. }
  131. });
  132. return false;
  133. });
  134. $("*").each(function (index, element) {
  135. // 此元素被點選後執行
  136. $(this).click(function (e) {
  137. // 取得被點選元素的屬性:data-gt-target
  138. var target = $(this).attr("data-gt-target");
  139. var duration = $(this).attr("data-gt-duration");
  140. var offset = $(this).attr("data-gt-offset");
  141. // JS 語法:判斷式
  142. // if (條件) {程式區塊}
  143. // 當條件成立,會執行程式區塊
  144. // 如果 目標有資料 才會執行 { } 內的程式
  145. // 避免出現 undefine (未定義 - 不存在的資料)
  146. if (target) {
  147. //console.log("目標:" + target);
  148. //console.log("時間:" + duration);
  149. //console.log("位移:" + offset);
  150. // 上方位置 = 目標區塊.位移().上方位置
  151. var top = $(target).offset().top;
  152. //console.log("要前往元素的上方位置:" + top);
  153. // 網頁元素.停止().動畫({ 上方捲動:指定元素 - 位移},持續時間)
  154. // parseInt() 將文字轉為數字
  155. $("html").stop().animate({
  156. scrollTop: top - offset
  157. }, parseInt(duration));
  158. }
  159. });
  160. });
  161. // 避免動畫與使用者滾輪衝突
  162. // html 在滾動滾輪時 停止 html 所有效果
  163. $("html").on("mousewheel", function () {
  164. $("html").stop();
  165. });
  166. $(document).ready(function () {
  167. $("#date").datepicker();
  168. });
  169. // // javascript document
  170. // // This is called with the results from from FB.getLoginStatus().
  171. // function statusChangeCallback(response) {
  172. // console.log('statusChangeCallback');
  173. // console.log(response);
  174. // // The response object is returned with a status field that lets the
  175. // // app know the current login status of the persopren.
  176. // // Full docs on the response object can be found in the documentation
  177. // // for FB.getLoginStatus().
  178. // if (response.status === 'connected') {
  179. // // Logged into your app and Facebook.
  180. // login(response.authResponse.accessToken);
  181. // } else if (response.status === 'not_authorized') {
  182. // // The person is logged into Facebook, but not your app.
  183. // console.log('The person is logged into Facebook, but not your app');
  184. // } else {
  185. // // The person is not logged into Facebook, so we're not sure if
  186. // // they are logged into this app or not.
  187. // console.log("The person is not logged into Facebook");
  188. // }
  189. // }
  190. // // This function is called when someone finishes with the Login
  191. // // Button. See the onlogin handler attached to it in the sample
  192. // // code below.
  193. // function checkLoginState() {
  194. // FB.getLoginStatus(function (response) {
  195. // statusChangeCallback(response);
  196. // });
  197. // }
  198. // window.fbAsyncInit = function () {
  199. // FB.init({
  200. // appId: '1388696554848391',
  201. // cookie: true, // enable cookies to allow the server to access
  202. // // the session
  203. // xfbml: true, // parse social plugins on this page
  204. // version: 'v11.0' // use version 2.2
  205. // });
  206. // };
  207. // // Now that we've initialized the JavaScript SDK, we call
  208. // // FB.getLoginStatus(). This function gets the state of the
  209. // // person visiting this page and can return one of three states to
  210. // // the callback you provide. They can be:
  211. // //
  212. // // 1. Logged into your app ('connected')
  213. // // 2. Logged into Facebook, but not your app ('not_authorized')
  214. // // 3. Not logged into Facebook and can't tell if they are logged into
  215. // // your app or not.
  216. // //
  217. // // These three cases are handled in the callback function.
  218. // // Load the SDK asynchronously
  219. // (function (d, s, id) {
  220. // var js, fjs = d.getElementsByTagName(s)[0];
  221. // if (d.getElementById(id)) return;
  222. // js = d.createElement(s); js.id = id;
  223. // js.src = "//connect.facebook.net/en_US/sdk.js";
  224. // fjs.parentNode.insertBefore(js, fjs);
  225. // }(document, "script", "facebook-jssdk"));
  226. // // Here we run a very simple test of the Graph API after login is
  227. // // successful. See statusChangeCallback() for when this call is made.
  228. // function loginNEMI(token) {
  229. // // 把 access_token 傳至後端再做資料拿取
  230. // console.log("Welcome! Fetching your information.... ");
  231. // var xhr = new XMLHttpRequest();
  232. // xhr.open("POST", "/login", true);
  233. // xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  234. // xhr.onreadystatechange = function () {
  235. // if (xhr.readyState === 4 && xhr.status === 200) {
  236. // if (JSON.parse(xhr.responseText).status === "ok")
  237. // location.href = "/index";
  238. // else
  239. // alert("something wrong!");
  240. // }
  241. // };
  242. // xhr.send("token=" + token);
  243. // }
  244. // $("#fb-button").click(function(){
  245. // FB.login(function (response) {
  246. // statusChangeCallback(response);
  247. // console.log(response);
  248. // }, { scope: 'public_profile,email' });
  249. // // console.log('FB API回傳資料: ' + JSON.stringify(response));
  250. // });
  251. window.fbAsyncInit = function () {
  252. FB.init({
  253. appId: '1388696554848391', // 填入 FB APP ID
  254. cookie: true,
  255. xfbml: true,
  256. version: 'v11.0'
  257. });
  258. FB.getLoginStatus(function (response) {
  259. statusChangeCallback(response);
  260. });
  261. };
  262. // 處理各種登入身份
  263. function statusChangeCallback(response) {
  264. console.log(response);
  265. var target = document.getElementById("FB_STATUS_2"),
  266. html = "";
  267. // 登入 FB 且已加入會員
  268. if (response.status === 'connected') {
  269. html = "已登入 FB,並加入 WFU BLOG DEMO 應用程式<br/>";
  270. FB.api('/me?fields=id,name,email', function (response) {
  271. console.log(response);
  272. html += "會員暱稱:" + response.name + "<br/>";
  273. html += "會員 email:" + response.email;
  274. target.innerHTML = html;
  275. });
  276. }
  277. // 登入 FB, 未偵測到加入會員
  278. else if (response.status === "not_authorized") {
  279. target.innerHTML = "已登入 FB,但未加入 WFU BLOG DEMO 應用程式";
  280. }
  281. // 未登入 FB
  282. else {
  283. target.innerHTML = "未登入 FB";
  284. }
  285. }
  286. // 點擊登入
  287. $("#fb_login").click(function () {
  288. // 進行登入程序
  289. FB.login(function (response) {
  290. statusChangeCallback(response);
  291. }, {
  292. scope: 'public_profile,email'
  293. },
  294. {
  295. scope: 'public_profile,name'
  296. }
  297. );
  298. if (response.id) {
  299. document.getElementById("email").value = response.email;
  300. document.getElementById("name").value = response.name;
  301. // 隱藏FB登入按鈕
  302. document.getElementById("fb_login").style.display = 'none';
  303. }
  304. });
  305. // 點擊登出
  306. // $("#FB_logout").click(function() {
  307. // FB.logout(function(response) {
  308. // statusChangeCallback(response);
  309. // });
  310. // });
  311. // 載入 FB SDK
  312. (function (d, s, id) {
  313. var js, fjs = d.getElementsByTagName(s)[0];
  314. if (d.getElementById(id)) return;
  315. js = d.createElement(s);
  316. js.id = id;
  317. js.src = "https://connect.facebook.net/zh_TW/sdk.js";
  318. fjs.parentNode.insertBefore(js, fjs);
  319. }(document, 'script', 'facebook-jssdk'));