goto.js 8.1 KB

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