Permalink
Browse files

Removed version from filename, added build instructions

  • Loading branch information...
1 parent cea03fd commit 2ece1a033fbdb4403bcdee06d6f12dc4d4d0dc24 @markdalgleish committed Aug 15, 2011
Showing with 61 additions and 0 deletions.
  1. +7 −0 README.md
  2. +47 −0 tmpload.js
  3. +7 −0 tmpload.min.js
View
@@ -12,6 +12,13 @@ Usage
Beginner's guide available at the [official tmpload page](http://markdalgleish.com/projects/tmpload).
+How to Build
+------------
+
+The code is minified using UglifyJS using the following command:
+
+`uglifyjs -o tmpload.min.js tmpload.js`
+
Questions?
----------
View
@@ -0,0 +1,47 @@
+/*
+tmpload jQuery Plugin v1.1
+Copyright 2011, Mark Dalgleish
+
+This content is released under the MIT License
+github.com/markdalgleish/tmpload/blob/master/MIT-LICENSE.txt
+*/
+(function($, undefined) {
+ //Template cache
+ var templates = {};
+
+ $.tmpload = function(obj, url) {
+ if (url === undefined) {
+ //Declaring template(s)
+ if (typeof obj === "object") {
+ if (obj.length) {
+ //Array of declaration objects
+ for (var i = 0; i < obj.length; i++) {
+ templates[obj[i].name] = obj[i].url;
+ }
+ } else {
+ //A single declaration object
+ templates[obj.name] = obj.url;
+ }
+ }
+ //Loading the template
+ else if (typeof obj === "string") {
+ if (typeof templates[obj] === "string") {
+ //The template hasn't been loaded yet
+ return templates[obj] = $.Deferred(function(dfd) {
+ $.get(templates[obj]).success(function(d) {
+ dfd.resolve($.template(obj, d));
+ }).error(function(d) {
+ dfd.reject(d);
+ });
+ }).promise();
+ } else {
+ //The template has already been cached
+ return templates[obj];
+ }
+ }
+ //Declaring a single template
+ } else {
+ templates[obj] = url;
+ }
+ };
+})(jQuery);
View
@@ -0,0 +1,7 @@
+/*
+tmpload jQuery Plugin v1.1
+Copyright 2011, Mark Dalgleish
+
+This content is released under the MIT License
+github.com/markdalgleish/tmpload/blob/master/MIT-LICENSE.txt
+*/(function(a,b){var c={};a.tmpload=function(d,e){if(e===b){if(typeof d=="object")if(d.length)for(var f=0;f<d.length;f++)c[d[f].name]=d[f].url;else c[d.name]=d.url;else if(typeof d=="string")return typeof c[d]=="string"?c[d]=a.Deferred(function(b){a.get(c[d]).success(function(c){b.resolve(a.template(d,c))}).error(function(a){b.reject(a)})}).promise():c[d]}else c[d]=e}})(jQuery)

0 comments on commit 2ece1a0

Please sign in to comment.