ganglia_js_charts 0.0.1

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.
@@ -0,0 +1,482 @@
1
+ /*!
2
+ * jQuery Templates Plugin 1.0.0pre
3
+ * http://github.com/jquery/jquery-tmpl
4
+ * Requires jQuery 1.4.2
5
+ *
6
+ * Copyright Software Freedom Conservancy, Inc.
7
+ * Dual licensed under the MIT or GPL Version 2 licenses.
8
+ * http://jquery.org/license
9
+ */
10
+ (function( jQuery, undefined ){
11
+ var oldManip = jQuery.fn.domManip, tmplItmAtt = "_tmplitem", htmlExpr = /^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,
12
+ newTmplItems = {}, wrappedItems = {}, appendToTmplItems, topTmplItem = { key: 0, data: {} }, itemKey = 0, cloneIndex = 0, stack = [];
13
+
14
+ function newTmplItem( options, parentItem, fn, data ) {
15
+ // Returns a template item data structure for a new rendered instance of a template (a 'template item').
16
+ // The content field is a hierarchical array of strings and nested items (to be
17
+ // removed and replaced by nodes field of dom elements, once inserted in DOM).
18
+ var newItem = {
19
+ data: data || (parentItem ? parentItem.data : {}),
20
+ _wrap: parentItem ? parentItem._wrap : null,
21
+ tmpl: null,
22
+ parent: parentItem || null,
23
+ nodes: [],
24
+ calls: tiCalls,
25
+ nest: tiNest,
26
+ wrap: tiWrap,
27
+ html: tiHtml,
28
+ update: tiUpdate
29
+ };
30
+ if ( options ) {
31
+ jQuery.extend( newItem, options, { nodes: [], parent: parentItem });
32
+ }
33
+ if ( fn ) {
34
+ // Build the hierarchical content to be used during insertion into DOM
35
+ newItem.tmpl = fn;
36
+ newItem._ctnt = newItem._ctnt || newItem.tmpl( jQuery, newItem );
37
+ newItem.key = ++itemKey;
38
+ // Keep track of new template item, until it is stored as jQuery Data on DOM element
39
+ (stack.length ? wrappedItems : newTmplItems)[itemKey] = newItem;
40
+ }
41
+ return newItem;
42
+ }
43
+
44
+ // Override appendTo etc., in order to provide support for targeting multiple elements. (This code would disappear if integrated in jquery core).
45
+ jQuery.each({
46
+ appendTo: "append",
47
+ prependTo: "prepend",
48
+ insertBefore: "before",
49
+ insertAfter: "after",
50
+ replaceAll: "replaceWith"
51
+ }, function( name, original ) {
52
+ jQuery.fn[ name ] = function( selector ) {
53
+ var ret = [], insert = jQuery( selector ), elems, i, l, tmplItems,
54
+ parent = this.length === 1 && this[0].parentNode;
55
+
56
+ appendToTmplItems = newTmplItems || {};
57
+ if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
58
+ insert[ original ]( this[0] );
59
+ ret = this;
60
+ } else {
61
+ for ( i = 0, l = insert.length; i < l; i++ ) {
62
+ cloneIndex = i;
63
+ elems = (i > 0 ? this.clone(true) : this).get();
64
+ jQuery( insert[i] )[ original ]( elems );
65
+ ret = ret.concat( elems );
66
+ }
67
+ cloneIndex = 0;
68
+ ret = this.pushStack( ret, name, insert.selector );
69
+ }
70
+ tmplItems = appendToTmplItems;
71
+ appendToTmplItems = null;
72
+ jQuery.tmpl.complete( tmplItems );
73
+ return ret;
74
+ };
75
+ });
76
+
77
+ jQuery.fn.extend({
78
+ // Use first wrapped element as template markup.
79
+ // Return wrapped set of template items, obtained by rendering template against data.
80
+ tmpl: function( data, options, parentItem ) {
81
+ return jQuery.tmpl( this[0], data, options, parentItem );
82
+ },
83
+
84
+ // Find which rendered template item the first wrapped DOM element belongs to
85
+ tmplItem: function() {
86
+ return jQuery.tmplItem( this[0] );
87
+ },
88
+
89
+ // Consider the first wrapped element as a template declaration, and get the compiled template or store it as a named template.
90
+ template: function( name ) {
91
+ return jQuery.template( name, this[0] );
92
+ },
93
+
94
+ domManip: function( args, table, callback, options ) {
95
+ if ( args[0] && jQuery.isArray( args[0] )) {
96
+ var dmArgs = jQuery.makeArray( arguments ), elems = args[0], elemsLength = elems.length, i = 0, tmplItem;
97
+ while ( i < elemsLength && !(tmplItem = jQuery.data( elems[i++], "tmplItem" ))) {}
98
+ if ( tmplItem && cloneIndex ) {
99
+ dmArgs[2] = function( fragClone ) {
100
+ // Handler called by oldManip when rendered template has been inserted into DOM.
101
+ jQuery.tmpl.afterManip( this, fragClone, callback );
102
+ };
103
+ }
104
+ oldManip.apply( this, dmArgs );
105
+ } else {
106
+ oldManip.apply( this, arguments );
107
+ }
108
+ cloneIndex = 0;
109
+ if ( !appendToTmplItems ) {
110
+ jQuery.tmpl.complete( newTmplItems );
111
+ }
112
+ return this;
113
+ }
114
+ });
115
+
116
+ jQuery.extend({
117
+ // Return wrapped set of template items, obtained by rendering template against data.
118
+ tmpl: function( tmpl, data, options, parentItem ) {
119
+ var ret, topLevel = !parentItem;
120
+ if ( topLevel ) {
121
+ // This is a top-level tmpl call (not from a nested template using {{tmpl}})
122
+ parentItem = topTmplItem;
123
+ tmpl = jQuery.template[tmpl] || jQuery.template( null, tmpl );
124
+ wrappedItems = {}; // Any wrapped items will be rebuilt, since this is top level
125
+ } else if ( !tmpl ) {
126
+ // The template item is already associated with DOM - this is a refresh.
127
+ // Re-evaluate rendered template for the parentItem
128
+ tmpl = parentItem.tmpl;
129
+ newTmplItems[parentItem.key] = parentItem;
130
+ parentItem.nodes = [];
131
+ if ( parentItem.wrapped ) {
132
+ updateWrapped( parentItem, parentItem.wrapped );
133
+ }
134
+ // Rebuild, without creating a new template item
135
+ return jQuery( build( parentItem, null, parentItem.tmpl( jQuery, parentItem ) ));
136
+ }
137
+ if ( !tmpl ) {
138
+ return []; // Could throw...
139
+ }
140
+ if ( typeof data === "function" ) {
141
+ data = data.call( parentItem || {} );
142
+ }
143
+ if ( options && options.wrapped ) {
144
+ updateWrapped( options, options.wrapped );
145
+ }
146
+ ret = jQuery.isArray( data ) ?
147
+ jQuery.map( data, function( dataItem ) {
148
+ return dataItem ? newTmplItem( options, parentItem, tmpl, dataItem ) : null;
149
+ }) :
150
+ [ newTmplItem( options, parentItem, tmpl, data ) ];
151
+ return topLevel ? jQuery( build( parentItem, null, ret ) ) : ret;
152
+ },
153
+
154
+ // Return rendered template item for an element.
155
+ tmplItem: function( elem ) {
156
+ var tmplItem;
157
+ if ( elem instanceof jQuery ) {
158
+ elem = elem[0];
159
+ }
160
+ while ( elem && elem.nodeType === 1 && !(tmplItem = jQuery.data( elem, "tmplItem" )) && (elem = elem.parentNode) ) {}
161
+ return tmplItem || topTmplItem;
162
+ },
163
+
164
+ // Set:
165
+ // Use $.template( name, tmpl ) to cache a named template,
166
+ // where tmpl is a template string, a script element or a jQuery instance wrapping a script element, etc.
167
+ // Use $( "selector" ).template( name ) to provide access by name to a script block template declaration.
168
+
169
+ // Get:
170
+ // Use $.template( name ) to access a cached template.
171
+ // Also $( selectorToScriptBlock ).template(), or $.template( null, templateString )
172
+ // will return the compiled template, without adding a name reference.
173
+ // If templateString includes at least one HTML tag, $.template( templateString ) is equivalent
174
+ // to $.template( null, templateString )
175
+ template: function( name, tmpl ) {
176
+ if (tmpl) {
177
+ // Compile template and associate with name
178
+ if ( typeof tmpl === "string" ) {
179
+ // This is an HTML string being passed directly in.
180
+ tmpl = buildTmplFn( tmpl )
181
+ } else if ( tmpl instanceof jQuery ) {
182
+ tmpl = tmpl[0] || {};
183
+ }
184
+ if ( tmpl.nodeType ) {
185
+ // If this is a template block, use cached copy, or generate tmpl function and cache.
186
+ tmpl = jQuery.data( tmpl, "tmpl" ) || jQuery.data( tmpl, "tmpl", buildTmplFn( tmpl.innerHTML ));
187
+ // Issue: In IE, if the container element is not a script block, the innerHTML will remove quotes from attribute values whenever the value does not include white space.
188
+ // This means that foo="${x}" will not work if the value of x includes white space: foo="${x}" -> foo=value of x.
189
+ // To correct this, include space in tag: foo="${ x }" -> foo="value of x"
190
+ }
191
+ return typeof name === "string" ? (jQuery.template[name] = tmpl) : tmpl;
192
+ }
193
+ // Return named compiled template
194
+ return name ? (typeof name !== "string" ? jQuery.template( null, name ):
195
+ (jQuery.template[name] ||
196
+ // If not in map, treat as a selector. (If integrated with core, use quickExpr.exec)
197
+ jQuery.template( null, htmlExpr.test( name ) ? name : jQuery( name )))) : null;
198
+ },
199
+
200
+ encode: function( text ) {
201
+ // Do HTML encoding replacing < > & and ' and " by corresponding entities.
202
+ return ("" + text).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;");
203
+ }
204
+ });
205
+
206
+ jQuery.extend( jQuery.tmpl, {
207
+ tag: {
208
+ "tmpl": {
209
+ _default: { $2: "null" },
210
+ open: "if($notnull_1){_=_.concat($item.nest($1,$2));}"
211
+ // tmpl target parameter can be of type function, so use $1, not $1a (so not auto detection of functions)
212
+ // This means that {{tmpl foo}} treats foo as a template (which IS a function).
213
+ // Explicit parens can be used if foo is a function that returns a template: {{tmpl foo()}}.
214
+ },
215
+ "wrap": {
216
+ _default: { $2: "null" },
217
+ open: "$item.calls(_,$1,$2);_=[];",
218
+ close: "call=$item.calls();_=call._.concat($item.wrap(call,_));"
219
+ },
220
+ "each": {
221
+ _default: { $2: "$index, $value" },
222
+ open: "if($notnull_1){$.each($1a,function($2){with(this){",
223
+ close: "}});}"
224
+ },
225
+ "if": {
226
+ open: "if(($notnull_1) && $1a){",
227
+ close: "}"
228
+ },
229
+ "else": {
230
+ _default: { $1: "true" },
231
+ open: "}else if(($notnull_1) && $1a){"
232
+ },
233
+ "html": {
234
+ // Unecoded expression evaluation.
235
+ open: "if($notnull_1){_.push($1a);}"
236
+ },
237
+ "=": {
238
+ // Encoded expression evaluation. Abbreviated form is ${}.
239
+ _default: { $1: "$data" },
240
+ open: "if($notnull_1){_.push($.encode($1a));}"
241
+ },
242
+ "!": {
243
+ // Comment tag. Skipped by parser
244
+ open: ""
245
+ }
246
+ },
247
+
248
+ // This stub can be overridden, e.g. in jquery.tmplPlus for providing rendered events
249
+ complete: function( items ) {
250
+ newTmplItems = {};
251
+ },
252
+
253
+ // Call this from code which overrides domManip, or equivalent
254
+ // Manage cloning/storing template items etc.
255
+ afterManip: function afterManip( elem, fragClone, callback ) {
256
+ // Provides cloned fragment ready for fixup prior to and after insertion into DOM
257
+ var content = fragClone.nodeType === 11 ?
258
+ jQuery.makeArray(fragClone.childNodes) :
259
+ fragClone.nodeType === 1 ? [fragClone] : [];
260
+
261
+ // Return fragment to original caller (e.g. append) for DOM insertion
262
+ callback.call( elem, fragClone );
263
+
264
+ // Fragment has been inserted:- Add inserted nodes to tmplItem data structure. Replace inserted element annotations by jQuery.data.
265
+ storeTmplItems( content );
266
+ cloneIndex++;
267
+ }
268
+ });
269
+
270
+ //========================== Private helper functions, used by code above ==========================
271
+
272
+ function build( tmplItem, nested, content ) {
273
+ // Convert hierarchical content into flat string array
274
+ // and finally return array of fragments ready for DOM insertion
275
+ var frag, ret = content ? jQuery.map( content, function( item ) {
276
+ return (typeof item === "string") ?
277
+ // Insert template item annotations, to be converted to jQuery.data( "tmplItem" ) when elems are inserted into DOM.
278
+ (tmplItem.key ? item.replace( /(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g, "$1 " + tmplItmAtt + "=\"" + tmplItem.key + "\" $2" ) : item) :
279
+ // This is a child template item. Build nested template.
280
+ build( item, tmplItem, item._ctnt );
281
+ }) :
282
+ // If content is not defined, insert tmplItem directly. Not a template item. May be a string, or a string array, e.g. from {{html $item.html()}}.
283
+ tmplItem;
284
+ if ( nested ) {
285
+ return ret;
286
+ }
287
+
288
+ // top-level template
289
+ ret = ret.join("");
290
+
291
+ // Support templates which have initial or final text nodes, or consist only of text
292
+ // Also support HTML entities within the HTML markup.
293
+ ret.replace( /^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/, function( all, before, middle, after) {
294
+ frag = jQuery( middle ).get();
295
+
296
+ storeTmplItems( frag );
297
+ if ( before ) {
298
+ frag = unencode( before ).concat(frag);
299
+ }
300
+ if ( after ) {
301
+ frag = frag.concat(unencode( after ));
302
+ }
303
+ });
304
+ return frag ? frag : unencode( ret );
305
+ }
306
+
307
+ function unencode( text ) {
308
+ // Use createElement, since createTextNode will not render HTML entities correctly
309
+ var el = document.createElement( "div" );
310
+ el.innerHTML = text;
311
+ return jQuery.makeArray(el.childNodes);
312
+ }
313
+
314
+ // Generate a reusable function that will serve to render a template against data
315
+ function buildTmplFn( markup ) {
316
+ return new Function("jQuery","$item",
317
+ "var $=jQuery,call,_=[],$data=$item.data;" +
318
+
319
+ // Introduce the data as local variables using with(){}
320
+ "with($data){_.push('" +
321
+
322
+ // Convert the template into pure JavaScript
323
+ jQuery.trim(markup)
324
+ .replace( /([\\'])/g, "\\$1" )
325
+ .replace( /[\r\t\n]/g, " " )
326
+ .replace( /\$\{([^\}]*)\}/g, "{{= $1}}" )
327
+ .replace( /\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,
328
+ function( all, slash, type, fnargs, target, parens, args ) {
329
+ var tag = jQuery.tmpl.tag[ type ], def, expr, exprAutoFnDetect;
330
+ if ( !tag ) {
331
+ throw "Template command not found: " + type;
332
+ }
333
+ def = tag._default || [];
334
+ if ( parens && !/\w$/.test(target)) {
335
+ target += parens;
336
+ parens = "";
337
+ }
338
+ if ( target ) {
339
+ target = unescape( target );
340
+ args = args ? ("," + unescape( args ) + ")") : (parens ? ")" : "");
341
+ // Support for target being things like a.toLowerCase();
342
+ // In that case don't call with template item as 'this' pointer. Just evaluate...
343
+ expr = parens ? (target.indexOf(".") > -1 ? target + unescape( parens ) : ("(" + target + ").call($item" + args)) : target;
344
+ exprAutoFnDetect = parens ? expr : "(typeof(" + target + ")==='function'?(" + target + ").call($item):(" + target + "))";
345
+ } else {
346
+ exprAutoFnDetect = expr = def.$1 || "null";
347
+ }
348
+ fnargs = unescape( fnargs );
349
+ return "');" +
350
+ tag[ slash ? "close" : "open" ]
351
+ .split( "$notnull_1" ).join( target ? "typeof(" + target + ")!=='undefined' && (" + target + ")!=null" : "true" )
352
+ .split( "$1a" ).join( exprAutoFnDetect )
353
+ .split( "$1" ).join( expr )
354
+ .split( "$2" ).join( fnargs || def.$2 || "" ) +
355
+ "_.push('";
356
+ }) +
357
+ "');}return _;"
358
+ );
359
+ }
360
+ function updateWrapped( options, wrapped ) {
361
+ // Build the wrapped content.
362
+ options._wrap = build( options, true,
363
+ // Suport imperative scenario in which options.wrapped can be set to a selector or an HTML string.
364
+ jQuery.isArray( wrapped ) ? wrapped : [htmlExpr.test( wrapped ) ? wrapped : jQuery( wrapped ).html()]
365
+ ).join("");
366
+ }
367
+
368
+ function unescape( args ) {
369
+ return args ? args.replace( /\\'/g, "'").replace(/\\\\/g, "\\" ) : null;
370
+ }
371
+ function outerHtml( elem ) {
372
+ var div = document.createElement("div");
373
+ div.appendChild( elem.cloneNode(true) );
374
+ return div.innerHTML;
375
+ }
376
+
377
+ // Store template items in jQuery.data(), ensuring a unique tmplItem data data structure for each rendered template instance.
378
+ function storeTmplItems( content ) {
379
+ var keySuffix = "_" + cloneIndex, elem, elems, newClonedItems = {}, i, l, m;
380
+ for ( i = 0, l = content.length; i < l; i++ ) {
381
+ if ( (elem = content[i]).nodeType !== 1 ) {
382
+ continue;
383
+ }
384
+ elems = elem.getElementsByTagName("*");
385
+ for ( m = elems.length - 1; m >= 0; m-- ) {
386
+ processItemKey( elems[m] );
387
+ }
388
+ processItemKey( elem );
389
+ }
390
+ function processItemKey( el ) {
391
+ var pntKey, pntNode = el, pntItem, tmplItem, key;
392
+ // Ensure that each rendered template inserted into the DOM has its own template item,
393
+ if ( (key = el.getAttribute( tmplItmAtt ))) {
394
+ while ( pntNode.parentNode && (pntNode = pntNode.parentNode).nodeType === 1 && !(pntKey = pntNode.getAttribute( tmplItmAtt ))) { }
395
+ if ( pntKey !== key ) {
396
+ // The next ancestor with a _tmplitem expando is on a different key than this one.
397
+ // So this is a top-level element within this template item
398
+ // Set pntNode to the key of the parentNode, or to 0 if pntNode.parentNode is null, or pntNode is a fragment.
399
+ pntNode = pntNode.parentNode ? (pntNode.nodeType === 11 ? 0 : (pntNode.getAttribute( tmplItmAtt ) || 0)) : 0;
400
+ if ( !(tmplItem = newTmplItems[key]) ) {
401
+ // The item is for wrapped content, and was copied from the temporary parent wrappedItem.
402
+ tmplItem = wrappedItems[key];
403
+ tmplItem = newTmplItem( tmplItem, newTmplItems[pntNode]||wrappedItems[pntNode] );
404
+ tmplItem.key = ++itemKey;
405
+ newTmplItems[itemKey] = tmplItem;
406
+ }
407
+ if ( cloneIndex ) {
408
+ cloneTmplItem( key );
409
+ }
410
+ }
411
+ el.removeAttribute( tmplItmAtt );
412
+ } else if ( cloneIndex && (tmplItem = jQuery.data( el, "tmplItem" )) ) {
413
+ // This was a rendered element, cloned during append or appendTo etc.
414
+ // TmplItem stored in jQuery data has already been cloned in cloneCopyEvent. We must replace it with a fresh cloned tmplItem.
415
+ cloneTmplItem( tmplItem.key );
416
+ newTmplItems[tmplItem.key] = tmplItem;
417
+ pntNode = jQuery.data( el.parentNode, "tmplItem" );
418
+ pntNode = pntNode ? pntNode.key : 0;
419
+ }
420
+ if ( tmplItem ) {
421
+ pntItem = tmplItem;
422
+ // Find the template item of the parent element.
423
+ // (Using !=, not !==, since pntItem.key is number, and pntNode may be a string)
424
+ while ( pntItem && pntItem.key != pntNode ) {
425
+ // Add this element as a top-level node for this rendered template item, as well as for any
426
+ // ancestor items between this item and the item of its parent element
427
+ pntItem.nodes.push( el );
428
+ pntItem = pntItem.parent;
429
+ }
430
+ // Delete content built during rendering - reduce API surface area and memory use, and avoid exposing of stale data after rendering...
431
+ delete tmplItem._ctnt;
432
+ delete tmplItem._wrap;
433
+ // Store template item as jQuery data on the element
434
+ jQuery.data( el, "tmplItem", tmplItem );
435
+ }
436
+ function cloneTmplItem( key ) {
437
+ key = key + keySuffix;
438
+ tmplItem = newClonedItems[key] =
439
+ (newClonedItems[key] || newTmplItem( tmplItem, newTmplItems[tmplItem.parent.key + keySuffix] || tmplItem.parent ));
440
+ }
441
+ }
442
+ }
443
+
444
+ //---- Helper functions for template item ----
445
+
446
+ function tiCalls( content, tmpl, data, options ) {
447
+ if ( !content ) {
448
+ return stack.pop();
449
+ }
450
+ stack.push({ _: content, tmpl: tmpl, item:this, data: data, options: options });
451
+ }
452
+
453
+ function tiNest( tmpl, data, options ) {
454
+ // nested template, using {{tmpl}} tag
455
+ return jQuery.tmpl( jQuery.template( tmpl ), data, options, this );
456
+ }
457
+
458
+ function tiWrap( call, wrapped ) {
459
+ // nested template, using {{wrap}} tag
460
+ var options = call.options || {};
461
+ options.wrapped = wrapped;
462
+ // Apply the template, which may incorporate wrapped content,
463
+ return jQuery.tmpl( jQuery.template( call.tmpl ), call.data, options, call.item );
464
+ }
465
+
466
+ function tiHtml( filter, textOnly ) {
467
+ var wrapped = this._wrap;
468
+ return jQuery.map(
469
+ jQuery( jQuery.isArray( wrapped ) ? wrapped.join("") : wrapped ).filter( filter || "*" ),
470
+ function(e) {
471
+ return textOnly ?
472
+ e.innerText || e.textContent :
473
+ e.outerHTML || outerHtml(e);
474
+ });
475
+ }
476
+
477
+ function tiUpdate() {
478
+ var coll = this.nodes;
479
+ jQuery.tmpl( null, null, null, this).insertBefore( coll[0] );
480
+ jQuery( coll ).remove();
481
+ }
482
+ })( jQuery );