goto.js 7.3 KB

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