goto.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. alert(jsonString);
  102. $.ajax({
  103. type: 'POST',
  104. url: 'https://go.hhh.com.tw:8001/deco_request_detail',
  105. data: jsonString,
  106. dataType: 'json',
  107. success: function (data) {
  108. console.log('送出成功: ' + data);
  109. alert("送出成功");
  110. if (data == 0) {
  111. alert("送出成功");
  112. } else if (data == 1) {
  113. alert("此email已填過表單");
  114. } else if (data == 2) {
  115. alert("此phone已填過表單");
  116. } else if (data == 3) {
  117. alert("此email、phone已填過表單");
  118. }
  119. },
  120. beforeSend: function () {
  121. console.log('beforeSend');
  122. },
  123. complete: function () {
  124. console.log('complete');
  125. },
  126. error: function (jqXHR, textStatus, errorThrown) {
  127. console.log(JSON.stringify(jqXHR));
  128. console.log("AJAX errr: " + textStatus + ' : ' + errorThrown);
  129. console.log('送出失敗: ' + jqXHR.responseText);
  130. alert("送出失敗");
  131. }
  132. });
  133. return false;
  134. });
  135. $("*").each(function (index, element) {
  136. // 此元素被點選後執行
  137. $(this).click(function (e) {
  138. // 取得被點選元素的屬性:data-gt-target
  139. var target = $(this).attr("data-gt-target");
  140. var duration = $(this).attr("data-gt-duration");
  141. var offset = $(this).attr("data-gt-offset");
  142. // JS 語法:判斷式
  143. // if (條件) {程式區塊}
  144. // 當條件成立,會執行程式區塊
  145. // 如果 目標有資料 才會執行 { } 內的程式
  146. // 避免出現 undefine (未定義 - 不存在的資料)
  147. if (target) {
  148. //console.log("目標:" + target);
  149. //console.log("時間:" + duration);
  150. //console.log("位移:" + offset);
  151. // 上方位置 = 目標區塊.位移().上方位置
  152. var top = $(target).offset().top;
  153. //console.log("要前往元素的上方位置:" + top);
  154. // 網頁元素.停止().動畫({ 上方捲動:指定元素 - 位移},持續時間)
  155. // parseInt() 將文字轉為數字
  156. $("html").stop().animate({
  157. scrollTop: top - offset
  158. }, parseInt(duration));
  159. }
  160. });
  161. });
  162. // 避免動畫與使用者滾輪衝突
  163. // html 在滾動滾輪時 停止 html 所有效果
  164. $("html").on("mousewheel", function () {
  165. $("html").stop();
  166. });
  167. $(document).ready(function () {
  168. $("#date").datepicker();
  169. });
  170. // javascript document
  171. // This is called with the results from from FB.getLoginStatus().
  172. function statusChangeCallback(response) {
  173. console.log('statusChangeCallback');
  174. console.log(response);
  175. // The response object is returned with a status field that lets the
  176. // app know the current login status of the persopren.
  177. // Full docs on the response object can be found in the documentation
  178. // for FB.getLoginStatus().
  179. if (response.status === 'connected') {
  180. // Logged into your app and Facebook.
  181. login(response.authResponse.accessToken);
  182. } else if (response.status === 'not_authorized') {
  183. // The person is logged into Facebook, but not your app.
  184. console.log('The person is logged into Facebook, but not your app');
  185. } else {
  186. // The person is not logged into Facebook, so we're not sure if
  187. // they are logged into this app or not.
  188. console.log("The person is not logged into Facebook");
  189. }
  190. }
  191. // This function is called when someone finishes with the Login
  192. // Button. See the onlogin handler attached to it in the sample
  193. // code below.
  194. function checkLoginState() {
  195. FB.getLoginStatus(function (response) {
  196. statusChangeCallback(response);
  197. });
  198. }
  199. window.fbAsyncInit = function () {
  200. FB.init({
  201. appId: '1388696554848391',
  202. cookie: true, // enable cookies to allow the server to access
  203. // the session
  204. xfbml: true, // parse social plugins on this page
  205. version: 'v11.0' // use version 2.2
  206. });
  207. };
  208. // Now that we've initialized the JavaScript SDK, we call
  209. // FB.getLoginStatus(). This function gets the state of the
  210. // person visiting this page and can return one of three states to
  211. // the callback you provide. They can be:
  212. //
  213. // 1. Logged into your app ('connected')
  214. // 2. Logged into Facebook, but not your app ('not_authorized')
  215. // 3. Not logged into Facebook and can't tell if they are logged into
  216. // your app or not.
  217. //
  218. // These three cases are handled in the callback function.
  219. // Load the SDK asynchronously
  220. (function (d, s, id) {
  221. var js, fjs = d.getElementsByTagName(s)[0];
  222. if (d.getElementById(id)) return;
  223. js = d.createElement(s); js.id = id;
  224. js.src = "//connect.facebook.net/en_US/sdk.js";
  225. fjs.parentNode.insertBefore(js, fjs);
  226. }(document, "script", "facebook-jssdk"));
  227. // Here we run a very simple test of the Graph API after login is
  228. // successful. See statusChangeCallback() for when this call is made.
  229. function loginNEMI(token) {
  230. // 把 access_token 傳至後端再做資料拿取
  231. console.log("Welcome! Fetching your information.... ");
  232. var xhr = new XMLHttpRequest();
  233. xhr.open("POST", "/login", true);
  234. xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  235. xhr.onreadystatechange = function () {
  236. if (xhr.readyState === 4 && xhr.status === 200) {
  237. if (JSON.parse(xhr.responseText).status === "ok")
  238. location.href = "/index";
  239. else
  240. alert("something wrong!");
  241. }
  242. };
  243. xhr.send("token=" + token);
  244. }
  245. // custom fb login button
  246. function fb_login() {
  247. // FB 第三方登入,要求公開資料與email
  248. FB.login(function (response) {
  249. statusChangeCallback(response);
  250. console.log(response);
  251. }, { scope: 'public_profile,email' });
  252. }