jQuery Boilerplate

Jump-starting jQuery plugins development

Beinhaltet viele Kommentare um leicht loslegen zu kรถnnen. Es ist komplett Object ortientiert und beinhaltet, public und private Methoden sowie public und private Eigenschaften, was es zum idealen Kandidaten fรผr die Entwicklung einfacher und komplexer jQuery Plugins macht

Es folgt nicht den Vorschlรคgen der jQuery Dokumentation fรผr Plugin/Entwicklung weshalb es bessere Performance und Speicherauslastung bietet weil es nicht fรผr jedes Element eine eigene Instanze des Plugins erstellt.

Download now Fork on Github

Benutzung


$(document).ready(function() {

   // erstellt eine neue Instanz des Plugins
   var myplugin = new $.pluginName($('#element'));

   // ruft eine public Methode auf
   myplugin.fooPublicMethod();

   // gibt den wert einer public Eigenschaft
   myplugin.settings.property;

});
		

jQuery Boilerplate (kompakte Version, ohne Kommentare)


;(function($) {

   $.pluginName = function(el, options) {

      var defaults = {
         propertyName: 'value',
         onSomeEvent: function() {}
      }

      var plugin = this;

      plugin.settings = {}

      var init = function() {
         plugin.settings = $.extend({}, defaults, options);
         plugin.el = el;
         // code hier
      }

      plugin.fooPublicMethod = function() {
         // code hier
      }

      var fooPrivateMethod = function() {
         // code hier
      }

      init();

   }

})(jQuery);
      
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.