-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.tmpldeck.js
68 lines (58 loc) · 1.67 KB
/
jquery.tmpldeck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*! jQuery.TmplDeck - v0.2.1 - 2/8/2013
* https://github.com/Takazudo/jQuery.TmplDeck
* Copyright (c) 2013 "Takazudo" Takeshi Takatsudo; Licensed MIT */
// Generated by CoffeeScript 1.4.0
(function() {
(function($) {
var TmplDeck;
TmplDeck = (function() {
TmplDeck.prototype._options = {
dataType: 'text',
url: null,
cache: true
};
function TmplDeck(url, options) {
if (!(this instanceof arguments.callee)) {
return new TmplDeck(url, options);
}
this._options = $.extend({}, this._options, {
url: url
});
this._fetchDefer = $.Deferred();
this._cache = {};
}
TmplDeck.prototype.load = function() {
var _this = this;
return ($.ajax(this._options)).then(function(data) {
_this._fetchedText = data;
return _this._fetchDefer.resolve();
});
};
TmplDeck.prototype.ready = function(fn) {
this._fetchDefer.done(function() {
return fn();
});
return this;
};
TmplDeck.prototype.draw = function(id) {
var cached, re, res;
cached = this._cache[id];
if (cached) {
return cached;
}
re = new RegExp("(^|\\n)" + id + "\\s\{\{\{\{\\r?\\n([\\s\\S]+?)\}\}\}\}");
res = this._fetchedText.match(re);
if (res) {
return (this._cache[id] = res[2]);
} else {
return null;
}
};
return TmplDeck;
})();
TmplDeck.prototype.tmpl = function(id, data) {
return (_.template(this.draw(id)))(data);
};
return $.TmplDeck = TmplDeck;
})(jQuery);
}).call(this);