main-grammar.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  1. $(document).ready(function(){
  2. $(window).scroll(function(){
  3. var pos = $(window).scrollTop();
  4. if(pos >= 30){
  5. $('.main-header').css('position','fixed');
  6. $('.main-header').css('top','0');
  7. }else{
  8. $('.main-header').css('position','relative');
  9. $('.main-header').css('top','0');
  10. }
  11. });
  12. $("input[name='loginRememberPassword']").change(function(){
  13. if($(this).prop("checked") == true){
  14. $(this).parent().css("color", "#4c87ed");
  15. }else{
  16. $(this).parent().css("color", "#4b4b4b");
  17. }
  18. })
  19. //Effect for login input
  20. $('#loginModal').on('shown.bs.modal', function () {
  21. $("input[name='loginEmail']").focus()
  22. });
  23. //Effect for login input
  24. $(document).on('click','.loginNameInputText',function(){
  25. $(this).prev().focus();
  26. });
  27. //Effect for login input
  28. $(document).on('focusin',".loginInputText",function(){
  29. if(!$(this).next().hasClass('loginFocusInput')){
  30. $(this).next().addClass('loginFocusInput');
  31. }
  32. });
  33. //Effect for login input loginHasText
  34. $(document).on('focusout',".loginInputText", outInput);
  35. $(".loginInputText").focusout(outInput);
  36. var checkOutInput = 1;
  37. function outInput(){
  38. if(checkOutInput == 1){
  39. if($(this).next().hasClass('loginFocusInput')){
  40. $(this).next().removeClass('loginFocusInput');
  41. }
  42. if($(this).next().hasClass('loginHasText') && $(this).val() == ''){
  43. $(this).next().removeClass('loginHasText');
  44. }
  45. if(!$(this).next().hasClass('loginHasText') && $(this).val() != ''){
  46. $(this).next().addClass('loginHasText');
  47. }
  48. checkOutInput = 0;
  49. setTimeout(function() {
  50. checkOutInput = 1;
  51. }, 50);
  52. }
  53. }
  54. //Effect for login button
  55. $("input[name='loginEmail'], input[name='loginPassword']").on("keyup", function(){
  56. if(checkRegisterEmail($("input[name='loginEmail']").val())
  57. && $("input[name='loginPassword']").val() != ''){
  58. $(".loginButtonSubmit").addClass("loginSuccess");
  59. }else{
  60. $(".loginButtonSubmit").removeClass("loginSuccess");
  61. }
  62. });
  63. $(document).on('keypress',"input[name='loginEmail'], input[name='loginPassword']" ,function(e){
  64. if(e.keyCode == 13){
  65. $( ".loginButtonSubmit" ).trigger( "click" );
  66. }
  67. });
  68. //Ajax for login
  69. $(".loginButtonSubmit").click(function(){
  70. $(".loginValidationError").css('display', 'none');
  71. var email = $("input[name='loginEmail']").val();
  72. var password = $("input[name='loginPassword']").val();
  73. var rememberPassword = $("input[name='loginRememberPassword']").is(':checked')?1:0;
  74. var url = $(this).attr('url');
  75. if(email == ''){
  76. $(".dontEnterEmail").css('display', 'block');
  77. return false;
  78. }else{
  79. $(".dontEnterEmail").css('display', 'none');
  80. }
  81. if(!checkRegisterEmail(email)){
  82. $(".loginEmailInvalid").css('display', 'block');
  83. return false;
  84. }else{
  85. $(".loginEmailInvalid").css('display', 'none');
  86. }
  87. if(password == ''){
  88. $(".dontEnterPassword").css('display', 'block');
  89. return false;
  90. }else{
  91. $(".dontEnterPassword").css('display', 'none');
  92. }
  93. $.ajaxSetup({
  94. headers: {
  95. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  96. }
  97. });
  98. $.ajax({
  99. url: url,
  100. type: "POST",
  101. data: {
  102. loginEmail: email,
  103. loginPassword: password,
  104. loginRememberPassword: rememberPassword
  105. },
  106. success: function(result){
  107. if(result[0] == 'success'){
  108. //location.reload(true);
  109. window.location.href = result[1];
  110. }else if(result[0] == 'error'){
  111. if(result[1].length >= 2000){
  112. $('body').find('#register-msg-modal').prev('style').remove();
  113. $('body').find('#register-msg-modal').remove();
  114. $('body').append(result[1]);
  115. $('#register-msg-modal').modal();
  116. $('#loginModal').modal('hide');
  117. }else{
  118. $(".loginValidationError").css('display', 'block');
  119. $(".loginValidationError p").text(result[1]);
  120. }
  121. return false;
  122. }
  123. //Check validate
  124. if(result.loginEmail != undefined){
  125. $(".loginEmailInvalid").css('display', 'block');
  126. }else{
  127. $(".loginEmailInvalid").css('display', 'none');
  128. }
  129. if(result.loginPassword != undefined){
  130. $(".loginValidationError").css('display', 'block');
  131. $(".loginValidationError p").text(result.loginPassword[0]);
  132. }else{
  133. $(".loginValidationError").css('display', 'none');
  134. }
  135. },
  136. error: function(data){
  137. var errors = data.responseJSON;
  138. if(errors != undefined){
  139. if(errors.loginEmail != undefined){
  140. $(".loginEmailInvalid").css('display', 'block');
  141. //$(".loginEmailInvalid p").text(errors.loginEmail[0]);
  142. return false;
  143. }else{
  144. $(".loginEmailInvalid").css('display', 'none');
  145. }
  146. if(errors.loginPassword != undefined){
  147. $(".loginValidationError").css('display', 'block');
  148. $(".loginValidationError p").text(errors.loginPassword[0]);
  149. return false;
  150. }else{
  151. $(".loginValidationError").css('display', 'none');
  152. }
  153. }
  154. }
  155. });
  156. });
  157. //Effect for register input
  158. $("input[name='registerName']").keyup(function(){
  159. if(checkRegisterName($(this).val())){
  160. $(this).parent().find('.registerCheckSuccess').css('opacity', '1');
  161. }else{
  162. $(this).parent().find('.registerCheckSuccess').css('opacity', '0');
  163. }
  164. });
  165. $("input[name='registerEmail']").keyup(function(){
  166. if(checkRegisterEmail($(this).val())){
  167. $(this).parent().find('.registerCheckSuccess').css('opacity', '1');
  168. }else{
  169. $(this).parent().find('.registerCheckSuccess').css('opacity', '0');
  170. }
  171. });
  172. $("input[name='registerPassword']").keyup(function(){
  173. if(checkRegisterPassword($(this).val())){
  174. $(this).parent().find('.registerCheckSuccess').css('opacity', '1');
  175. }else{
  176. $(this).parent().find('.registerCheckSuccess').css('opacity', '0');
  177. }
  178. });
  179. //Effect for register button
  180. $("input[name='registerName'], input[name='registerEmail'], input[name='registerPassword'], input[name='registerCaptcha'], input[name='registerAgreeVocaRule']").on("keyup change", function(){
  181. if(checkRegisterName($("input[name='registerName']").val())
  182. && checkRegisterEmail($("input[name='registerEmail']").val())
  183. && checkRegisterPassword($("input[name='registerPassword']").val())
  184. && $("input[name='registerCaptcha']").val() != ''
  185. && $("input[name='registerAgreeVocaRule']").prop("checked")){
  186. $(".registerButtonSubmit").addClass("registerSuccess");
  187. }else{
  188. $(".registerButtonSubmit").removeClass("registerSuccess");
  189. }
  190. });
  191. $("#loginModal input, #registerModal input, #forgotPasswordModal input, #activeCodeModal input").on('keyup', function(){
  192. $(this).parent().find(".loginErrorInput").css("display", "none");
  193. });
  194. $("input[name='registerCaptcha']").on('keyup', function(){
  195. $(".registerCaptchaIncorrect").css('display', 'none');
  196. $(".registerDontEnterCaptcha").css('display', 'none');
  197. });
  198. //Effect for login input
  199. $('#registerModal').on('shown.bs.modal', function () {
  200. $("input[name='registerName']").focus();
  201. $('#registerModal .registerResetCaptcha').click();
  202. });
  203. $(".loginDontAccount").click(function(){
  204. $('#registerModal').modal('show');
  205. setTimeout(function(){
  206. $("body").addClass("modal-open");
  207. },500);
  208. });
  209. $(".loginForgotPassword").click(function(){
  210. $('#forgotPasswordModal').modal('show');
  211. setTimeout(function(){
  212. $("body").addClass("modal-open");
  213. },500);
  214. });
  215. $(document).on('keypress',"input[name='registerName'], input[name='registerEmail'], input[name='registerPassword'], input[name='registerCaptcha']" ,function(e){
  216. if(e.keyCode == 13){
  217. $( ".registerButtonSubmit" ).trigger( "click" );
  218. }
  219. });
  220. $("input[name='loginEmail']").focusout(function(){
  221. var email = $("input[name='loginEmail']").val();
  222. if(email == ''){
  223. $(".dontEnterEmail").css('display', 'block');
  224. return false;
  225. }else{
  226. $(".dontEnterEmail").css('display', 'none');
  227. }
  228. });
  229. $("input[name='loginPassword']").focusout(function(){
  230. var password = $("input[name='loginPassword']").val();
  231. if(password == ''){
  232. $(".dontEnterPassword").css('display', 'block');
  233. return false;
  234. }else{
  235. $(".dontEnterPassword").css('display', 'none');
  236. }
  237. });
  238. $("input[name='registerName']").focusout(function(){
  239. var name = $("input[name='registerName']").val();
  240. if(name == ''){
  241. $(".registerDontEnterName").css('display', 'block');
  242. return false;
  243. }else{
  244. $(".registerDontEnterName").css('display', 'none');
  245. }
  246. if(name.length < 5){
  247. $(".registerNameShort").css('display', 'block');
  248. return false;
  249. }else{
  250. $(".registerNameShort").css('display', 'none');
  251. }
  252. if(name.length >= 255){
  253. $(".registerNameLong").css('display', 'block');
  254. return false;
  255. }else{
  256. $(".registerNameLong").css('display', 'none');
  257. }
  258. });
  259. $("input[name='registerEmail']").focusout(function(){
  260. var email = $("input[name='registerEmail']").val();
  261. if(email == ''){
  262. $(".registerDontEnterEmail").css('display', 'block');
  263. return false;
  264. }else{
  265. $(".registerDontEnterEmail").css('display', 'none');
  266. }
  267. if(!checkRegisterEmail(email)){
  268. $(".registerEmailInvalid").css('display', 'block');
  269. return false;
  270. }else{
  271. $(".registerEmailInvalid").css('display', 'none');
  272. }
  273. });
  274. $("input[name='registerPassword']").focusout(function(){
  275. var password = $("input[name='registerPassword']").val();
  276. if(password == ''){
  277. $(".registerDontEnterPassword").css('display', 'block');
  278. return false;
  279. }else{
  280. $(".registerDontEnterPassword").css('display', 'none');
  281. }
  282. if(password.length < 6){
  283. $(".registerPasswordShort").css('display', 'block');
  284. return false;
  285. }else{
  286. $(".registerPasswordShort").css('display', 'none');
  287. }
  288. if(password.length >= 255){
  289. $(".registerPasswordLong").css('display', 'block');
  290. return false;
  291. }else{
  292. $(".registerPasswordLong").css('display', 'none');
  293. }
  294. });
  295. $("input[name='registerCaptcha']").focusout(function(){
  296. var captcha = $("input[name='registerCaptcha']").val();
  297. if(captcha == ''){
  298. $(".registerDontEnterCaptcha").css('display', 'block');
  299. return false;
  300. }else{
  301. $(".registerDontEnterCaptcha").css('display', 'none');
  302. }
  303. });
  304. //Ajax for REGISTER
  305. $(".registerButtonSubmit").click(function(){
  306. $(".registerValidationError").css('display', 'none');
  307. $(".registerEmailExist").css('display', 'none');
  308. $(".registerCaptchaIncorrect").css('display', 'none');
  309. var name = $("input[name='registerName']").val();
  310. var email = $("input[name='registerEmail']").val();
  311. var password = $("input[name='registerPassword']").val();
  312. var captcha = $("input[name='registerCaptcha']").val();
  313. var confirmAgree = $("input[name='registerAgreeVocaRule']").is(':checked')?1:0;
  314. var url = $(this).attr('url');
  315. if(name == ''){
  316. $(".registerDontEnterName").css('display', 'block');
  317. return false;
  318. }else{
  319. $(".registerDontEnterName").css('display', 'none');
  320. }
  321. if(name.length < 5){
  322. $(".registerNameShort").css('display', 'block');
  323. return false;
  324. }else{
  325. $(".registerNameShort").css('display', 'none');
  326. }
  327. if(name.length >= 255){
  328. $(".registerNameLong").css('display', 'block');
  329. return false;
  330. }else{
  331. $(".registerNameLong").css('display', 'none');
  332. }
  333. if(email == ''){
  334. $(".registerDontEnterEmail").css('display', 'block');
  335. return false;
  336. }else{
  337. $(".registerDontEnterEmail").css('display', 'none');
  338. }
  339. if(!checkRegisterEmail(email)){
  340. $(".registerEmailInvalid").css('display', 'block');
  341. return false;
  342. }else{
  343. $(".registerEmailInvalid").css('display', 'none');
  344. }
  345. if(password == ''){
  346. $(".registerDontEnterPassword").css('display', 'block');
  347. return false;
  348. }else{
  349. $(".registerDontEnterPassword").css('display', 'none');
  350. }
  351. if(password.length < 6){
  352. $(".registerPasswordShort").css('display', 'block');
  353. return false;
  354. }else{
  355. $(".registerPasswordShort").css('display', 'none');
  356. }
  357. if(password.length >= 255){
  358. $(".registerPasswordLong").css('display', 'block');
  359. return false;
  360. }else{
  361. $(".registerPasswordLong").css('display', 'none');
  362. }
  363. if(captcha == ''){
  364. $(".registerDontEnterCaptcha").css('display', 'block');
  365. return false;
  366. }else{
  367. $(".registerDontEnterCaptcha").css('display', 'none');
  368. }
  369. if(confirmAgree == 0){
  370. $(".registerDontConfirm").css('display', 'block');
  371. return false;
  372. }else{
  373. $(".registerDontConfirm").css('display', 'none');
  374. }
  375. $.ajaxSetup({
  376. headers: {
  377. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  378. }
  379. });
  380. $.ajax({
  381. url: url,
  382. type: "POST",
  383. data: {
  384. registerName: name,
  385. registerEmail: email,
  386. registerPassword: password,
  387. registerCaptcha: captcha
  388. },
  389. success: function(result){
  390. $('#registerModal .registerResetCaptcha').click();
  391. if(result[0] == 'success'){
  392. window.location.href = result[1];
  393. }else if(result[0] == 'error'){
  394. $(".registerValidationError").css('display', 'block');
  395. $(".registerValidationError p").text(result[1]);
  396. }
  397. //Check validate
  398. if(result.registerEmail != undefined){
  399. $(".registerEmailExist").css('display', 'block');
  400. $("input[name='registerEmail']").focus();
  401. return false;
  402. }
  403. if(result.registerCaptcha != undefined){
  404. $(".registerCaptchaIncorrect").css('display', 'block');
  405. $("input[name='registerCaptcha']").focus();
  406. return false;
  407. }
  408. },
  409. error: function(data){
  410. var error = data.responseJSON;
  411. if(error != undefined){
  412. $('#registerModal .registerResetCaptcha').click();
  413. if(error.registerEmail != undefined){
  414. $(".registerEmailExist").css('display', 'block');
  415. $("input[name='registerEmail']").focus();
  416. return false;
  417. }
  418. if(error.registerCaptcha != undefined){
  419. $(".registerCaptchaIncorrect").css('display', 'block');
  420. $("input[name='registerCaptcha']").focus();
  421. return false;
  422. }
  423. }
  424. }
  425. });
  426. });
  427. $(document).on('click','.register-get-active', function(){
  428. var url = $(this).attr('url');
  429. $.ajax({
  430. url: url,
  431. type: "GET",
  432. success: function(result){
  433. $('body').find('#activeCodeModal').remove();
  434. $('body').append(result);
  435. $('#activeCodeModal').modal();
  436. $('#register-msg-modal').modal('hide');
  437. }
  438. });
  439. });
  440. //Effect for login button
  441. $("input[name='forgotPasswordEmail'], input[name='forgotPasswordCaptcha']").on("keyup", function(){
  442. if(checkRegisterEmail($("input[name='forgotPasswordEmail']").val())
  443. && $("input[name='forgotPasswordCaptcha']").val() != ''){
  444. $(".forgotPasswordButtonSubmit").addClass("forgotPasswordSuccess");
  445. }else{
  446. $(".forgotPasswordButtonSubmit").removeClass("forgotPasswordSuccess");
  447. }
  448. });
  449. //Effect for login button
  450. $(document).on("keyup","input[name='activeCodeEmail'], input[name='activeCodeCaptcha']", function(){
  451. if(checkRegisterEmail($("input[name='activeCodeEmail']").val())
  452. && $("input[name='activeCodeCaptcha']").val() != ''){
  453. $(".activeCodeButtonSubmit").addClass("activeCodeSuccess");
  454. }else{
  455. $(".activeCodeButtonSubmit").removeClass("activeCodeSuccess");
  456. }
  457. });
  458. $(document).on('keypress',"input[name='forgotPasswordEmail'], input[name='forgotPasswordCaptcha']" ,function(e){
  459. if(e.keyCode == 13){
  460. $( ".forgotPasswordButtonSubmit" ).trigger( "click" );
  461. }
  462. });
  463. $(document).on('keypress',"input[name='activeCodeEmail'], input[name='activeCodeCaptcha']" ,function(e){
  464. if(e.keyCode == 13){
  465. $( ".activeCodeButtonSubmit" ).trigger( "click" );
  466. }
  467. });
  468. $("input[name='forgotPasswordEmail']").focusout(function(){
  469. var email = $("input[name='forgotPasswordEmail']").val();
  470. if(email == ''){
  471. $(".forgotPasswordDontEnterEmail").css('display', 'block');
  472. return false;
  473. }else{
  474. $(".forgotPasswordDontEnterEmail").css('display', 'none');
  475. }
  476. if(!checkRegisterEmail(email)){
  477. $(".forgotPasswordEmailInvalid").css('display', 'block');
  478. return false;
  479. }else{
  480. $(".forgotPasswordEmailInvalid").css('display', 'none');
  481. }
  482. });
  483. $("input[name='activeCodeEmail']").focusout(function(){
  484. var email = $("input[name='activeCodeEmail']").val();
  485. if(email == ''){
  486. $(".activeCodeDontEnterEmail").css('display', 'block');
  487. return false;
  488. }else{
  489. $(".activeCodeDontEnterEmail").css('display', 'none');
  490. }
  491. if(!checkRegisterEmail(email)){
  492. $(".activeCodeEmailInvalid").css('display', 'block');
  493. return false;
  494. }else{
  495. $(".activeCodeEmailInvalid").css('display', 'none');
  496. }
  497. });
  498. $("input[name='forgotPasswordCaptcha']").focusout(function(){
  499. var captcha = $("input[name='forgotPasswordCaptcha']").val();
  500. if(captcha == ''){
  501. $(".forgotPasswordDontEnterCaptcha").css('display', 'block');
  502. return false;
  503. }else{
  504. $(".forgotPasswordDontEnterCaptcha").css('display', 'none');
  505. }
  506. });
  507. $("input[name='activeCodeCaptcha']").focusout(function(){
  508. var captcha = $("input[name='activeCodeCaptcha']").val();
  509. if(captcha == ''){
  510. $(".activeCodeDontEnterCaptcha").css('display', 'block');
  511. return false;
  512. }else{
  513. $(".activeCodeDontEnterCaptcha").css('display', 'none');
  514. }
  515. });
  516. $('#forgotPasswordModal').on('shown.bs.modal', function () {
  517. $('#forgotPasswordModal .registerResetCaptcha').click();
  518. });
  519. //Ajax for FORGOT PASSWORD
  520. $(".forgotPasswordButtonSubmit").click(function(){
  521. $(".forgotPasswordCaptchaIncorrect").css('display', 'none');
  522. var email = $("input[name='forgotPasswordEmail']").val();
  523. var captcha = $("input[name='forgotPasswordCaptcha']").val();
  524. var url = $(this).attr('url');
  525. if(email == ''){
  526. $(".forgotPasswordDontEnterEmail").css('display', 'block');
  527. return false;
  528. }else{
  529. $(".forgotPasswordDontEnterEmail").css('display', 'none');
  530. }
  531. if(!checkRegisterEmail(email)){
  532. $(".forgotPasswordEmailInvalid").css('display', 'block');
  533. return false;
  534. }else{
  535. $(".forgotPasswordEmailInvalid").css('display', 'none');
  536. }
  537. if(captcha == ''){
  538. $(".forgotPasswordDontEnterCaptcha").css('display', 'block');
  539. return false;
  540. }else{
  541. $(".forgotPasswordDontEnterCaptcha").css('display', 'none');
  542. }
  543. $.ajaxSetup({
  544. headers: {
  545. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  546. }
  547. });
  548. $.ajax({
  549. url: url,
  550. type: "POST",
  551. data: {
  552. forgotPasswordEmail: email,
  553. forgotPasswordCaptcha: captcha
  554. },
  555. success: function(result){
  556. $('#forgotPasswordModal .registerResetCaptcha').click();
  557. if(result[0] == 'success'){
  558. $("#forgotPasswordModal").modal('hide');
  559. $("#forgotPasswordSuccessModal").modal('show');
  560. setTimeout(function(){
  561. $("body").addClass("modal-open");
  562. },500);
  563. }else if(result[0] == 'error'){
  564. $("#forgotPasswordModal").modal('hide');
  565. $("#forgotPasswordErrorModal").modal('show');
  566. setTimeout(function(){
  567. $("body").addClass("modal-open");
  568. },500);
  569. }
  570. if(result.forgotPasswordCaptcha != undefined){
  571. $(".forgotPasswordCaptchaIncorrect").css('display', 'block');
  572. $("input[name='forgotPasswordCaptcha']").focus();
  573. return false;
  574. }
  575. },
  576. error: function(data){
  577. var error = data.responseJSON;
  578. if(error != undefined){
  579. $('#forgotPasswordModal .registerResetCaptcha').click();
  580. if(error.forgotPasswordCaptcha != undefined){
  581. $(".forgotPasswordCaptchaIncorrect").css('display', 'block');
  582. $("input[name='forgotPasswordCaptcha']").focus();
  583. return false;
  584. }
  585. }
  586. }
  587. });
  588. });
  589. $('#activeCodeModal').on('shown.bs.modal', function () {
  590. $('#activeCodeModal .registerResetCaptcha').click();
  591. });
  592. //Ajax for active code
  593. $(document).on("click",".activeCodeButtonSubmit",function(){
  594. $(".activeCodeCaptchaIncorrect").css('display', 'none');
  595. var email = $("input[name='activeCodeEmail']").val();
  596. var captcha = $("input[name='activeCodeCaptcha']").val();
  597. var url = $(this).attr('url');
  598. if(email == ''){
  599. $(".activeCodeDontEnterEmail").css('display', 'block');
  600. return false;
  601. }else{
  602. $(".activeCodeDontEnterEmail").css('display', 'none');
  603. }
  604. if(!checkRegisterEmail(email)){
  605. $(".activeCodeEmailInvalid").css('display', 'block');
  606. return false;
  607. }else{
  608. $(".activeCodeEmailInvalid").css('display', 'none');
  609. }
  610. if(captcha == ''){
  611. $(".activeCodeDontEnterCaptcha").css('display', 'block');
  612. return false;
  613. }else{
  614. $(".activeCodeDontEnterCaptcha").css('display', 'none');
  615. }
  616. $.ajaxSetup({
  617. headers: {
  618. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  619. }
  620. });
  621. $.ajax({
  622. url: url,
  623. type: "POST",
  624. data: {
  625. email: email,
  626. captcha: captcha
  627. },
  628. success: function(result){
  629. $('.error-msg').css('display','none');
  630. $('.success-msg').css('display','none');
  631. $('#activeCodeModal .registerResetCaptcha').click();
  632. if(result[0] == 'success'){
  633. $('.success-msg').css('display','block');
  634. $('.success-msg').html(result[1]);
  635. }else if(result[0] == 'error'){
  636. $('.error-msg').css('display','block');
  637. $('.error-msg').html(result[1]);
  638. }
  639. if(result.captcha != undefined){
  640. $(".activeCodeCaptchaIncorrect").css('display', 'block');
  641. $("input[name='activeCodeCaptcha']").focus();
  642. return false;
  643. }
  644. },
  645. error: function(data){
  646. var error = data.responseJSON;
  647. if(error != undefined){
  648. $('#activeCodeModal .registerResetCaptcha').click();
  649. if(error.captcha != undefined){
  650. $(".activeCodeCaptchaIncorrect").css('display', 'block');
  651. $("input[name='activeCodeCaptcha']").focus();
  652. return false;
  653. }
  654. }
  655. }
  656. });
  657. });
  658. $(".forgotPasswordEnterAgain").click(function(){
  659. $("#forgotPasswordErrorModal").modal('hide');
  660. $("#forgotPasswordModal").modal('show');
  661. setTimeout(function(){
  662. $("body").addClass("modal-open");
  663. },500);
  664. });
  665. $(".activeCodeEnterAgain").click(function(){
  666. $("#activeCodeErrorModal").modal('hide');
  667. $("#activeCodeModal").modal('show');
  668. setTimeout(function(){
  669. $("body").addClass("modal-open");
  670. },500);
  671. });
  672. });
  673. //Show search
  674. $(document).ready(function(){
  675. $("#header-container-library-search-input").focus(function(){
  676. if(!$(".header-search-container").hasClass("header-search-show")){
  677. $(".header-search-container").addClass("header-search-show");
  678. if($(".header-search-list-cate").html() == ''){
  679. //Get category product
  680. var link = $(this).attr('linkCate');
  681. $.ajax({
  682. url: link,
  683. type: "GET",
  684. success: function(result){
  685. if(result.length > 0){
  686. $(".header-search-list-cate").empty();
  687. for (var i = 0; i < result.length; i++) {
  688. $(".header-search-list-cate").append("<li><a href='" + configUrl( "library/" + result[i].cate_slug) + "'>" + result[i].cate_name + "</a></li>");
  689. };
  690. }
  691. }
  692. });
  693. }
  694. }
  695. });
  696. });
  697. //Hide search
  698. $(document).mouseup(function(e){
  699. var container = $(".header-container-library-search");
  700. // if the target of the click isn't the container nor a descendant of the container
  701. if (!container.is(e.target) && container.has(e.target).length === 0)
  702. {
  703. if($(".header-search-container").hasClass("header-search-show")){
  704. $(".header-search-container").removeClass("header-search-show");
  705. }
  706. }
  707. });
  708. //Click icon search
  709. $(document).ready(function(){
  710. $("#header-container-library-search-icon").click(function(){
  711. if($("#header-container-library-search-input").val().length > 0){
  712. window.location.href = configUrl('library-search/'+ $("#header-container-library-search-input").val());
  713. }
  714. });
  715. });
  716. //Show search result
  717. $(document).ready(function(){
  718. $("#header-container-library-search-input").keyup(function(e){
  719. if(!$(".header-search-container").hasClass("header-search-show")){
  720. $(".header-search-container").addClass("header-search-show");
  721. }
  722. if($(this).val().length > 0){
  723. //Press Enter
  724. if(e.keyCode == 13){
  725. $("#header-container-library-search-icon").click();
  726. return false;
  727. }
  728. //Hide
  729. if(!$(".header-search-before").hasClass("header-search-hide")){
  730. $(".header-search-before").addClass("header-search-hide");
  731. }
  732. //Show
  733. if($(".header-search-result").hasClass("header-search-hide")){
  734. $(".header-search-result").removeClass("header-search-hide");
  735. }
  736. //Get result search
  737. var link = $(this).attr("linkSearch");
  738. var word = $(this).val();
  739. clearTimeout($.data(this, 'timersearch'));
  740. $(this).data('timersearch', setTimeout(function(){
  741. $.ajaxSetup({
  742. headers: {
  743. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  744. }
  745. });
  746. $.ajax({
  747. url: link,
  748. type: "POST",
  749. data: {
  750. word: word
  751. },
  752. success: function(result){
  753. $(".header-search-list-result").empty();
  754. //For loop max = 4
  755. for (var i = 0; i < Math.min(result.length, 4); i++) {
  756. $(".header-search-list-result").append("<li><a href='" + configUrl( "product-detail/" + result[i].product_slug) + "'>" + result[i].product_name + "</a></li>");
  757. };
  758. //Show button view all if product > 4
  759. if(result.length > 4){
  760. //Set link
  761. $(".header-search-result .header-search-result-all").attr('href', configUrl("library-search/" + word));
  762. //Show
  763. if($(".header-search-result .header-search-result-all").hasClass('header-search-hide')){
  764. $(".header-search-result .header-search-result-all").removeClass('header-search-hide');
  765. }
  766. }else{
  767. //Remove link
  768. $(".header-search-result .header-search-result-all").attr('href', "javascript:void(0)");
  769. //Dide
  770. if(!$(".header-search-result .header-search-result-all").hasClass('header-search-hide')){
  771. $(".header-search-result .header-search-result-all").addClass('header-search-hide');
  772. }
  773. }
  774. }
  775. });
  776. },300));
  777. }else{
  778. //Show
  779. if($(".header-search-before").hasClass("header-search-hide")){
  780. $(".header-search-before").removeClass("header-search-hide");
  781. }
  782. //Hide
  783. if(!$(".header-search-result").hasClass("header-search-hide")){
  784. $(".header-search-result").addClass("header-search-hide");
  785. }
  786. }
  787. });
  788. });
  789. // Show number noitification
  790. $(document).ready(function(){
  791. //Check Element '.header-container-library-notification' exist AND not has class '.session-notification'
  792. if($(".header-container-library-notification").length > 0 && !$(".header-container-library-notification").hasClass('session-notification')){
  793. $.ajax({
  794. url: configUrl('get-number-notification'),
  795. type: "GET",
  796. success: function(result){
  797. if(result > 0){
  798. $(".header-container-library-notification").addClass('notification-icon-active');
  799. $('.header-container-library-notification .header-container-library-icon-number').text(result);
  800. $('.header-container-library-notification .header-container-library-icon-number').css('display','inline-block');
  801. }
  802. }
  803. });
  804. }
  805. //Show list notification
  806. $(".header-container-library-notification-icon").click(function(){
  807. if($("#modal-notify").length == 0){
  808. $.ajax({
  809. url: configUrl('get-list-notification'),
  810. type: "GET",
  811. success: function(result){
  812. $("body").append(result);
  813. $("#modal-notify").modal();
  814. }
  815. });
  816. }else{
  817. $("#modal-notify").modal();
  818. }
  819. });
  820. //Get detail notification
  821. $(document).on('click', '#modal-notify .notify-item .item-button', function(){
  822. var element = $(this).parents('.notify-item');
  823. var notifyId = $(this).attr('notifyId');
  824. $.ajax({
  825. url: configUrl('get-detail-notification') + '/' + notifyId,
  826. type: "GET",
  827. success: function(result){
  828. $("#modal-nofitication-detail").html(result[1]);
  829. $("#modal-nofitication-detail").modal();
  830. if(result[0] == 2){
  831. $('.header-container-library-notification .header-container-library-icon-number').text(parseInt($('.header-container-library-notification .header-container-library-icon-number').text()) - 1);
  832. element.remove();
  833. }
  834. }
  835. });
  836. });
  837. //Get notification main
  838. if($(".notification-main-cover .notification-main").length == 0){
  839. $.ajax({
  840. url: configUrl('get-first-notification'),
  841. type: "GET",
  842. success: function(result){
  843. $(".notification-main-cover").html(result);
  844. }
  845. });
  846. }
  847. });
  848. function checkRegisterName(name){
  849. if(name.length >= 5 && name.length < 255){
  850. return true;
  851. }else{
  852. return false;
  853. }
  854. }
  855. function checkRegisterEmail(email){
  856. var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  857. return re.test(email);
  858. }
  859. function checkRegisterPassword(password){
  860. if(password.length >= 6 && password.length < 255){
  861. return true;
  862. }else{
  863. return false;
  864. }
  865. }
  866. function configUrl($link){
  867. return location.protocol + "//" + location.host + '/' + $link;
  868. }
  869. function facebookLogin(){
  870. var width = 900;
  871. var height = 500;
  872. var left = (screen.width/2)-(width/2);
  873. var top = (screen.height/2)-(height/2);
  874. loginWindown = window.open(configUrl('login-facebook'),'name','width = '+width+',height = '+height+',left = '+left+',top = '+top);
  875. }
  876. function googleLogin(){
  877. var width = 900;
  878. var height = 500;
  879. var left = (screen.width/2)-(width/2);
  880. var top = (screen.height/2)-(height/2);
  881. loginWindown = window.open(configUrl('login-google'),'name','width = '+width+',height = '+height+',left = '+left+',top = '+top);
  882. }
  883. function redirect(id)
  884. {
  885. loginWindown.close();
  886. self.location = configUrl('library');
  887. }
  888. $(document).ready(function(){
  889. $(document).on('click','.registerResetCaptcha',function(){
  890. var img = $(this).prev();
  891. $.ajaxSetup({
  892. headers: {
  893. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  894. }
  895. });
  896. $.ajax({
  897. url: configUrl("get-captcha"),
  898. type: "POST",
  899. success: function (data) {
  900. img.attr('src', data);
  901. }
  902. });
  903. });
  904. });
  905. $(document).on('click', '.header-middle', function(){
  906. amimateUpDown($('.main-header-cover .header-menu'));
  907. // amimateUpDown($('.main-header-cover .header-right'));
  908. });
  909. function amimateUpDown(element){
  910. if($(element).hasClass('menu-show')){
  911. $(element).slideUp('fast',function(){
  912. $(element).removeClass('menu-show');
  913. });
  914. }else{
  915. $(element).slideDown('fast',function(){
  916. $(element).addClass('menu-show');
  917. });
  918. }
  919. }
  920. $(document).on('click', '.button-set-language', function(){
  921. var lang = $(this).attr('val');
  922. $('#input-set-language').val(lang);
  923. $('#form-set-language').submit();
  924. });
  925. $(document).on('click', '.head-menu-item-language', function(){
  926. amimateUpDown($(this).next('.header-menu-lang-cover'));
  927. })