goto.js 7.4 KB

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