jquery_gantt_rails 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +74 -0
  3. data/.idea/encodings.xml +5 -0
  4. data/.idea/jquery_gantt_rails.iml +9 -0
  5. data/.idea/misc.xml +22 -0
  6. data/.idea/modules.xml +9 -0
  7. data/.idea/scopes/scope_settings.xml +5 -0
  8. data/.idea/vcs.xml +7 -0
  9. data/.ruby-version.rb +1 -0
  10. data/Gemfile +3 -0
  11. data/README.md +41 -0
  12. data/Rakefile +1 -0
  13. data/jquery_gantt_rails.gemspec +20 -0
  14. data/lib/jquery_gantt_rails/version.rb +3 -0
  15. data/lib/jquery_gantt_rails/version.rb~ +3 -0
  16. data/lib/jquery_gantt_rails.rb +9 -0
  17. data/vendor/assets/javascripts/jquery_gantt/README.md +28 -0
  18. data/vendor/assets/javascripts/jquery_gantt/add.gif +0 -0
  19. data/vendor/assets/javascripts/jquery_gantt/alert.gif +0 -0
  20. data/vendor/assets/javascripts/jquery_gantt/closeBig.png +0 -0
  21. data/vendor/assets/javascripts/jquery_gantt/del.gif +0 -0
  22. data/vendor/assets/javascripts/jquery_gantt/edit.gif +0 -0
  23. data/vendor/assets/javascripts/jquery_gantt/gantt.css +323 -0
  24. data/vendor/assets/javascripts/jquery_gantt/gantt.html +547 -0
  25. data/vendor/assets/javascripts/jquery_gantt/ganttDrawer.js +752 -0
  26. data/vendor/assets/javascripts/jquery_gantt/ganttGridEditor.js +518 -0
  27. data/vendor/assets/javascripts/jquery_gantt/ganttMaster.js +702 -0
  28. data/vendor/assets/javascripts/jquery_gantt/ganttTask.js +947 -0
  29. data/vendor/assets/javascripts/jquery_gantt/ganttUtilities.js +237 -0
  30. data/vendor/assets/javascripts/jquery_gantt/gantt_compact.css +323 -0
  31. data/vendor/assets/javascripts/jquery_gantt/hasExternalDeps.png +0 -0
  32. data/vendor/assets/javascripts/jquery_gantt/libs/JST/jquery.JST.js +167 -0
  33. data/vendor/assets/javascripts/jquery_gantt/libs/date.js +584 -0
  34. data/vendor/assets/javascripts/jquery_gantt/libs/dateField/images/next.png +0 -0
  35. data/vendor/assets/javascripts/jquery_gantt/libs/dateField/images/prev.png +0 -0
  36. data/vendor/assets/javascripts/jquery_gantt/libs/dateField/jquery.dateField.css +88 -0
  37. data/vendor/assets/javascripts/jquery_gantt/libs/dateField/jquery.dateField.js +212 -0
  38. data/vendor/assets/javascripts/jquery_gantt/libs/i18nJs.js +140 -0
  39. data/vendor/assets/javascripts/jquery_gantt/libs/jquery.livequery.min.js +11 -0
  40. data/vendor/assets/javascripts/jquery_gantt/libs/jquery.timers.js +142 -0
  41. data/vendor/assets/javascripts/jquery_gantt/libs/platform.js +954 -0
  42. data/vendor/assets/javascripts/jquery_gantt/linkArrow.png +0 -0
  43. data/vendor/assets/javascripts/jquery_gantt/milestone.png +0 -0
  44. data/vendor/assets/javascripts/jquery_gantt/platform.css +346 -0
  45. data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.eot +0 -0
  46. data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.otf +0 -0
  47. data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.svg +152 -0
  48. data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.ttf +0 -0
  49. data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.woff +0 -0
  50. data/vendor/assets/javascripts/jquery_gantt/teamworkFont.css +16 -0
  51. data/vendor/assets/javascripts/jquery_gantt/twGanttSmall.png +0 -0
  52. metadata +107 -0
