Advertisement
Guest User

Untitled

a guest
Sep 15th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.12 KB | None | 0 0
  1. var gsb = {
  2. data:{},
  3. tags:[{"id":"1","name":"thanh 1"},{"id":"2","name":"thanh 2"},{"id":"3","name":"thanh 3"},{"id":"4","name":"thanh 4"},{"id":"5","name":"thanh 5"},{"id":"6","name":"thành 6"},{"id":"7","name":"luyen thi dai hoc"},{"id":"8","name":"luyen thi hoc sinh gioi"}],
  4. jsf:{
  5. extend:function(o) {
  6. $.extend(true, gsb.data, o);
  7. }
  8. },
  9. home: {
  10. searching:false,
  11. init: function () {
  12. $('.carousel').carousel();
  13. gsb.library.html.search_box();
  14. $('#query').typing({
  15. start: function (event, $elem) {
  16. $('#suggestion').html('');
  17. },
  18. stop: function (event, $elem) {
  19. var search = $.trim($elem.val());
  20. if(!search) return true;
  21. var params = {
  22. _token:gsb.data.csrf,
  23. kw: search
  24. };
  25. gsb.ajax.html(gsb.data.suggest_url,params,'#suggestion', function(){
  26. $elem.focus();// show suggestion
  27. var suggestion = $('.autocomplete-suggestion');
  28. // unbine click on element
  29. suggestion.unbind('click');
  30. suggestion.click(function(){
  31. var url = $(this).data('url');
  32. $("#search-suggestions").removeClass('autocomplete-visible');
  33. window.location = url;
  34. });
  35. suggestion.hover(
  36. function() {
  37. gsb.home.searching = true;
  38. }, function() {
  39. gsb.home.searching = false;
  40. }
  41. );
  42. });
  43. },
  44. delay: 500
  45. });
  46. }
  47. },
  48. login: {
  49. init: function () {
  50.  
  51. }
  52. },
  53. register: {
  54. init: function () {
  55. $("#registerForm").validate({
  56. rules: {
  57. name: {
  58. required: true,
  59. minlength: 2,
  60. maxlength: 50
  61. },
  62. username: {
  63. required: true,
  64. minlength: 6,
  65. maxlength: 20
  66. },
  67. password: {
  68. required: true,
  69. minlength: 6,
  70. maxlength: 12
  71. },
  72. email: {
  73. required: true,
  74. email: true
  75. },
  76. become: {
  77. required: true,
  78. minlength: 1
  79. },
  80. accept: {
  81. required: true,
  82. minlength: 1
  83. }
  84. },
  85. messages: {
  86. name: {
  87. required: "Bắt buộc phải nhập.",
  88. minlength: "Độ dài yêu cầu từ 2 - 50 kí tự.",
  89. maxlength: "Độ dài yêu cầu từ 2 - 50 kí tự."
  90. },
  91. username: {
  92. required: "Bắt buộc phải nhập.",
  93. minlength: "Độ dài yêu cầu từ 6 - 20 kí tự.",
  94. maxlength: "Độ dài yêu cầu từ 6 - 20 kí tự."
  95. },
  96. password: {
  97. required: "Bắt buộc phải nhập.",
  98. minlength: "Độ dài yêu cầu từ 6 - 12 kí tự.",
  99. maxlength: "Độ dài yêu cầu từ 6 - 12 kí tự."
  100. },
  101. email: "Địa chỉ email không hợp lệ.",
  102. become: {
  103. required: "Bắt buộc phải nhập."
  104. },
  105. accept: {
  106. required: 'Bắt buộc phải nhập.'
  107. }
  108. },
  109. submitHandler:function(a){if($(a).valid()){a.submit()}return false}
  110. });
  111. }
  112. },
  113. dashboard: {},
  114. user: {
  115. view: {
  116. init: function () {
  117. $('[data-toggle="tooltip"]').tooltip();
  118. $('.profile-tab a').click(function (e) {
  119. e.preventDefault();
  120. $(this).tab('show');
  121. });
  122. gsb.google.map.radius();
  123. }
  124. },
  125. edit: {
  126. opt: {
  127. cropData: {
  128. "dummyData": 1
  129. },
  130. /*uploadUrl:'img_save_to_file.php',*/
  131. cropUrl: 'img_crop_to_file.php',
  132. customUploadButtonId: null,
  133. rotateControls: false,
  134. enableMousescroll: true,
  135. doubleZoomControls:true,
  136. modal: false,
  137. processInline: true,
  138. loaderHtml: '<div class="loader bubblingG"><span id="bubblingG_1"></span><span id="bubblingG_2"></span><span id="bubblingG_3"></span></div> ',
  139. onBeforeImgUpload: function () {
  140. console.log('onBeforeImgUpload')
  141. },
  142. onAfterImgUpload: function () {
  143. console.log('onAfterImgUpload')
  144. },
  145. onImgDrag: function () {
  146. console.log('onImgDrag')
  147. },
  148. onImgZoom: function () {
  149. console.log('onImgZoom')
  150. },
  151. onBeforeImgCrop: function () {
  152. console.log('onBeforeImgCrop')
  153. },
  154. onAfterImgCrop: function () {
  155. console.log('onAfterImgCrop')
  156. },
  157. onError: function (errormessage) {
  158. console.log('onError:' + errormessage)
  159. }
  160. },
  161. init: function () {
  162. gsb.user.edit.cropcover();
  163. gsb.user.edit.cropavatar();
  164. gsb.user.edit.textarea();
  165. gsb.library.html.select();
  166. $('#birthday').datepicker({
  167. format: "dd/mm/yyyy",
  168. language: "vi",
  169. calendarWeeks: true,
  170. autoclose: true,
  171. todayHighlight: true,
  172. /*datesDisabled: ['08/08/2015', '12/08/2015'],*/
  173. toggleActive: true
  174. });
  175. $('#birthday').datepicker('update', gsb.data.bday );
  176. $('#subject').select2({
  177. maximumSelectionLength:5,
  178. placeholder:'Chọn lĩnh vực chuyên môn',
  179. templateSelection: function(data){ return data.text.toLowerCase();}
  180. });
  181. $('#gender,#school,#city,#state,#country,#teach_in,#teach_state,#degree,#experience').select2();
  182. $('#skill').select2({
  183. tags:true,
  184. tokenSeparators: [','],
  185. maximumSelectionLength:10,
  186. placeholder:'Vd: Luyện thi học sinh giỏi, anh văn giao tiếp...',
  187. templateSelection: function(data){ return data.text.toLowerCase();}
  188. });
  189. gsb.google.map.drag();
  190. $("button#done").click(function(){
  191. $('#updateForm').submit();
  192. });
  193. },
  194. cropavatar: function () {
  195. gsb.user.edit.opt.customUploadButtonId = 'cropAvatarButton';
  196. gsb.user.edit.opt.cropUrl = gsb.data.url + '/photo/crop';
  197. gsb.user.edit.opt.doubleZoomControls = false;
  198. new Croppic('croppicavatar', gsb.user.edit.opt);
  199. },
  200. cropcover: function () {
  201. gsb.user.edit.opt.customUploadButtonId = 'cropCoverButton';
  202. gsb.user.edit.opt.cropUrl = gsb.data.url + '/photo/crop';
  203. gsb.user.edit.opt.doubleZoomControls = true;
  204. new Croppic('croppiccover', gsb.user.edit.opt);
  205. },
  206. textarea:function(){
  207. $('#about').popover();
  208. },
  209. tinymce:function(){
  210. tinymce.init({
  211. selector: "#about",
  212. menu:[],
  213. toolbar: "",
  214. setup: function (editor) {
  215. // Set placeholder
  216. var placeholder = $.trim($('#' + editor.id).attr('placeholder'));
  217. if (typeof placeholder !== 'undefined' && placeholder !== false) {
  218. var is_default = false;
  219. editor.on('init', function () {
  220. // get the current content
  221. var content = $.trim(editor.getContent());
  222.  
  223. // If its empty and we have a placeholder set the value
  224. if (content.length === 0) {
  225. editor.setContent(placeholder);
  226. // Get updated content
  227. content = placeholder;
  228. }
  229. // convert to plain text and compare strings
  230. is_default = (content == placeholder);
  231.  
  232. // nothing to do
  233. if (!is_default) {
  234. return;
  235. }
  236. })
  237. .on('focus', function () {
  238. if ($.trim(editor.getContent()) == '<p>'+placeholder+'</p>'){
  239. editor.setContent('');
  240. }
  241. })
  242. .on('blur', function () {
  243. if ($.trim(editor.getContent()).length === 0) {
  244. editor.setContent(placeholder);
  245. }
  246. });
  247. }
  248. }
  249. });
  250. }
  251. },
  252. browse:{
  253. init: function () {
  254. gsb.library.more_less('user');
  255. $('input:radio[name="city-name"]').change(function(){
  256. window.location= $(this).data('url');
  257. });
  258. }
  259. }
  260. },
  261. job:{
  262. data:{
  263. schedule:{}
  264. },
  265. post:{
  266. init:function(){
  267. gsb.job.post.textarea();
  268. gsb.library.html.select();
  269. $('#skill').tagEditor({
  270. initialTags: [],
  271. autocomplete: {
  272. delay: 0,
  273. position: { collision: 'flip' },
  274. source: ['ActionScript', 'AppleScript', 'Asp', 'BASIC', 'C', 'C++', 'CSS', 'Clojure', 'COBOL', 'ColdFusion', 'Erlang', 'Fortran', 'Groovy', 'Haskell', 'HTML', 'Java', 'JavaScript', 'Lisp', 'Perl', 'PHP', 'Python', 'Ruby', 'Scala', 'Scheme']
  275. },
  276. placeholder: 'Vd: Luyện thi học sinh giỏi, Toán lớp 6, Tin học văn phòng ...',
  277. onChange: function(field, editor, tags) { console.log(tags) }
  278. });
  279. $('#expired').datepicker({
  280. format: "dd/mm/yyyy",
  281. language: "vi",
  282. autoclose: true,
  283. startDate: "+5d",
  284. endDate: "+30d",
  285. todayHighlight: true,
  286. toggleActive: true
  287. });
  288. $('#job_type').change(function(){
  289. if($(this).val()==2){
  290. $('label#price-label').text("Thù lao tối đa/buổi");
  291. } else {
  292. $('label#price-label').text("Thù lao/buổi");
  293. }
  294. });
  295. gsb.job.post.action.cal_hover();
  296. gsb.job.post.action.cal_click();
  297. gsb.job.post.action.cal_initial();
  298. gsb.job.post.action.map_initial();
  299.  
  300. $(".fix-table").freezeHeader();
  301. $("button#done").click(function(){
  302. // check du lieu schedule post len phai la json
  303. if(!gsb.library.is_json($('#schedule').val())) return;
  304. $('#createForm').submit();
  305. });
  306. gsb.google.map.drag();
  307. },
  308. textarea:function(){
  309. $('#jcontent').popover();
  310. },
  311. action: {
  312. cal_hover: function() {
  313. var cls = '';
  314. $('div[class^="col-"]').hover(
  315. function() {
  316. col = $(this).attr('class').split(' ')[0];
  317. $('.' + col).each(function() {
  318. if ($(this).hasClass('sch')) {
  319. $(this).addClass('sch-hover');
  320. } else {
  321. $(this).addClass('week-day-hover');
  322. }
  323. });
  324. },
  325. function() {
  326. col = $(this).attr('class').split(' ')[0];
  327. $('.' + col).each(function() {
  328. if ($(this).hasClass('sch')) {
  329. $(this).removeClass('sch-hover');
  330. } else {
  331. $(this).removeClass('week-day-hover');
  332. }
  333. });
  334. }
  335. );
  336. },
  337. cal_click: function() {
  338. $('div.maru').unbind('click').click(function() {
  339. if($(this).hasClass('sch-disabled')){ return; }
  340. day = $(this).data('day');
  341. slot= $(this).data('slot');
  342. col = $(this).attr('class').split(' ')[0];
  343. if($(this).hasClass('sch-selected')){
  344. $(this).removeClass('sch-selected');
  345. // remove class sch-disabled
  346. $('.' + col).each(function() {
  347. $(this).removeClass('sch-disabled');
  348. });
  349. delete gsb.job.data.schedule[day];// unset data
  350. gsb.job.post.action.day_per_week(gsb.job.data.schedule);
  351. } else {
  352. $(this).addClass('sch-selected');
  353. // add class sch-disabled
  354. $('.' + col).each(function() {
  355. if (!$(this).hasClass('sch-selected')) {
  356. $(this).addClass('sch-disabled');
  357. }
  358. });
  359. gsb.job.data.schedule[day] = slot;// set data
  360. gsb.job.post.action.day_per_week(gsb.job.data.schedule);
  361. }
  362. });
  363. },
  364. cal_initial: function(){
  365. var schedules = gsb.library.parse_json($('#schedule').val());
  366. $.each(schedules, function( index, value ) {
  367. var selected = $('div.sch[data-day="'+index+'"][data-slot="'+value+'"]');
  368. var cls = selected.attr('class');
  369. selected.click();
  370. });
  371. },
  372. day_per_week: function(sch){
  373. $('#schedule').val(JSON.stringify(sch));
  374. total = Object.keys(sch).length;
  375. if(total==0){
  376. $('#totals').text('chọn thời gian bắt đầu');
  377. } else {
  378. $('#totals').text(total+' buổi/tuần');
  379. }
  380. },
  381. map_initial: function(){
  382. var latlng = $('#latlng').val();
  383. if(latlng=='[lat:lng]') {return;}
  384. latlng = $('#latlng').val().split(':');
  385. gsb.data.lat = latlng[0];
  386. gsb.data.lng = latlng[1];
  387. }
  388. }
  389. },
  390. view:{
  391. init:function (){
  392. $('#price').keyup(function(){
  393. gsb.job.view.action.chek_price($(this));
  394. });
  395. $('#price').change(function(){
  396. gsb.job.view.action.chek_price($(this));
  397. });
  398.  
  399. $('#start').datepicker({
  400. format: "dd/mm/yyyy",
  401. language: "vi",
  402. autoclose: true,
  403. startDate: "+0d",
  404. endDate: gsb.data.enddate,
  405. daysOfWeekDisabled: gsb.data.disabled,
  406. toggleActive: true
  407. });
  408. $("#start").focusin(function(){$(this).prop("readonly",true)});
  409. $("#start").focusout(function(){$(this).prop("readonly",false)});
  410. $("#start").change(function(){$(this).valid()});
  411. $('#accept').change(function(){
  412. gsb.job.view.action.chek_price($('#price'));
  413. gsb.job.view.action.aceppted($(this));
  414. });
  415. $("#apply").click(function(){$(".job-apply").show();$(".call-to-action").hide();});
  416. gsb.job.view.action.form_valid(); // validation
  417. $("button#done").click(function(){
  418. $("#applyForm").valid();
  419. gsb.job.view.action.aceppted($('#accept'));
  420. if(!$("#applyForm").valid()) return false;
  421. if(!gsb.job.view.action.aceppted($('#accept'))) return false;
  422. // ajax to
  423. var params = {
  424. _token:gsb.data.csrf,
  425. job_id:gsb.data.job.id,
  426. content:$('#jcontent').val(),
  427. price:$('#price').val(),
  428. start:$('#start').val(),
  429. accept:$('#accept').val()
  430. };
  431. gsb.ajax.json(gsb.data.job.urly, params, function () {
  432. $('#popup-content').html(gsb.ajax.result.success.msg);
  433. $('#popup-title').html(gsb.ajax.result.success.tit);
  434. $('.tgs-fas').popup({transition: 'all 0.3s',onclose: function () {location.reload();}});
  435. $('.popup-close').click(function(){$('.tgs-fas').popup('hide');});
  436. $('.tgs-fas').popup('show');
  437. });
  438. });
  439. // hire a tutor
  440. $('.job-hire').click(function(){
  441. // ajax to hire
  442. var params = {
  443. _token:gsb.data.csrf,
  444. job_id:gsb.data.job.id,
  445. tutor_id:$(this).data('tutor')
  446. };
  447. gsb.ajax.json(gsb.data.job.urle, params, function () {
  448. $('#popup-content').html(gsb.ajax.result.success.msg);
  449. $('#popup-title').html(gsb.ajax.result.success.tit);
  450. $('.tgs-fas').popup({transition: 'all 0.3s',onclose: function () {location.reload();}});
  451. $('.popup-close').click(function(){$('.tgs-fas').popup('hide');});
  452. $('.tgs-fas').popup('show');
  453. });
  454. });
  455. // load google map
  456. gsb.google.map.view();
  457. },
  458. action:{
  459. form_valid: function () {
  460. $("#applyForm").validate({
  461. rules: {
  462. content: {
  463. required: true,
  464. minlength: 200,
  465. maxlength: 2000
  466. },
  467. price: {
  468. required: true,
  469. number: true,
  470. min: 80000
  471. },
  472. start: {
  473. required: true
  474. }
  475. },
  476. messages: {
  477. content: {
  478. required: "Bắt buộc phải nhập.",
  479. minlength: "Độ dài tối thiểu 200 kí tự.",
  480. maxlength: "Độ dài tối đa 2000 kí tự."
  481. },
  482. price: {
  483. required: "Bắt buộc phải nhập.",
  484. number: "Phải là một số.",
  485. min: "Tối thiểu 80.000 ₫."
  486. },
  487. start: {
  488. required: "Bắt buộc phải nhập."
  489. }
  490. },
  491. submitHandler:function(a){if($(a).valid()){a.submit()}return false}
  492. });
  493. },
  494. aceppted: function(c){
  495. if(c.is(':checked')){
  496. $('.agree-to-rules').removeClass('agree-to-rules-error');
  497. $('.agree-to-rules').addClass('agree-to-rules-ok');
  498. return true;
  499. } else {
  500. $('.agree-to-rules').addClass('agree-to-rules-error');
  501. $('.agree-to-rules').removeClass('agree-to-rules-ok');
  502. return false;
  503. }
  504. },
  505. chek_price: function(p){
  506. var price = p.val();
  507. var salary = price * gsb.data.job.dpm;
  508. var fee = Math.ceil(salary * gsb.data.job.fee / 1000) * 1000;
  509. if(p.valid()){
  510. $('#slr').text('Thù lao: '+$.number(salary,0,'.','.')+' ₫/tháng');
  511. $('#fee').text('Lệ phí: '+$.number(fee,0,'.','.')+' ₫(*)');
  512. } else {
  513. $('#slr').text('Thù lao: 0 ₫/tháng');
  514. $('#fee').text('Lệ phí: 0 ₫(*)');
  515. }
  516. }
  517. }
  518. },
  519. edit:{},
  520. browse:{
  521. init:function (){
  522. gsb.library.more_less('job');
  523. $('input:radio[name="city-name"]').change(function(){
  524. window.location= $(this).data('url');
  525. });
  526. }
  527. },
  528. tags:{
  529. init:function (){
  530.  
  531. }
  532. }
  533. },
  534. ajax: {
  535. result:{},
  536. html: function(url, data, container, call_back) {
  537. var error = false;
  538. $.ajax({
  539. type: "POST",
  540. url: url,
  541. data: data,
  542. dataType: "html",
  543. async: true,
  544. beforeSend: function() {/*do something*/},
  545. success: function(html) {
  546. if(gsb.library.is_json(html)){
  547. gsb.ajax.result = gsb.library.parse_json(html);
  548. if (gsb.ajax.result.error) {
  549. error = true;
  550. alert(gsb.ajax.result.error.msg);
  551. }
  552. } else {
  553. $(container).html(html);
  554. if (typeof call_back == 'function'){call_back.call();}
  555. }
  556. },
  557. error: function(error) {}
  558. });
  559. return gsb.ajax.result;
  560. },
  561. json: function(url, data, call_back) {
  562. $.ajax({
  563. type: "POST",
  564. url: url,
  565. data: data,
  566. dataType: "json",
  567. async: true,
  568. beforeSend: function() {/*do something*/},
  569. success: function(json) {
  570. try {
  571. gsb.ajax.result = json;
  572. if (gsb.ajax.result.error) {
  573. gsb.popup.refresh = gsb.ajax.result.error.rfr;
  574. gsb.popup.fas(gsb.ajax.result.error.tit,gsb.ajax.result.error.msg);
  575. } else {if (typeof call_back == 'function'){call_back.call();}}
  576. } catch (e) {alert(json);}
  577. },
  578. error: function(error) {/* do something */}
  579. });
  580. return gsb.ajax.result;
  581. },
  582. xml: function(){
  583. $.ajax({
  584. type: "POST",
  585. url: url,
  586. data: data,
  587. dataType: "xml",
  588. async: false,
  589. beforeSend: function() {/* do something */},
  590. success: function(xml) {},
  591. error: function(error) {/* do something */}
  592. });
  593. }
  594. },
  595. popup:{
  596. refresh:false,
  597. fas: function(title, msg){
  598. $('#popup-content').html(msg);
  599. $('#popup-title').html(title);
  600. $('.popup-close').click(function(){$('.tgs-fas').popup('hide');});
  601. $('.tgs-fas').popup({transition: 'all 0.3s',onclose: function () { if(gsb.popup.refresh){location.reload();}}});
  602. $('.tgs-fas').popup('show');
  603. }
  604. },
  605. error:{
  606. unauthorized: function (msg) {
  607. }
  608. },
  609. library: {
  610. html:{
  611. //custom placeholder for select field
  612. select: function(){$("select").change(function(){if($(this).val()==""){$(this).removeClass("no-empty")}else{$(this).addClass("no-empty")}});$("select").change();},
  613. menu:function(){$('ul.dropdown-menu >li[class^="gs-"]').click(function(c){var b=$(this);var a=b.attr("class");if(b.hasClass("active")){b.removeClass("active")}else{$('ul.dropdown-menu >li[class^="gs-"]').each(function(){$(this).removeClass("active")});b.addClass("active")}c.stopPropagation()});},
  614. search_box:function(){var si=$("#query");var s_suggestions=$("#search-suggestions");var a_suggestions=$(".autocomplete-suggestions");si.focus(function(){if(a_suggestions.html().length>0){s_suggestions.addClass("autocomplete-visible")}});si.blur(function(){if(!gsb.home.searching){s_suggestions.removeClass("autocomplete-visible");}if(!$.trim(si.val())){s_suggestions.removeClass("searching")}});si.keyup(function(){if(!$.trim(si.val())){s_suggestions.removeClass("searching")}else{s_suggestions.addClass("searching")}});}
  615. },
  616. more_less: function(obj){// obj user or job
  617. $('.jobs-list .view-more, .users-list .view-more').click(function(){
  618. var id = $(this).parent().parent().attr('id');
  619. $('#'+id+' .'+obj+'-desc-short').hide();
  620. $('#'+id+' .'+obj+'-desc').show();
  621. });
  622. $('.jobs-list .view-less, .users-list .view-less').click(function(){
  623. var id = $(this).parent().parent().attr('id');
  624. $('#'+id+' .'+obj+'-desc').hide();
  625. $('#'+id+' .'+obj+'-desc-short').show();
  626. });
  627. },
  628. parse_json: function(json){return $.parseJSON(json);},
  629. is_json :function (string){ try { $.parseJSON(string);} catch (e) { return false; }return true;},
  630. array_intersect:function(a,b){return $.grep(a, function(i){return $.inArray(i, b) > -1;});},
  631. scroll: function(element, offset) {$('html, body').animate({scrollTop: $(element).offset().top - parseInt(offset)}, 500);}
  632. },
  633. google:{
  634. analytics: {},
  635. map: {
  636. drag:function(){
  637. var loc = new google.maps.LatLng(gsb.data.lat, gsb.data.lng);
  638. function initialize() {
  639. var prop = {
  640. center: loc,
  641. zoom: 1,
  642. mapTypeControl: false,
  643. streetViewControl: false,
  644. mapTypeId: google.maps.MapTypeId.ROADMAP
  645. };
  646. var map = new google.maps.Map(document.getElementById("map"), prop);
  647.  
  648. // make circle
  649. var radius = 1000;//1km
  650. var around = new google.maps.Circle({
  651. center: loc,
  652. radius: radius,
  653. strokeColor: "#4D6AA4",
  654. strokeOpacity: 0.0,
  655. strokeWeight: 1,
  656. fillColor: "#4D6AA4",
  657. fillOpacity: 0.0
  658. });
  659.  
  660. // make map fit with circle
  661. map.fitBounds(around.getBounds());
  662. around.setMap(map);
  663.  
  664. // add marker for map
  665. var marker = new google.maps.Marker({
  666. position: loc,
  667. map: map,
  668. draggable: true,
  669. icon: gsb.data.url + '/img/icons/pin7.png'
  670. });
  671. gsb.google.map.myloc(map,marker);
  672. google.maps.event.addListener(marker, 'dragend', function () {
  673. var lat = this.getPosition().lat().toFixed(6);
  674. var lng = this.getPosition().lng().toFixed(6);
  675. $('#latlng').val(lat+':'+lng);
  676. });
  677. }
  678. google.maps.event.addDomListener(window, 'load', initialize);
  679. },
  680. view:function(){
  681. var loc = new google.maps.LatLng(gsb.data.lat, gsb.data.lng);
  682. function initialize() {
  683. var prop = {
  684. center: loc,
  685. zoom: 1,
  686. mapTypeControl: false,
  687. streetViewControl: false,
  688. mapTypeId: google.maps.MapTypeId.ROADMAP
  689. };
  690. var map = new google.maps.Map(document.getElementById("map"), prop);
  691.  
  692. // make circle
  693. var radius = 1000;//1km
  694. var around = new google.maps.Circle({
  695. center: loc,
  696. radius: radius,
  697. strokeColor: "#4D6AA4",
  698. strokeOpacity: 0.0,
  699. strokeWeight: 1,
  700. fillColor: "#4D6AA4",
  701. fillOpacity: 0.0
  702. });
  703.  
  704. // make map fit with circle
  705. map.fitBounds(around.getBounds());
  706. around.setMap(map);
  707.  
  708. // add marker for map
  709. var marker = new google.maps.Marker({
  710. position: loc,
  711. map: map,
  712. draggable: false,
  713. icon: gsb.data.url + '/img/icons/pin3.png'
  714. });
  715. google.maps.event.addListener(marker, 'dragend', function () {
  716. var lat = this.getPosition().lat().toFixed(6);
  717. var lng = this.getPosition().lng().toFixed(6);
  718. $('#latlng').val(lat+':'+lng);
  719. });
  720. }
  721. google.maps.event.addDomListener(window, 'load', initialize);
  722. },
  723. radius:function(){
  724. var loc = new google.maps.LatLng(gsb.data.lat, gsb.data.lng);
  725. function initialize() {
  726. var prop = {
  727. center: loc,
  728. zoom: 1,
  729. mapTypeControl: false,
  730. streetViewControl: false,
  731. mapTypeId: google.maps.MapTypeId.ROADMAP
  732. };
  733. var map = new google.maps.Map(document.getElementById("map"), prop);
  734. // make circle
  735. var radius = 1000;//1km
  736. var around = new google.maps.Circle({
  737. center: loc,
  738. radius: radius,
  739. strokeColor: "#4D6AA4",
  740. strokeOpacity: 0.37254901960784315,
  741. strokeWeight: 1,
  742. fillColor: "#4D6AA4",
  743. fillOpacity: 0.11764705882352941
  744. });
  745.  
  746. // make map fit with circle
  747. map.fitBounds(around.getBounds());
  748. around.setMap(map);
  749.  
  750. // add marker for map
  751. var marker = new google.maps.Marker({
  752. position: loc,
  753. map: map,
  754. draggable: false,
  755. icon: gsb.data.url + '/img/icons/pin7.png'
  756. });
  757. google.maps.event.addListener(marker, 'dragend', function () {
  758. console.log(this.getPosition().lat().toFixed(4));
  759. console.log(this.getPosition().lng().toFixed(4));
  760. });
  761. }
  762. google.maps.event.addDomListener(window, 'load', initialize);
  763. },
  764. myloc: function (map, marker) {
  765. var controlDiv = document.createElement('div');
  766. var firstChild = document.createElement('button');
  767. firstChild.id = 'my-loc-button';
  768. firstChild.title = 'Ví trí của bạn';
  769. controlDiv.appendChild(firstChild);
  770.  
  771. var secondChild = document.createElement('div');
  772. secondChild.id = 'my-loc-img';
  773. firstChild.appendChild(secondChild);
  774.  
  775. google.maps.event.addListener(map, 'dragend', function () {
  776. $('#my-loc-img').css('background-position', '0px 0px');
  777. });
  778.  
  779. firstChild.addEventListener('click', function () {
  780. var imgX = '0';
  781. var animationInterval = setInterval(function () {
  782. if (imgX == '-18') { imgX = '0'; }
  783. else { imgX = '-18'; }
  784. $('#my-loc-img').css('background-position', imgX + 'px 0px');
  785. }, 500);
  786. if (navigator.geolocation) {
  787. navigator.geolocation.getCurrentPosition(function (position) {
  788. var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
  789. marker.setPosition(latlng);
  790. map.setCenter(latlng);
  791. clearInterval(animationInterval);
  792. $('#my-loc-img').css('background-position', '-144px 0px');
  793. });
  794. }
  795. else {
  796. clearInterval(animationInterval);
  797. $('#my-loc-img').css('background-position', '0px 0px');
  798. }
  799. });
  800.  
  801. controlDiv.index = 1;
  802. map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(controlDiv);
  803. }
  804.  
  805. }
  806.  
  807. }
  808. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement