Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
  var pluginName = "intlTelInput";
2
 
3
	// A really lightweight plugin wrapper around the constructor,
4
	// preventing against multiple instantiations
5
	$.fn[pluginName] = function(options) {
6
    var args = arguments;
7
 
8
    // Is the first parameter an object (options), or was omitted, instantiate a new instance of the plugin.
9
    if (options === undefined || typeof options === "object") {
10
			return this.each(function() {
11
				if (!$.data(this, "plugin_" + pluginName)) {
12
          var iti = new Iti(this, options);
13
          iti._init();
14
          window.intlTelInputGlobals.instances[iti.id] = iti;
15
					$.data(this, "plugin_" + pluginName, iti);
16
				}
17
			});
18
    } else if (typeof options === "string" && options[0] !== "_") {
19
      // If the first parameter is a string and it doesn't start with an underscore treat this as a call to a public method.
20
 
21
      // Cache the method call to make it possible to return a value
22
      var returns;
23
      this.each(function() {
24
        var instance = $.data(this, "plugin_" + pluginName);
25
 
26
        // Tests that there's already a plugin-instance and checks that the requested public method exists
27
        if (instance instanceof Iti && typeof instance[options] === "function") {
28
          // Call the method of our plugin instance, and pass it the supplied arguments.
29
          returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1));
30
        }
31
 
32
        // Allow instances to be destroyed via the 'destroy' method
33
        if (options === "destroy") $.data(this, "plugin_" + pluginName, null);
34
      });
35
 
36
      // If the earlier cached method gives a value back return the value, otherwise return this to preserve chainability.
37
      return returns !== undefined ? returns : this;
38
    }
39
	};
40
}));