User:MateyY/Template.js

/* Creates interactive templates * Version 0.1 BETA * 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"]).is(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 {               for (var i = 0; i < this.defaultValues.length; i++) {                    $(this.defaultValues[i].element).html(this.defaultValues[i].value);               }               return this;          }     };     window.Template = Template; })(jQuery,window);