From 523175003496d75253648488c093279aa6226e7c Mon Sep 17 00:00:00 2001 From: Indigo744 Date: Sat, 21 Nov 2015 23:56:01 +0100 Subject: [PATCH 1/3] New arch: add init method --- js/jquery.mapael.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/js/jquery.mapael.js b/js/jquery.mapael.js index a93b53a..12d8f4e 100644 --- a/js/jquery.mapael.js +++ b/js/jquery.mapael.js @@ -212,14 +212,20 @@ // Avoid multiple instanciation if ($.data(this, pluginName)) throw new Error("Mapael already exists on this element."); - + // Save instanciation on element // This allow external access to Mapael using $(".mapcontainer").data("mapael") $.data(this, pluginName, Mapael); - var $container = $(this) // the current element + Mapael.init(this, options); + + }); + }; + + Mapael.init = function(container, options) { + var $container = $(container) // the current element , $tooltip = $("
").addClass(options.map.tooltip.cssClass).css("display", "none") // the tooltip container - , $map = $("." + options.map.cssClass, this).empty().append($tooltip) // the map container + , $map = $("." + options.map.cssClass, container).empty().append($tooltip) // the map container , mapConf = $.fn[pluginName].maps[options.map.name] , paper = new Raphael($map[0], mapConf.width, mapConf.height) , elemOptions = {} @@ -638,7 +644,7 @@ if (options.map.afterInit) options.map.afterInit($container, paper, areas, plots, options); $(paper.desc).append(" and Mapael (http://www.vincentbroute.fr/mapael/)"); - }); + }; /* From 417392d1ce3a8d21673786d1896dddf47fb34d44 Mon Sep 17 00:00:00 2001 From: Indigo744 Date: Sun, 22 Nov 2015 00:01:32 +0100 Subject: [PATCH 2/3] Moved members after constructor (and before init) --- js/jquery.mapael.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/js/jquery.mapael.js b/js/jquery.mapael.js index 12d8f4e..914e765 100644 --- a/js/jquery.mapael.js +++ b/js/jquery.mapael.js @@ -222,6 +222,23 @@ }); }; + /* + * Version number of jQuery Mapael. See http://semver.org/ for more information. + * @type string + */ + Mapael.version = '1.1.0'; + + /* zoom TimeOut handler (used to set and clear) */ + Mapael.zoomTO = 0; + + /* Panning: tell if panning action is in progress */ + Mapael.panning = false; + /* Panning TimeOut handler (used to set and clear) */ + Mapael.panningTO = 0; + + /* Animate view box Interval handler (used to set and clear) */ + Mapael.animationIntervalID = null; + Mapael.init = function(container, options) { var $container = $(container) // the current element , $tooltip = $("
").addClass(options.map.tooltip.cssClass).css("display", "none") // the tooltip container @@ -647,14 +664,6 @@ }; - /* - * Version number of jQuery Mapael. See http://semver.org/ for more information. - * @type string - */ - Mapael.version = '1.1.0'; - - Mapael.zoomTO = 0; - /* * Init the element "elem" on the map (drawing, setting attributes, events, tooltip, ...) */ @@ -1015,9 +1024,6 @@ }); }; - Mapael.panning = false; - Mapael.panningTO = 0; - /* * Init zoom and panning for the map * @param $map @@ -1575,7 +1581,6 @@ return {}; }; - Mapael.animationIntervalID = null; /* * Animated view box changes From f523484039aed2eb6de9d312b2dddd50686e7ef9 Mon Sep 17 00:00:00 2001 From: Indigo744 Date: Sun, 22 Nov 2015 00:08:13 +0100 Subject: [PATCH 3/3] Added comments Conflicts: js/jquery.mapael.js --- js/jquery.mapael.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/js/jquery.mapael.js b/js/jquery.mapael.js index 914e765..d196009 100644 --- a/js/jquery.mapael.js +++ b/js/jquery.mapael.js @@ -28,7 +28,6 @@ var pluginName = "mapael"; - // Default map options var defaultOptions = { map : { @@ -132,6 +131,7 @@ , links : {} }; + // Default legends option var legendDefaultOptions = { area : { cssClass : "areaLegend" @@ -194,11 +194,17 @@ } }; + /* + * Mapael constructor + * Called directly on DOM element to apply the plugin + * @param options the user options + */ var Mapael = function(options) { - // Extend legend default options with user options + // Extend default options with user options options = $.extend(true, {}, defaultOptions, options); + // Extend each legend default options with user options $.each(options.legend, function(type) { if ($.isArray(options.legend[type])) { for (var i = 0; i < options.legend[type].length; ++i) @@ -208,6 +214,7 @@ } }); + // Init the plugin on each DOM element return this.each(function() { // Avoid multiple instanciation @@ -217,8 +224,8 @@ // This allow external access to Mapael using $(".mapcontainer").data("mapael") $.data(this, pluginName, Mapael); + // Initialize Mapael.init(this, options); - }); }; @@ -239,6 +246,12 @@ /* Animate view box Interval handler (used to set and clear) */ Mapael.animationIntervalID = null; + /* + * Initialize the plugin + * Called by the constructor + * @param container the DOM element on which to apply the plugin + * @param options the complete options to use + */ Mapael.init = function(container, options) { var $container = $(container) // the current element , $tooltip = $("
").addClass(options.map.tooltip.cssClass).css("display", "none") // the tooltip container