Created
September 15, 2016 10:31
-
-
Save tolawho/cfa289d7cb530583ab945b69dfbf4f16 to your computer and use it in GitHub Desktop.
js trong dự án cá nhân
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gsb = { | |
data:{}, | |
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"}], | |
jsf:{ | |
extend:function(o) { | |
$.extend(true, gsb.data, o); | |
} | |
}, | |
home: { | |
searching:false, | |
init: function () { | |
$('.carousel').carousel(); | |
gsb.library.html.search_box(); | |
$('#query').typing({ | |
start: function (event, $elem) { | |
$('#suggestion').html(''); | |
}, | |
stop: function (event, $elem) { | |
var search = $.trim($elem.val()); | |
if(!search) return true; | |
var params = { | |
_token:gsb.data.csrf, | |
kw: search | |
}; | |
gsb.ajax.html(gsb.data.suggest_url,params,'#suggestion', function(){ | |
$elem.focus();// show suggestion | |
var suggestion = $('.autocomplete-suggestion'); | |
// unbine click on element | |
suggestion.unbind('click'); | |
suggestion.click(function(){ | |
var url = $(this).data('url'); | |
$("#search-suggestions").removeClass('autocomplete-visible'); | |
window.location = url; | |
}); | |
suggestion.hover( | |
function() { | |
gsb.home.searching = true; | |
}, function() { | |
gsb.home.searching = false; | |
} | |
); | |
}); | |
}, | |
delay: 500 | |
}); | |
} | |
}, | |
login: { | |
init: function () { | |
} | |
}, | |
register: { | |
init: function () { | |
$("#registerForm").validate({ | |
rules: { | |
name: { | |
required: true, | |
minlength: 2, | |
maxlength: 50 | |
}, | |
username: { | |
required: true, | |
minlength: 6, | |
maxlength: 20 | |
}, | |
password: { | |
required: true, | |
minlength: 6, | |
maxlength: 12 | |
}, | |
email: { | |
required: true, | |
email: true | |
}, | |
become: { | |
required: true, | |
minlength: 1 | |
}, | |
accept: { | |
required: true, | |
minlength: 1 | |
} | |
}, | |
messages: { | |
name: { | |
required: "Bắt buộc phải nhập.", | |
minlength: "Độ dài yêu cầu từ 2 - 50 kí tự.", | |
maxlength: "Độ dài yêu cầu từ 2 - 50 kí tự." | |
}, | |
username: { | |
required: "Bắt buộc phải nhập.", | |
minlength: "Độ dài yêu cầu từ 6 - 20 kí tự.", | |
maxlength: "Độ dài yêu cầu từ 6 - 20 kí tự." | |
}, | |
password: { | |
required: "Bắt buộc phải nhập.", | |
minlength: "Độ dài yêu cầu từ 6 - 12 kí tự.", | |
maxlength: "Độ dài yêu cầu từ 6 - 12 kí tự." | |
}, | |
email: "Địa chỉ email không hợp lệ.", | |
become: { | |
required: "Bắt buộc phải nhập." | |
}, | |
accept: { | |
required: 'Bắt buộc phải nhập.' | |
} | |
}, | |
submitHandler:function(a){if($(a).valid()){a.submit()}return false} | |
}); | |
} | |
}, | |
dashboard: {}, | |
user: { | |
view: { | |
init: function () { | |
$('[data-toggle="tooltip"]').tooltip(); | |
$('.profile-tab a').click(function (e) { | |
e.preventDefault(); | |
$(this).tab('show'); | |
}); | |
gsb.google.map.radius(); | |
} | |
}, | |
edit: { | |
opt: { | |
cropData: { | |
"dummyData": 1 | |
}, | |
/*uploadUrl:'img_save_to_file.php',*/ | |
cropUrl: 'img_crop_to_file.php', | |
customUploadButtonId: null, | |
rotateControls: false, | |
enableMousescroll: true, | |
doubleZoomControls:true, | |
modal: false, | |
processInline: true, | |
loaderHtml: '<div class="loader bubblingG"><span id="bubblingG_1"></span><span id="bubblingG_2"></span><span id="bubblingG_3"></span></div> ', | |
onBeforeImgUpload: function () { | |
console.log('onBeforeImgUpload') | |
}, | |
onAfterImgUpload: function () { | |
console.log('onAfterImgUpload') | |
}, | |
onImgDrag: function () { | |
console.log('onImgDrag') | |
}, | |
onImgZoom: function () { | |
console.log('onImgZoom') | |
}, | |
onBeforeImgCrop: function () { | |
console.log('onBeforeImgCrop') | |
}, | |
onAfterImgCrop: function () { | |
console.log('onAfterImgCrop') | |
}, | |
onError: function (errormessage) { | |
console.log('onError:' + errormessage) | |
} | |
}, | |
init: function () { | |
gsb.user.edit.cropcover(); | |
gsb.user.edit.cropavatar(); | |
gsb.user.edit.textarea(); | |
gsb.library.html.select(); | |
$('#birthday').datepicker({ | |
format: "dd/mm/yyyy", | |
language: "vi", | |
calendarWeeks: true, | |
autoclose: true, | |
todayHighlight: true, | |
/*datesDisabled: ['08/08/2015', '12/08/2015'],*/ | |
toggleActive: true | |
}); | |
$('#birthday').datepicker('update', gsb.data.bday ); | |
$('#subject').select2({ | |
maximumSelectionLength:5, | |
placeholder:'Chọn lĩnh vực chuyên môn', | |
templateSelection: function(data){ return data.text.toLowerCase();} | |
}); | |
$('#gender,#school,#city,#state,#country,#teach_in,#teach_state,#degree,#experience').select2(); | |
$('#skill').select2({ | |
tags:true, | |
tokenSeparators: [','], | |
maximumSelectionLength:10, | |
placeholder:'Vd: Luyện thi học sinh giỏi, anh văn giao tiếp...', | |
templateSelection: function(data){ return data.text.toLowerCase();} | |
}); | |
gsb.google.map.drag(); | |
$("button#done").click(function(){ | |
$('#updateForm').submit(); | |
}); | |
}, | |
cropavatar: function () { | |
gsb.user.edit.opt.customUploadButtonId = 'cropAvatarButton'; | |
gsb.user.edit.opt.cropUrl = gsb.data.url + '/photo/crop'; | |
gsb.user.edit.opt.doubleZoomControls = false; | |
new Croppic('croppicavatar', gsb.user.edit.opt); | |
}, | |
cropcover: function () { | |
gsb.user.edit.opt.customUploadButtonId = 'cropCoverButton'; | |
gsb.user.edit.opt.cropUrl = gsb.data.url + '/photo/crop'; | |
gsb.user.edit.opt.doubleZoomControls = true; | |
new Croppic('croppiccover', gsb.user.edit.opt); | |
}, | |
textarea:function(){ | |
$('#about').popover(); | |
}, | |
tinymce:function(){ | |
tinymce.init({ | |
selector: "#about", | |
menu:[], | |
toolbar: "", | |
setup: function (editor) { | |
// Set placeholder | |
var placeholder = $.trim($('#' + editor.id).attr('placeholder')); | |
if (typeof placeholder !== 'undefined' && placeholder !== false) { | |
var is_default = false; | |
editor.on('init', function () { | |
// get the current content | |
var content = $.trim(editor.getContent()); | |
// If its empty and we have a placeholder set the value | |
if (content.length === 0) { | |
editor.setContent(placeholder); | |
// Get updated content | |
content = placeholder; | |
} | |
// convert to plain text and compare strings | |
is_default = (content == placeholder); | |
// nothing to do | |
if (!is_default) { | |
return; | |
} | |
}) | |
.on('focus', function () { | |
if ($.trim(editor.getContent()) == '<p>'+placeholder+'</p>'){ | |
editor.setContent(''); | |
} | |
}) | |
.on('blur', function () { | |
if ($.trim(editor.getContent()).length === 0) { | |
editor.setContent(placeholder); | |
} | |
}); | |
} | |
} | |
}); | |
} | |
}, | |
browse:{ | |
init: function () { | |
gsb.library.more_less('user'); | |
$('input:radio[name="city-name"]').change(function(){ | |
window.location= $(this).data('url'); | |
}); | |
} | |
} | |
}, | |
job:{ | |
data:{ | |
schedule:{} | |
}, | |
post:{ | |
init:function(){ | |
gsb.job.post.textarea(); | |
gsb.library.html.select(); | |
$('#skill').tagEditor({ | |
initialTags: [], | |
autocomplete: { | |
delay: 0, | |
position: { collision: 'flip' }, | |
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'] | |
}, | |
placeholder: 'Vd: Luyện thi học sinh giỏi, Toán lớp 6, Tin học văn phòng ...', | |
onChange: function(field, editor, tags) { console.log(tags) } | |
}); | |
$('#expired').datepicker({ | |
format: "dd/mm/yyyy", | |
language: "vi", | |
autoclose: true, | |
startDate: "+5d", | |
endDate: "+30d", | |
todayHighlight: true, | |
toggleActive: true | |
}); | |
$('#job_type').change(function(){ | |
if($(this).val()==2){ | |
$('label#price-label').text("Thù lao tối đa/buổi"); | |
} else { | |
$('label#price-label').text("Thù lao/buổi"); | |
} | |
}); | |
gsb.job.post.action.cal_hover(); | |
gsb.job.post.action.cal_click(); | |
gsb.job.post.action.cal_initial(); | |
gsb.job.post.action.map_initial(); | |
$(".fix-table").freezeHeader(); | |
$("button#done").click(function(){ | |
// check du lieu schedule post len phai la json | |
if(!gsb.library.is_json($('#schedule').val())) return; | |
$('#createForm').submit(); | |
}); | |
gsb.google.map.drag(); | |
}, | |
textarea:function(){ | |
$('#jcontent').popover(); | |
}, | |
action: { | |
cal_hover: function() { | |
var cls = ''; | |
$('div[class^="col-"]').hover( | |
function() { | |
col = $(this).attr('class').split(' ')[0]; | |
$('.' + col).each(function() { | |
if ($(this).hasClass('sch')) { | |
$(this).addClass('sch-hover'); | |
} else { | |
$(this).addClass('week-day-hover'); | |
} | |
}); | |
}, | |
function() { | |
col = $(this).attr('class').split(' ')[0]; | |
$('.' + col).each(function() { | |
if ($(this).hasClass('sch')) { | |
$(this).removeClass('sch-hover'); | |
} else { | |
$(this).removeClass('week-day-hover'); | |
} | |
}); | |
} | |
); | |
}, | |
cal_click: function() { | |
$('div.maru').unbind('click').click(function() { | |
if($(this).hasClass('sch-disabled')){ return; } | |
day = $(this).data('day'); | |
slot= $(this).data('slot'); | |
col = $(this).attr('class').split(' ')[0]; | |
if($(this).hasClass('sch-selected')){ | |
$(this).removeClass('sch-selected'); | |
// remove class sch-disabled | |
$('.' + col).each(function() { | |
$(this).removeClass('sch-disabled'); | |
}); | |
delete gsb.job.data.schedule[day];// unset data | |
gsb.job.post.action.day_per_week(gsb.job.data.schedule); | |
} else { | |
$(this).addClass('sch-selected'); | |
// add class sch-disabled | |
$('.' + col).each(function() { | |
if (!$(this).hasClass('sch-selected')) { | |
$(this).addClass('sch-disabled'); | |
} | |
}); | |
gsb.job.data.schedule[day] = slot;// set data | |
gsb.job.post.action.day_per_week(gsb.job.data.schedule); | |
} | |
}); | |
}, | |
cal_initial: function(){ | |
var schedules = gsb.library.parse_json($('#schedule').val()); | |
$.each(schedules, function( index, value ) { | |
var selected = $('div.sch[data-day="'+index+'"][data-slot="'+value+'"]'); | |
var cls = selected.attr('class'); | |
selected.click(); | |
}); | |
}, | |
day_per_week: function(sch){ | |
$('#schedule').val(JSON.stringify(sch)); | |
total = Object.keys(sch).length; | |
if(total==0){ | |
$('#totals').text('chọn thời gian bắt đầu'); | |
} else { | |
$('#totals').text(total+' buổi/tuần'); | |
} | |
}, | |
map_initial: function(){ | |
var latlng = $('#latlng').val(); | |
if(latlng=='[lat:lng]') {return;} | |
latlng = $('#latlng').val().split(':'); | |
gsb.data.lat = latlng[0]; | |
gsb.data.lng = latlng[1]; | |
} | |
} | |
}, | |
view:{ | |
init:function (){ | |
$('#price').keyup(function(){ | |
gsb.job.view.action.chek_price($(this)); | |
}); | |
$('#price').change(function(){ | |
gsb.job.view.action.chek_price($(this)); | |
}); | |
$('#start').datepicker({ | |
format: "dd/mm/yyyy", | |
language: "vi", | |
autoclose: true, | |
startDate: "+0d", | |
endDate: gsb.data.enddate, | |
daysOfWeekDisabled: gsb.data.disabled, | |
toggleActive: true | |
}); | |
$("#start").focusin(function(){$(this).prop("readonly",true)}); | |
$("#start").focusout(function(){$(this).prop("readonly",false)}); | |
$("#start").change(function(){$(this).valid()}); | |
$('#accept').change(function(){ | |
gsb.job.view.action.chek_price($('#price')); | |
gsb.job.view.action.aceppted($(this)); | |
}); | |
$("#apply").click(function(){$(".job-apply").show();$(".call-to-action").hide();}); | |
gsb.job.view.action.form_valid(); // validation | |
$("button#done").click(function(){ | |
$("#applyForm").valid(); | |
gsb.job.view.action.aceppted($('#accept')); | |
if(!$("#applyForm").valid()) return false; | |
if(!gsb.job.view.action.aceppted($('#accept'))) return false; | |
// ajax to | |
var params = { | |
_token:gsb.data.csrf, | |
job_id:gsb.data.job.id, | |
content:$('#jcontent').val(), | |
price:$('#price').val(), | |
start:$('#start').val(), | |
accept:$('#accept').val() | |
}; | |
gsb.ajax.json(gsb.data.job.urly, params, function () { | |
$('#popup-content').html(gsb.ajax.result.success.msg); | |
$('#popup-title').html(gsb.ajax.result.success.tit); | |
$('.tgs-fas').popup({transition: 'all 0.3s',onclose: function () {location.reload();}}); | |
$('.popup-close').click(function(){$('.tgs-fas').popup('hide');}); | |
$('.tgs-fas').popup('show'); | |
}); | |
}); | |
// hire a tutor | |
$('.job-hire').click(function(){ | |
// ajax to hire | |
var params = { | |
_token:gsb.data.csrf, | |
job_id:gsb.data.job.id, | |
tutor_id:$(this).data('tutor') | |
}; | |
gsb.ajax.json(gsb.data.job.urle, params, function () { | |
$('#popup-content').html(gsb.ajax.result.success.msg); | |
$('#popup-title').html(gsb.ajax.result.success.tit); | |
$('.tgs-fas').popup({transition: 'all 0.3s',onclose: function () {location.reload();}}); | |
$('.popup-close').click(function(){$('.tgs-fas').popup('hide');}); | |
$('.tgs-fas').popup('show'); | |
}); | |
}); | |
// load google map | |
gsb.google.map.view(); | |
}, | |
action:{ | |
form_valid: function () { | |
$("#applyForm").validate({ | |
rules: { | |
content: { | |
required: true, | |
minlength: 200, | |
maxlength: 2000 | |
}, | |
price: { | |
required: true, | |
number: true, | |
min: 80000 | |
}, | |
start: { | |
required: true | |
} | |
}, | |
messages: { | |
content: { | |
required: "Bắt buộc phải nhập.", | |
minlength: "Độ dài tối thiểu 200 kí tự.", | |
maxlength: "Độ dài tối đa 2000 kí tự." | |
}, | |
price: { | |
required: "Bắt buộc phải nhập.", | |
number: "Phải là một số.", | |
min: "Tối thiểu 80.000 ₫." | |
}, | |
start: { | |
required: "Bắt buộc phải nhập." | |
} | |
}, | |
submitHandler:function(a){if($(a).valid()){a.submit()}return false} | |
}); | |
}, | |
aceppted: function(c){ | |
if(c.is(':checked')){ | |
$('.agree-to-rules').removeClass('agree-to-rules-error'); | |
$('.agree-to-rules').addClass('agree-to-rules-ok'); | |
return true; | |
} else { | |
$('.agree-to-rules').addClass('agree-to-rules-error'); | |
$('.agree-to-rules').removeClass('agree-to-rules-ok'); | |
return false; | |
} | |
}, | |
chek_price: function(p){ | |
var price = p.val(); | |
var salary = price * gsb.data.job.dpm; | |
var fee = Math.ceil(salary * gsb.data.job.fee / 1000) * 1000; | |
if(p.valid()){ | |
$('#slr').text('Thù lao: '+$.number(salary,0,'.','.')+' ₫/tháng'); | |
$('#fee').text('Lệ phí: '+$.number(fee,0,'.','.')+' ₫(*)'); | |
} else { | |
$('#slr').text('Thù lao: 0 ₫/tháng'); | |
$('#fee').text('Lệ phí: 0 ₫(*)'); | |
} | |
} | |
} | |
}, | |
edit:{}, | |
browse:{ | |
init:function (){ | |
gsb.library.more_less('job'); | |
$('input:radio[name="city-name"]').change(function(){ | |
window.location= $(this).data('url'); | |
}); | |
} | |
}, | |
tags:{ | |
init:function (){ | |
} | |
} | |
}, | |
ajax: { | |
result:{}, | |
html: function(url, data, container, call_back) { | |
var error = false; | |
$.ajax({ | |
type: "POST", | |
url: url, | |
data: data, | |
dataType: "html", | |
async: true, | |
beforeSend: function() {/*do something*/}, | |
success: function(html) { | |
if(gsb.library.is_json(html)){ | |
gsb.ajax.result = gsb.library.parse_json(html); | |
if (gsb.ajax.result.error) { | |
error = true; | |
alert(gsb.ajax.result.error.msg); | |
} | |
} else { | |
$(container).html(html); | |
if (typeof call_back == 'function'){call_back.call();} | |
} | |
}, | |
error: function(error) {} | |
}); | |
return gsb.ajax.result; | |
}, | |
json: function(url, data, call_back) { | |
$.ajax({ | |
type: "POST", | |
url: url, | |
data: data, | |
dataType: "json", | |
async: true, | |
beforeSend: function() {/*do something*/}, | |
success: function(json) { | |
try { | |
gsb.ajax.result = json; | |
if (gsb.ajax.result.error) { | |
gsb.popup.refresh = gsb.ajax.result.error.rfr; | |
gsb.popup.fas(gsb.ajax.result.error.tit,gsb.ajax.result.error.msg); | |
} else {if (typeof call_back == 'function'){call_back.call();}} | |
} catch (e) {alert(json);} | |
}, | |
error: function(error) {/* do something */} | |
}); | |
return gsb.ajax.result; | |
}, | |
xml: function(){ | |
$.ajax({ | |
type: "POST", | |
url: url, | |
data: data, | |
dataType: "xml", | |
async: false, | |
beforeSend: function() {/* do something */}, | |
success: function(xml) {}, | |
error: function(error) {/* do something */} | |
}); | |
} | |
}, | |
popup:{ | |
refresh:false, | |
fas: function(title, msg){ | |
$('#popup-content').html(msg); | |
$('#popup-title').html(title); | |
$('.popup-close').click(function(){$('.tgs-fas').popup('hide');}); | |
$('.tgs-fas').popup({transition: 'all 0.3s',onclose: function () { if(gsb.popup.refresh){location.reload();}}}); | |
$('.tgs-fas').popup('show'); | |
} | |
}, | |
error:{ | |
unauthorized: function (msg) { | |
} | |
}, | |
library: { | |
html:{ | |
//custom placeholder for select field | |
select: function(){$("select").change(function(){if($(this).val()==""){$(this).removeClass("no-empty")}else{$(this).addClass("no-empty")}});$("select").change();}, | |
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()});}, | |
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")}});} | |
}, | |
more_less: function(obj){// obj user or job | |
$('.jobs-list .view-more, .users-list .view-more').click(function(){ | |
var id = $(this).parent().parent().attr('id'); | |
$('#'+id+' .'+obj+'-desc-short').hide(); | |
$('#'+id+' .'+obj+'-desc').show(); | |
}); | |
$('.jobs-list .view-less, .users-list .view-less').click(function(){ | |
var id = $(this).parent().parent().attr('id'); | |
$('#'+id+' .'+obj+'-desc').hide(); | |
$('#'+id+' .'+obj+'-desc-short').show(); | |
}); | |
}, | |
parse_json: function(json){return $.parseJSON(json);}, | |
is_json :function (string){ try { $.parseJSON(string);} catch (e) { return false; }return true;}, | |
array_intersect:function(a,b){return $.grep(a, function(i){return $.inArray(i, b) > -1;});}, | |
scroll: function(element, offset) {$('html, body').animate({scrollTop: $(element).offset().top - parseInt(offset)}, 500);} | |
}, | |
google:{ | |
analytics: {}, | |
map: { | |
drag:function(){ | |
var loc = new google.maps.LatLng(gsb.data.lat, gsb.data.lng); | |
function initialize() { | |
var prop = { | |
center: loc, | |
zoom: 1, | |
mapTypeControl: false, | |
streetViewControl: false, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}; | |
var map = new google.maps.Map(document.getElementById("map"), prop); | |
// make circle | |
var radius = 1000;//1km | |
var around = new google.maps.Circle({ | |
center: loc, | |
radius: radius, | |
strokeColor: "#4D6AA4", | |
strokeOpacity: 0.0, | |
strokeWeight: 1, | |
fillColor: "#4D6AA4", | |
fillOpacity: 0.0 | |
}); | |
// make map fit with circle | |
map.fitBounds(around.getBounds()); | |
around.setMap(map); | |
// add marker for map | |
var marker = new google.maps.Marker({ | |
position: loc, | |
map: map, | |
draggable: true, | |
icon: gsb.data.url + '/img/icons/pin7.png' | |
}); | |
gsb.google.map.myloc(map,marker); | |
google.maps.event.addListener(marker, 'dragend', function () { | |
var lat = this.getPosition().lat().toFixed(6); | |
var lng = this.getPosition().lng().toFixed(6); | |
$('#latlng').val(lat+':'+lng); | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); | |
}, | |
view:function(){ | |
var loc = new google.maps.LatLng(gsb.data.lat, gsb.data.lng); | |
function initialize() { | |
var prop = { | |
center: loc, | |
zoom: 1, | |
mapTypeControl: false, | |
streetViewControl: false, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}; | |
var map = new google.maps.Map(document.getElementById("map"), prop); | |
// make circle | |
var radius = 1000;//1km | |
var around = new google.maps.Circle({ | |
center: loc, | |
radius: radius, | |
strokeColor: "#4D6AA4", | |
strokeOpacity: 0.0, | |
strokeWeight: 1, | |
fillColor: "#4D6AA4", | |
fillOpacity: 0.0 | |
}); | |
// make map fit with circle | |
map.fitBounds(around.getBounds()); | |
around.setMap(map); | |
// add marker for map | |
var marker = new google.maps.Marker({ | |
position: loc, | |
map: map, | |
draggable: false, | |
icon: gsb.data.url + '/img/icons/pin3.png' | |
}); | |
google.maps.event.addListener(marker, 'dragend', function () { | |
var lat = this.getPosition().lat().toFixed(6); | |
var lng = this.getPosition().lng().toFixed(6); | |
$('#latlng').val(lat+':'+lng); | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); | |
}, | |
radius:function(){ | |
var loc = new google.maps.LatLng(gsb.data.lat, gsb.data.lng); | |
function initialize() { | |
var prop = { | |
center: loc, | |
zoom: 1, | |
mapTypeControl: false, | |
streetViewControl: false, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}; | |
var map = new google.maps.Map(document.getElementById("map"), prop); | |
// make circle | |
var radius = 1000;//1km | |
var around = new google.maps.Circle({ | |
center: loc, | |
radius: radius, | |
strokeColor: "#4D6AA4", | |
strokeOpacity: 0.37254901960784315, | |
strokeWeight: 1, | |
fillColor: "#4D6AA4", | |
fillOpacity: 0.11764705882352941 | |
}); | |
// make map fit with circle | |
map.fitBounds(around.getBounds()); | |
around.setMap(map); | |
// add marker for map | |
var marker = new google.maps.Marker({ | |
position: loc, | |
map: map, | |
draggable: false, | |
icon: gsb.data.url + '/img/icons/pin7.png' | |
}); | |
google.maps.event.addListener(marker, 'dragend', function () { | |
console.log(this.getPosition().lat().toFixed(4)); | |
console.log(this.getPosition().lng().toFixed(4)); | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); | |
}, | |
myloc: function (map, marker) { | |
var controlDiv = document.createElement('div'); | |
var firstChild = document.createElement('button'); | |
firstChild.id = 'my-loc-button'; | |
firstChild.title = 'Ví trí của bạn'; | |
controlDiv.appendChild(firstChild); | |
var secondChild = document.createElement('div'); | |
secondChild.id = 'my-loc-img'; | |
firstChild.appendChild(secondChild); | |
google.maps.event.addListener(map, 'dragend', function () { | |
$('#my-loc-img').css('background-position', '0px 0px'); | |
}); | |
firstChild.addEventListener('click', function () { | |
var imgX = '0'; | |
var animationInterval = setInterval(function () { | |
if (imgX == '-18') { imgX = '0'; } | |
else { imgX = '-18'; } | |
$('#my-loc-img').css('background-position', imgX + 'px 0px'); | |
}, 500); | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(function (position) { | |
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); | |
marker.setPosition(latlng); | |
map.setCenter(latlng); | |
clearInterval(animationInterval); | |
$('#my-loc-img').css('background-position', '-144px 0px'); | |
}); | |
} | |
else { | |
clearInterval(animationInterval); | |
$('#my-loc-img').css('background-position', '0px 0px'); | |
} | |
}); | |
controlDiv.index = 1; | |
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(controlDiv); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment