I started writing a jQuery plugin and I want to be able to:
- initialize it when i call it so
$('selector').sitemap(options); - use some elements (for example, "loader", "viewPort") in functions in the plugin
Pay attention to the 1st problem : did I do it the way I wrote the initialization (init function), or is there a more correct / elegant way to do this?
Pay attention to the second problem : to use elements such as 'loader', 'viewPort', I wrote all the functions in the sitemap object. Did I do it right or is there a more correct / elegant way to do this?
(function ($) {
$.extend($.fn, {
sitemap: function (options) {
var canvas = this;
if (!canvas.is('div')) return;
var viewPort = null;
var loader = $('<p id="initLoader">Loading...</p>');
init();
loadMap();
function init() {
setCanvas();
}
function setCanvas() {
}
function loadMap() {
viewPort.prepend(loader);
buildMap($.parseJSON('{"pages":[]}'));
}
function buildMap(map){
}
})(jQuery);
source
share