User:MateyY/Template.js

/* Template.js * Creates interactive templates * Version v.1.1 * Name the class name and, if any, other specific selectors * By MateyY */ (function($,window) {    var Template = function(info) {          if (info && typeof info !== "object" || !info) throw new Error("Template invoked without object holding information.");          if (!info["class"]) throw new Error("No template class name specified.");          if (!info.value) throw new Error("No template value specified.");          var elements = info.selectors ? $("." + info["class"]).filter(info.selectors) : $("." + info["class"]);         this.defaultValues = [];          for (var i = 0; i < elements.length; i++) {               this.defaultValues.push({element: elements[i], value: elements.eq(i).html});          }          elements.html(typeof info.value === "function" ? info.value : info.value);              this.elements = elements.toArray;               this.length = elements.length;     };     Template.prototype = {          toDefault: function(elm) {               for (var i = 0; i < this.defaultValues.length; i++) {                    if ((elm ? elm === this.defaultValues[i].element : elm)) $(this.defaultValues[i].element).html(this.defaultValues[i].value);               }               return this;          }     };     window.Template = Template; })(jQuery,window);