@@ -0,0 +1,237 @@
1
+ /*
2
+ Copyright (c) 2012-2013 Open Lab
3
+ Written by Roberto Bicchierai and Silvia Chelazzi http://roberto.open-lab.com
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ $.fn.gridify = function(options) {
25
+ this.options = {
26
+ colResizeZoneWidth:10
27
+ };
28
+
29
+ $.extend(this.options, options);
30
+ $.gridify.init($(this), this.options);
31
+ return this;
32
+ };
33
+
34
+ $.gridify = {
35
+ init: function(elems, opt) {
36
+ elems.each(function() {
37
+ var table = $(this);
38
+
39
+ //---------------------- header management start
40
+ table.find("th.gdfColHeader.gdfResizable:not(.gdfied)").mouseover(function() {
41
+ $(this).addClass("gdfColHeaderOver");
42
+
43
+ }).bind("mouseout.gdf", function() {
44
+ $(this).removeClass("gdfColHeaderOver");
45
+ if (!$.gridify.columInResize) {
46
+ $("body").removeClass("gdfHResizing");
47
+ }
48
+
49
+ }).bind("mousemove.gdf", function(e) {
50
+ if (!$.gridify.columInResize) {
51
+ var colHeader = $(this);
52
+ var mousePos = e.pageX - colHeader.offset().left;
53
+
54
+ if (colHeader.width() - mousePos < opt.colResizeZoneWidth) {
55
+ $("body").addClass("gdfHResizing");
56
+ } else {
57
+ $("body").removeClass("gdfHResizing");
58
+ }
59
+ }
60
+
61
+ }).bind("mousedown.gdf", function(e) {
62
+ var colHeader = $(this);
63
+ var mousePos = e.pageX - colHeader.offset().left;
64
+ if (colHeader.width() - mousePos < opt.colResizeZoneWidth) {
65
+ $.gridify.columInResize = $(this);
66
+ //bind event for start resizing
67
+ //console.debug("start resizing");
68
+ $(document).bind("mousemove.gdf", function(e) {
69
+ //manage resizing
70
+ //console.debug(e.pageX - $.gridify.columInResize.offset().left)
71
+ $.gridify.columInResize.width(e.pageX - $.gridify.columInResize.offset().left);
72
+
73
+
74
+ //bind mouse up on body to stop resizing
75
+ }).bind("mouseup.gdf", function() {
76
+ //console.debug("stop resizing");
77
+ $(this).unbind("mousemove.gdf").unbind("mouseup.gdf");
78
+ $("body").removeClass("gdfHResizing");
79
+ delete $.gridify.columInResize;
80
+ });
81
+ }
82
+ }).addClass("gdfied unselectable").attr("unselectable","true");
83
+
84
+
85
+ //---------------------- cell management start wrapping
86
+ table.find("td.gdfCell:not(.gdfied)").each(function() {
87
+ var cell = $(this);
88
+ if (cell.is(".gdfEditable")) {
89
+ var inp = $("<input type='text'>").addClass("gdfCellInput");
90
+ inp.val(cell.text());
91
+ cell.empty().append(inp);
92
+ } else {
93
+ var wrp = $("<div>").addClass("gdfCellWrap");
94
+ wrp.html(cell.html());
95
+ cell.empty().append(wrp);
96
+ }
97
+ }).addClass("gdfied");
98
+ ;
99
+
100
+ });
101
+ }
102
+ };
103
+
104
+ $.splittify = {
105
+ init: function(where, first, second,perc) {
106
+
107
+ perc=perc || 50;
108
+
109
+ var splitter = $("<div>").addClass("splitterContainer");
110
+
111
+ var firstBox = $("<div>").addClass("splitElement splitBox1");
112
+ var splitterBar = $("<div>").addClass("splitElement vSplitBar").attr("unselectable", "on").html("|").css("padding-top",where.height()/2+"px");
113
+ var secondBox = $("<div>").addClass("splitElement splitBox2");
114
+
115
+ firstBox.append(first);
116
+ secondBox.append(second);
117
+
118
+ splitter.append(firstBox);
119
+ splitter.append(secondBox);
120
+ splitter.append(splitterBar);
121
+
122
+
123
+ where.append(splitter);
124
+
125
+ var w = where.innerWidth();
126
+ firstBox.width(w *perc/ 100 - splitterBar.width()).css({left:0});
127
+ splitterBar.css({left:firstBox.width()});
128
+ secondBox.width(w -firstBox.width()-splitterBar.width() ).css({left:firstBox.width() + splitterBar.width()});
129
+
130
+
131
+
132
+ splitterBar.bind("mousedown.gdf", function(e) {
133
+ $.splittify.splitterBar = $(this);
134
+ //bind event for start resizing
135
+ //console.debug("start splitting");
136
+ $("body").unselectable().bind("mousemove.gdf", function(e) {
137
+ //manage resizing
138
+ //console.debug(e.pageX - $.gridify.columInResize.offset().left)
139
+ var sb = $.splittify.splitterBar;
140
+ var pos = e.pageX - sb.parent().offset().left;
141
+ var w = sb.parent().width();
142
+ if (pos > 10 && pos < w - 20) {
143
+ sb.css({left:pos});
144
+ firstBox.width(pos);
145
+ secondBox.css({left:pos + sb.width(),width:w - pos - sb.width()});
146
+ }
147
+
148
+ //bind mouse up on body to stop resizing
149
+ }).bind("mouseup.gdf", function() {
150
+ //console.debug("stop splitting");
151
+ $(this).unbind("mousemove.gdf").unbind("mouseup.gdf").clearUnselectable();
152
+ delete $.splittify.splitterBar;
153
+
154
+ });
155
+ });
156
+
157
+ return {firstBox:firstBox,secondBox:secondBox,splitterBar:splitterBar};
158
+ }
159
+ };
160
+
161
+
162
+
163
+
164
+ //<%------------------------------------------------------------------------ UTILITIES ---------------------------------------------------------------%>
165
+ function computeStart(start) {
166
+ var d = new Date(start+3600000*12);
167
+ d.setHours(0, 0, 0, 0);
168
+ //move to next working day
169
+ while (isHoliday(d)) {
170
+ d.setDate(d.getDate() + 1);
171
+ }
172
+ d.setHours(0, 0, 0, 0);
173
+ return d.getTime();
174
+ }
175
+
176
+ function computeEnd(end) {
177
+ var d = new Date(end-3600000*12);
178
+ d.setHours(23, 59, 59, 999);
179
+ //move to next working day
180
+ while (isHoliday(d)) {
181
+ d.setDate(d.getDate() + 1);
182
+ }
183
+ d.setHours(23, 59, 59, 999);
184
+ return d.getTime();
185
+ }
186
+
187
+ function computeEndByDuration(start, duration) {
188
+ var d = new Date(start);
189
+ //console.debug("computeEndByDuration start ",d,duration)
190
+ var q = duration - 1;
191
+ while (q > 0) {
192
+ d.setDate(d.getDate() + 1);
193
+ if (!isHoliday(d))
194
+ q--;
195
+ }
196
+ d.setHours(23, 59, 59, 999);
197
+ return d.getTime();
198
+ }
199
+
200
+ function incrementDateByWorkingDays(date, days) {
201
+ var d = new Date(date);
202
+ d.incrementDateByWorkingDays(days);
203
+ return d.getTime();
204
+ }
205
+
206
+ function recomputeDuration(start, end) {
207
+ //console.debug("recomputeDuration");
208
+ return new Date(start).distanceInWorkingDays(new Date(end));
209
+ }
210
+
211
+
212
+
213
+ //This prototype is provided by the Mozilla foundation and
214
+ //is distributed under the MIT license.
215
+ //http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
216
+
217
+ if (!Array.prototype.filter){
218
+ Array.prototype.filter = function(fun )
219
+ {
220
+ var len = this.length;
221
+ if (typeof fun != "function")
222
+ throw new TypeError();
223
+
224
+ var res = new Array();
225
+ var thisp = arguments[1];
226
+ for (var i = 0; i < len; i++)
227
+ {
228
+ if (i in this)
229
+ {
230
+ var val = this[i]; // in case fun mutates this
231
+ if (fun.call(thisp, val, i, this))
232
+ res.push(val);
233
+ }
234
+ }
235
+ return res;
236
+ };
237
+ }
@@ -0,0 +1,323 @@
1
+ .gdfTable {
2
+ table-layout: fixed;
3
+ border-collapse: separate;
4
+ border-spacing: 0;
5
+ }
6
+
7
+ .gdfTable td, .gdfTable th {
8
+ vertical-align: middle;
9
+ overflow: hidden;
10
+ text-overflow: clip;
11
+ white-space: nowrap;
12
+ font-size: 10px
13
+ }
14
+
15
+ .gdfCell {
16
+ overflow: hidden;
17
+ padding:1px
18
+ }
19
+
20
+ .gdfColHeader {
21
+ min-width: 5px;
22
+ height: 30px;
23
+ }
24
+
25
+ .gdfCell, .gdfColHeader {
26
+ border-bottom: 1px solid #eee;
27
+ border-right: 1px solid #eee;
28
+ }
29
+
30
+
31
+ .ganttLines{
32
+ position:absolute;
33
+ width:100%;
34
+ height:1px;
35
+ border-top:1px solid #eee;
36
+ z-index:1;
37
+ }
38
+
39
+ .gdfCellInput {
40
+ border: 0 none;
41
+ font-size: 12px;
42
+ height: 14px;
43
+ margin: 0;
44
+ padding: 0;
45
+ width: 100%;
46
+ background-color: #d4fbe8;
47
+ }
48
+
49
+ .gdfCellWrap {
50
+ border: 0 none;
51
+ font-size: 12px;
52
+ height: 14px;
53
+ margin: 0;
54
+ padding: 0;
55
+ width: 100%;
56
+ overflow: hidden;
57
+
58
+ background-color: #ffcccc;
59
+ }
60
+
61
+ .gdfColHeaderOver {
62
+ opacity: .7;
63
+ }
64
+
65
+ .gdfHResizing {
66
+ cursor: w-resize;
67
+ }
68
+
69
+ .splitterContainer {
70
+ width: 100%;
71
+ height: 100%;
72
+ }
73
+
74
+ .splitBox1, .splitBox2 {
75
+ overflow-x: scroll;
76
+ overflow-y: hidden;
77
+
78
+ /*background-color: yellow;*/
79
+ }
80
+
81
+ .splitBox2 {
82
+ /*background-color: orange;*/
83
+ }
84
+
85
+ .unselectable {
86
+ -webkit-user-select: none;
87
+ -khtml-user-select: none;
88
+ -moz-user-select: none;
89
+ -o-user-select: none;
90
+ user-select: none;
91
+ }
92
+
93
+ .splitElement {
94
+ outline-style: none;
95
+ position: absolute;
96
+ height: 100%;
97
+ }
98
+
99
+ .vSplitBar {
100
+ width: 5px;
101
+ background-color: #aaa;
102
+ cursor: w-resize;
103
+ text-align: center;
104
+ color: white;
105
+ }
106
+
107
+ .end{
108
+ border-right:1px dotted #666
109
+ }
110
+
111
+ .holyH{
112
+ background-color: #9CB7AA;
113
+ }
114
+ .holy{
115
+ background-color: #FFF5E6;
116
+ }
117
+
118
+
119
+ .expcoll{
120
+ width:6px;
121
+ height:6px;
122
+ margin:1px;
123
+ padding:1px;
124
+ background-color:yellow;
125
+ display:inline-block;
126
+ border:1px solid gray;
127
+ }
128
+ .expcoll.exp{
129
+ display:none;
130
+ }
131
+
132
+
133
+ .ganttTable{
134
+ table-layout:fixed;
135
+ }
136
+
137
+ .ganttTable td,.ganttTable th{
138
+ overflow: hidden;
139
+ text-overflow: clip;
140
+ white-space: nowrap;
141
+ }
142
+
143
+ .ganttHead1,.ganttHead2{
144
+ height:20px;
145
+ }
146
+
147
+ .ganttHead1 th,.ganttHead2 th{
148
+ border-left:1px solid white;
149
+ }
150
+
151
+ .ganttToday{
152
+ position:absolute;
153
+ top:0;
154
+ width:1px;
155
+ height:100%;
156
+ border-left:2px dotted #13AFA5;
157
+ }
158
+
159
+ .ganttHighLight{
160
+ position:absolute;
161
+ width:100%;
162
+ height:18px;
163
+ background-color:yellow;
164
+ opacity:.4;
165
+ }
166
+
167
+ .ganttButtonBar{
168
+ position:relative;
169
+ padding:5px;
170
+ }
171
+
172
+ .ganttButtonBar .buttons {
173
+ float:left; margin:45px 0 0 40px
174
+ }
175
+
176
+
177
+ .ganttButtonBar .button span.teamworkIcon{
178
+ font-size: 150%
179
+ }
180
+
181
+ .ganttButtonSeparator{
182
+ border-left:1px solid gray;
183
+ padding-right:10px;
184
+ margin-left:10px;
185
+ font-size: 130%
186
+ }
187
+
188
+ .ganttLinks{
189
+ z-index:10;
190
+ }
191
+
192
+ .taskBox{
193
+ position:absolute;
194
+ height:18px;
195
+ margin-top:1px;
196
+ z-index:100;
197
+ }
198
+
199
+ .taskBox .layout {
200
+ height:100%;
201
+ color:red;
202
+ border-radius:2px;
203
+ background: #eee; /* Old browsers */
204
+ border:1px solid #bbb;
205
+ }
206
+
207
+ .taskBox .taskStatus {
208
+ left:5px;
209
+ top:4px;
210
+ position:absolute;
211
+ width:10px;
212
+ height:10px;
213
+ }
214
+
215
+ .taskBox .layout .milestone{
216
+ top:0px;
217
+ position:absolute;
218
+ width:16px;
219
+ background: url(milestone.png) no-repeat;
220
+ height:16px;
221
+ display:none;
222
+ }
223
+ .taskBox .layout .milestone.end{
224
+ right:0;
225
+ }
226
+ .taskBox .layout .milestone.active{
227
+ display:block;
228
+ }
229
+
230
+ .taskBox.hasChild .layout{
231
+ border-top:2px solid black;
232
+ }
233
+
234
+ .taskBox .taskProgress{
235
+ height:5px;
236
+ position:absolute;
237
+ }
238
+
239
+ .taskBox .layout.extDep{
240
+ background-image:url(hasExternalDeps.png);
241
+ }
242
+
243
+
244
+ .taskLabel{
245
+ position:absolute;
246
+ height:18px;
247
+ color:black;
248
+ text-align:right;
249
+ padding-right:5px;
250
+ overflow:hidden;
251
+ left:-200px;
252
+ width:195px;
253
+ white-space:nowrap;
254
+ }
255
+
256
+
257
+ .taskDepLine {
258
+ border: 1px solid #9999ff;
259
+ overflow: hidden;
260
+ position: absolute;
261
+ }
262
+
263
+
264
+ .taskEditRow,.emptyRow {
265
+ height:18px;
266
+ }
267
+
268
+ .taskEditRow input{
269
+ border: 0 none;
270
+ font-size: 10px;
271
+ height: 14px;
272
+ margin: 0;
273
+ padding: 0;
274
+ width: 100%;
275
+ font-family: Arial, sans-serif
276
+ }
277
+
278
+ .taskEditRow.rowSelected td,.taskEditRow.rowSelected input{
279
+ background-color:#FFFF99;
280
+ }
281
+
282
+ .taskStatusBox{
283
+ position:absolute;
284
+ width:100px;
285
+ height:18px;
286
+ border:1px solid #a0a0a0;
287
+ background-color:#fff;
288
+ margin-top:2px;
289
+ margin-left:-1px;
290
+ padding: 2px
291
+ }
292
+ .taskStatus{
293
+ width:12px;
294
+ height:12px;
295
+ display:inline-block;
296
+ }
297
+ .taskStatus[status=STATUS_ACTIVE]{
298
+ background-color: #66FF99;
299
+ }
300
+ .taskStatus[status=STATUS_DONE]{
301
+ background-color: #0099FF;
302
+ }
303
+ .taskStatus[status=STATUS_FAILED]{
304
+ background-color: #660066;
305
+ }
306
+ .taskStatus[status=STATUS_SUSPENDED]{
307
+ background-color: #fbb11e;
308
+ }
309
+ .taskStatus[status=STATUS_UNDEFINED]{
310
+ background-color: #ffffff;
311
+ }
312
+ .taskStatus.selected{
313
+ border:#666 2px solid;
314
+ }
315
+
316
+
317
+ .ui-resizable-helper { border: 1px dotted #00F; }
318
+ .ui-resizable-e, .ui-resizable-w {width: 5px;}
319
+ .ui-draggable{
320
+ cursor:move;
321
+ }
322
+
323
+
@@ -0,0 +1,167 @@
1
+ $.fn.loadTemplates = function() {
2
+ $.JST.loadTemplates($(this));
3
+ return this;
4
+ };
5
+
6
+ $.JST = {
7
+ _templates: new Object(),
8
+ _decorators:new Object(),
9
+
10
+ loadTemplates: function(elems) {
11
+ elems.each(function() {
12
+ $(this).find(".__template__").each(function() {
13
+ var tmpl = $(this);
14
+ var type = tmpl.attr("type");
15
+
16
+ //template may be inside <!-- ... --> or not in case of ajax loaded templates
17
+ if (tmpl.get(0).firstChild.nodeType == 8) // 8==comment
18
+ var templateBody = tmpl.get(0).firstChild.nodeValue; // this is inside the comment
19
+ else
20
+ var templateBody = tmpl.html(); // this is the whole template
21
+
22
+ if (!templateBody.match(/##\w+##/)) { // is Resig' style? e.g. (#=id#) or (# ...some javascript code 'obj' is the alias for the object #)
23
+ var strFunc =
24
+ "var p=[],print=function(){p.push.apply(p,arguments);};" +
25
+ "with(obj){p.push('" +
26
+ templateBody.replace(/[\r\t\n]/g, " ")
27
+ .replace(/'(?=[^#]*#\))/g, "\t")
28
+ .split("'").join("\\'")
29
+ .split("\t").join("'")
30
+ .replace(/\(#=(.+?)#\)/g, "',$1,'")
31
+ .split("(#").join("');")
32
+ .split("#)").join("p.push('")
33
+ + "');}return p.join('');";
34
+
35
+ try {
36
+ $.JST._templates[type] = new Function("obj", strFunc);
37
+ } catch (e) {
38
+ console.error("JST error: "+type, e,strFunc);
39
+ }
40
+
41
+ } else { //plain template e.g. ##id##
42
+ try {
43
+ $.JST._templates[type] = templateBody;
44
+ } catch (e) {
45
+ console.error("JST error: "+type, e,templateBody);
46
+ }
47
+ }
48
+
49
+ tmpl.remove();
50
+
51
+ });
52
+ });
53
+ },
54
+
55
+ createFromTemplate: function(jsonData, template, transformToPrintable) {
56
+ var templates = $.JST._templates;
57
+
58
+ var jsData=new Object();
59
+ if (transformToPrintable){
60
+ for (var prop in jsonData){
61
+ var value = jsonData[prop];
62
+ if (typeof(value) == "string")
63
+ value = (value + "").replace(/\n/g, "<br>");
64
+ jsData[prop]=value;
65
+ }
66
+ } else {
67
+ jsData=jsonData;
68
+ }
69
+
70
+
71
+ function fillStripData(strip, data) {
72
+ for (var prop in data) {
73
+ var value = data[prop];
74
+
75
+ strip = strip.replace(new RegExp("##" + prop + "##", "gi"), value);
76
+ }
77
+ // then clean the remaining ##xxx##
78
+ strip = strip.replace(new RegExp("##\\w+##", "gi"), "");
79
+ return strip;
80
+ }
81
+
82
+ var stripString = "";
83
+ if (typeof(template) == "undefined") {
84
+ alert("Template is required");
85
+ stripString = "<div>Template is required</div>";
86
+
87
+ } else if (typeof(templates[template]) == "function") { // resig template
88
+ try {
89
+ stripString = templates[template](jsData);// create a jquery object in memory
90
+ } catch (e) {
91
+ console.error("JST error: "+template,e.message);
92
+ stripString = "<div> ERROR: "+template+"<br>" + e.message + "</div>";
93
+ }
94
+
95
+ } else {
96
+ stripString = templates[template]; // recover strip template
97
+ if (!stripString || stripString.trim() == "") {
98
+ console.error("No template found for type '" + template + "'");
99
+ return $("<div>");
100
+
101
+ } else {
102
+ stripString = fillStripData(stripString, jsData); //replace placeholders with data
103
+ }
104
+ }
105
+
106
+ var ret = $(stripString);// create a jquery object in memory
107
+ ret.attr("__template", template); // set __template attribute
108
+
109
+ //decorate the strip
110
+ var dec = $.JST._decorators[template];
111
+ if (typeof (dec) == "function")
112
+ dec(ret, jsData);
113
+
114
+ return ret;
115
+ },
116
+
117
+
118
+ existsTemplate: function(template) {
119
+ return $.JST._templates[template];
120
+ },
121
+
122
+ //decorate function is like function(domElement,jsonData){...}
123
+ loadDecorator:function(template, decorator) {
124
+ $.JST._decorators[template] = decorator;
125
+ },
126
+
127
+ getDecorator:function(template) {
128
+ return $.JST._decorators[template];
129
+ },
130
+
131
+ decorateTemplate:function(element) {
132
+ var dec = $.JST._decorators[element.attr("__template")];
133
+ if (typeof (dec) == "function")
134
+ dec(editor);
135
+ },
136
+
137
+ // asynchronous
138
+ ajaxLoadAsynchTemplates: function(templateUrl, callback) {
139
+
140
+ $.get(templateUrl, function(data) {
141
+
142
+ var div = $("<div>");
143
+ div.html(data);
144
+
145
+ $.JST.loadTemplates(div);
146
+
147
+ if (typeof(callback == "function"))
148
+ callback();
149
+ },"html");
150
+ },
151
+
152
+ ajaxLoadTemplates: function(templateUrl) {
153
+ $.ajax({
154
+ async:false,
155
+ url: templateUrl,
156
+ dataType: "html",
157
+ success: function(data) {
158
+ var div = $("<div>");
159
+ div.html(data);
160
+ $.JST.loadTemplates(div);
161
+ }
162
+ });
163
+
164
+ }
165
+
166
+
167
+ };