Created
November 11, 2018 01:07
-
-
Save Kcko/165384b61d505224ec732bd1814a3bcc to your computer and use it in GitHub Desktop.
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
;(function($) { | |
var privateFunction = function () { | |
//do something | |
} | |
var methods = { | |
init : function( options ) { | |
var defaults = { | |
center: { | |
lat: -36.8442, | |
lng: 174.7676 | |
} | |
}; | |
var t = $.extend(true, defaults, options); | |
return this.each(function () { | |
var $this = $(this), | |
data = $this.data('myMapPlugin'); | |
if ( !data ) { | |
var map = new google.maps.Map(this, { | |
zoom: 8, | |
center: new google.maps.LatLng(t['center'][lat], t['center']['lng']), | |
mapTypeId: google.maps.MapTypeId.ROADMAP, | |
mapTypeControlOptions:{ | |
mapTypeIds: [google.maps.MapTypeId.ROADMAP] | |
} | |
}); | |
var geocoder = new google.maps.Geocoder(); | |
var $form = $('form', $this.parent()); | |
var form = $form.get(0); | |
var $search = $('input[data-type=search]', $form); | |
$form.submit(function () { | |
$this.myMapPlugin('search', $search.val()); | |
return false; | |
}); | |
google.maps.event.addListener(map, 'idle', function () { | |
// do something | |
}); | |
$this.data('myMapPlugin', { | |
'target': $this, | |
'map': map, | |
'form':form, | |
'geocoder':geocoder | |
}); | |
} | |
}); | |
}, | |
resize : function ( ) { | |
return this.each(function(){ | |
var $this = $(this), | |
data = $this.data('myMapPlugin'); | |
google.maps.event.trigger(data.map, 'resize'); | |
}); | |
}, | |
search : function ( searchString ) { | |
return this.each(function () { | |
// do something with geocoder | |
}); | |
}, | |
update : function ( content ) { | |
// ToDo | |
}, | |
destroy : function ( ) { | |
return this.each(function(){ | |
var $this = $(this), | |
data = $this.data('myMapPlugin'); | |
$(window).unbind('.locationmap'); | |
data.locationmap.remove(); | |
$this.removeData('locationmap'); | |
}); | |
} | |
}; | |
$.fn.myMapPlugin = function (method) { | |
if ( methods[method] ) { | |
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); | |
} else if ( typeof method === 'object' || ! method ) { | |
return methods.init.apply( this, arguments ); | |
} else { | |
$.error( 'Method ' + method + ' does not exist on jQuery.myMapPlugin' ); | |
} | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment