Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

698 lines
27 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. /**
  16. * @class Ext
  17. */
  18. Ext.ns("Ext.grid", "Ext.list", "Ext.dd", "Ext.tree", "Ext.form", "Ext.menu",
  19. "Ext.state", "Ext.layout", "Ext.app", "Ext.ux", "Ext.chart", "Ext.direct");
  20. <div id="prop-Ext-ux"></div>/**
  21. * Namespace alloted for extensions to the framework.
  22. * @property ux
  23. * @type Object
  24. */
  25. Ext.apply(Ext, function(){
  26. var E = Ext,
  27. idSeed = 0,
  28. scrollWidth = null;
  29. return {
  30. <div id="prop-Ext-emptyFn"></div>/**
  31. * A reusable empty function
  32. * @property
  33. * @type Function
  34. */
  35. emptyFn : function(){},
  36. <div id="prop-Ext-BLANK_IMAGE_URL"></div>/**
  37. * URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images.
  38. * In older versions of IE, this defaults to "http://extjs.com/s.gif" and you should change this to a URL on your server.
  39. * For other browsers it uses an inline data URL.
  40. * @type String
  41. */
  42. BLANK_IMAGE_URL : Ext.isIE6 || Ext.isIE7 || Ext.isAir ?
  43. 'http:/' + '/www.extjs.com/s.gif' :
  44. 'data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
  45. extendX : function(supr, fn){
  46. return Ext.extend(supr, fn(supr.prototype));
  47. },
  48. <div id="method-Ext-getDoc"></div>/**
  49. * Returns the current HTML document object as an {@link Ext.Element}.
  50. * @return Ext.Element The document
  51. */
  52. getDoc : function(){
  53. return Ext.get(document);
  54. },
  55. <div id="method-Ext-num"></div>/**
  56. * Utility method for validating that a value is numeric, returning the specified default value if it is not.
  57. * @param {Mixed} value Should be a number, but any type will be handled appropriately
  58. * @param {Number} defaultValue The value to return if the original value is non-numeric
  59. * @return {Number} Value, if numeric, else defaultValue
  60. */
  61. num : function(v, defaultValue){
  62. v = Number(Ext.isEmpty(v) || Ext.isArray(v) || typeof v == 'boolean' || (typeof v == 'string' && v.trim().length == 0) ? NaN : v);
  63. return isNaN(v) ? defaultValue : v;
  64. },
  65. <div id="method-Ext-value"></div>/**
  66. * <p>Utility method for returning a default value if the passed value is empty.</p>
  67. * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
  68. * <li>null</li>
  69. * <li>undefined</li>
  70. * <li>an empty array</li>
  71. * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
  72. * </ul></div>
  73. * @param {Mixed} value The value to test
  74. * @param {Mixed} defaultValue The value to return if the original value is empty
  75. * @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
  76. * @return {Mixed} value, if non-empty, else defaultValue
  77. */
  78. value : function(v, defaultValue, allowBlank){
  79. return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
  80. },
  81. <div id="method-Ext-escapeRe"></div>/**
  82. * Escapes the passed string for use in a regular expression
  83. * @param {String} str
  84. * @return {String}
  85. */
  86. escapeRe : function(s) {
  87. return s.replace(/([-.*+?^${}()|[\]\/\\])/g, "\\$1");
  88. },
  89. sequence : function(o, name, fn, scope){
  90. o[name] = o[name].createSequence(fn, scope);
  91. },
  92. <div id="method-Ext-addBehaviors"></div>/**
  93. * Applies event listeners to elements by selectors when the document is ready.
  94. * The event name is specified with an <tt>&#64;</tt> suffix.
  95. * <pre><code>
  96. Ext.addBehaviors({
  97. // add a listener for click on all anchors in element with id foo
  98. '#foo a&#64;click' : function(e, t){
  99. // do something
  100. },
  101. // add the same listener to multiple selectors (separated by comma BEFORE the &#64;)
  102. '#foo a, #bar span.some-class&#64;mouseover' : function(){
  103. // do something
  104. }
  105. });
  106. * </code></pre>
  107. * @param {Object} obj The list of behaviors to apply
  108. */
  109. addBehaviors : function(o){
  110. if(!Ext.isReady){
  111. Ext.onReady(function(){
  112. Ext.addBehaviors(o);
  113. });
  114. } else {
  115. var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
  116. parts,
  117. b,
  118. s;
  119. for (b in o) {
  120. if ((parts = b.split('@'))[1]) { // for Object prototype breakers
  121. s = parts[0];
  122. if(!cache[s]){
  123. cache[s] = Ext.select(s);
  124. }
  125. cache[s].on(parts[1], o[b]);
  126. }
  127. }
  128. cache = null;
  129. }
  130. },
  131. <div id="method-Ext-getScrollBarWidth"></div>/**
  132. * Utility method for getting the width of the browser scrollbar. This can differ depending on
  133. * operating system settings, such as the theme or font size.
  134. * @param {Boolean} force (optional) true to force a recalculation of the value.
  135. * @return {Number} The width of the scrollbar.
  136. */
  137. getScrollBarWidth: function(force){
  138. if(!Ext.isReady){
  139. return 0;
  140. }
  141. if(force === true || scrollWidth === null){
  142. // Append our div, do our calculation and then remove it
  143. var div = Ext.getBody().createChild('<div class="x-hide-offsets" style="width:100px;height:50px;overflow:hidden;"><div style="height:200px;"></div></div>'),
  144. child = div.child('div', true);
  145. var w1 = child.offsetWidth;
  146. div.setStyle('overflow', (Ext.isWebKit || Ext.isGecko) ? 'auto' : 'scroll');
  147. var w2 = child.offsetWidth;
  148. div.remove();
  149. // Need to add 2 to ensure we leave enough space
  150. scrollWidth = w1 - w2 + 2;
  151. }
  152. return scrollWidth;
  153. },
  154. // deprecated
  155. combine : function(){
  156. var as = arguments, l = as.length, r = [];
  157. for(var i = 0; i < l; i++){
  158. var a = as[i];
  159. if(Ext.isArray(a)){
  160. r = r.concat(a);
  161. }else if(a.length !== undefined && !a.substr){
  162. r = r.concat(Array.prototype.slice.call(a, 0));
  163. }else{
  164. r.push(a);
  165. }
  166. }
  167. return r;
  168. },
  169. <div id="method-Ext-copyTo"></div>/**
  170. * Copies a set of named properties fom the source object to the destination object.
  171. * <p>example:<pre><code>
  172. ImageComponent = Ext.extend(Ext.BoxComponent, {
  173. initComponent: function() {
  174. this.autoEl = { tag: 'img' };
  175. MyComponent.superclass.initComponent.apply(this, arguments);
  176. this.initialBox = Ext.copyTo({}, this.initialConfig, 'x,y,width,height');
  177. }
  178. });
  179. * </code></pre>
  180. * @param {Object} dest The destination object.
  181. * @param {Object} source The source object.
  182. * @param {Array/String} names Either an Array of property names, or a comma-delimited list
  183. * of property names to copy.
  184. * @return {Object} The modified object.
  185. */
  186. copyTo : function(dest, source, names){
  187. if(typeof names == 'string'){
  188. names = names.split(/[,;\s]/);
  189. }
  190. Ext.each(names, function(name){
  191. if(source.hasOwnProperty(name)){
  192. dest[name] = source[name];
  193. }
  194. }, this);
  195. return dest;
  196. },
  197. <div id="method-Ext-destroy"></div>/**
  198. * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
  199. * DOM (if applicable) and calling their destroy functions (if available). This method is primarily
  200. * intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
  201. * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
  202. * passed into this function in a single call as separate arguments.
  203. * @param {Mixed} arg1 An {@link Ext.Element}, {@link Ext.Component}, or an Array of either of these to destroy
  204. * @param {Mixed} arg2 (optional)
  205. * @param {Mixed} etc... (optional)
  206. */
  207. destroy : function(){
  208. Ext.each(arguments, function(arg){
  209. if(arg){
  210. if(Ext.isArray(arg)){
  211. this.destroy.apply(this, arg);
  212. }else if(typeof arg.destroy == 'function'){
  213. arg.destroy();
  214. }else if(arg.dom){
  215. arg.remove();
  216. }
  217. }
  218. }, this);
  219. },
  220. <div id="method-Ext-destroyMembers"></div>/**
  221. * Attempts to destroy and then remove a set of named properties of the passed object.
  222. * @param {Object} o The object (most likely a Component) who's properties you wish to destroy.
  223. * @param {Mixed} arg1 The name of the property to destroy and remove from the object.
  224. * @param {Mixed} etc... More property names to destroy and remove.
  225. */
  226. destroyMembers : function(o, arg1, arg2, etc){
  227. for(var i = 1, a = arguments, len = a.length; i < len; i++) {
  228. Ext.destroy(o[a[i]]);
  229. delete o[a[i]];
  230. }
  231. },
  232. <div id="method-Ext-clean"></div>/**
  233. * Creates a copy of the passed Array with falsy values removed.
  234. * @param {Array/NodeList} arr The Array from which to remove falsy values.
  235. * @return {Array} The new, compressed Array.
  236. */
  237. clean : function(arr){
  238. var ret = [];
  239. Ext.each(arr, function(v){
  240. if(!!v){
  241. ret.push(v);
  242. }
  243. });
  244. return ret;
  245. },
  246. <div id="method-Ext-unique"></div>/**
  247. * Creates a copy of the passed Array, filtered to contain only unique values.
  248. * @param {Array} arr The Array to filter
  249. * @return {Array} The new Array containing unique values.
  250. */
  251. unique : function(arr){
  252. var ret = [],
  253. collect = {};
  254. Ext.each(arr, function(v) {
  255. if(!collect[v]){
  256. ret.push(v);
  257. }
  258. collect[v] = true;
  259. });
  260. return ret;
  261. },
  262. <div id="method-Ext-flatten"></div>/**
  263. * Recursively flattens into 1-d Array. Injects Arrays inline.
  264. * @param {Array} arr The array to flatten
  265. * @return {Array} The new, flattened array.
  266. */
  267. flatten : function(arr){
  268. var worker = [];
  269. function rFlatten(a) {
  270. Ext.each(a, function(v) {
  271. if(Ext.isArray(v)){
  272. rFlatten(v);
  273. }else{
  274. worker.push(v);
  275. }
  276. });
  277. return worker;
  278. }
  279. return rFlatten(arr);
  280. },
  281. <div id="method-Ext-min"></div>/**
  282. * Returns the minimum value in the Array.
  283. * @param {Array|NodeList} arr The Array from which to select the minimum value.
  284. * @param {Function} comp (optional) a function to perform the comparision which determines minimization.
  285. * If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1
  286. * @return {Object} The minimum value in the Array.
  287. */
  288. min : function(arr, comp){
  289. var ret = arr[0];
  290. comp = comp || function(a,b){ return a < b ? -1 : 1; };
  291. Ext.each(arr, function(v) {
  292. ret = comp(ret, v) == -1 ? ret : v;
  293. });
  294. return ret;
  295. },
  296. <div id="method-Ext-max"></div>/**
  297. * Returns the maximum value in the Array
  298. * @param {Array|NodeList} arr The Array from which to select the maximum value.
  299. * @param {Function} comp (optional) a function to perform the comparision which determines maximization.
  300. * If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
  301. * @return {Object} The maximum value in the Array.
  302. */
  303. max : function(arr, comp){
  304. var ret = arr[0];
  305. comp = comp || function(a,b){ return a > b ? 1 : -1; };
  306. Ext.each(arr, function(v) {
  307. ret = comp(ret, v) == 1 ? ret : v;
  308. });
  309. return ret;
  310. },
  311. <div id="method-Ext-mean"></div>/**
  312. * Calculates the mean of the Array
  313. * @param {Array} arr The Array to calculate the mean value of.
  314. * @return {Number} The mean.
  315. */
  316. mean : function(arr){
  317. return arr.length > 0 ? Ext.sum(arr) / arr.length : undefined;
  318. },
  319. <div id="method-Ext-sum"></div>/**
  320. * Calculates the sum of the Array
  321. * @param {Array} arr The Array to calculate the sum value of.
  322. * @return {Number} The sum.
  323. */
  324. sum : function(arr){
  325. var ret = 0;
  326. Ext.each(arr, function(v) {
  327. ret += v;
  328. });
  329. return ret;
  330. },
  331. <div id="method-Ext-partition"></div>/**
  332. * Partitions the set into two sets: a true set and a false set.
  333. * Example:
  334. * Example2:
  335. * <pre><code>
  336. // Example 1:
  337. Ext.partition([true, false, true, true, false]); // [[true, true, true], [false, false]]
  338. // Example 2:
  339. Ext.partition(
  340. Ext.query("p"),
  341. function(val){
  342. return val.className == "class1"
  343. }
  344. );
  345. // true are those paragraph elements with a className of "class1",
  346. // false set are those that do not have that className.
  347. * </code></pre>
  348. * @param {Array|NodeList} arr The array to partition
  349. * @param {Function} truth (optional) a function to determine truth. If this is omitted the element
  350. * itself must be able to be evaluated for its truthfulness.
  351. * @return {Array} [true<Array>,false<Array>]
  352. */
  353. partition : function(arr, truth){
  354. var ret = [[],[]];
  355. Ext.each(arr, function(v, i, a) {
  356. ret[ (truth && truth(v, i, a)) || (!truth && v) ? 0 : 1].push(v);
  357. });
  358. return ret;
  359. },
  360. <div id="method-Ext-invoke"></div>/**
  361. * Invokes a method on each item in an Array.
  362. * <pre><code>
  363. // Example:
  364. Ext.invoke(Ext.query("p"), "getAttribute", "id");
  365. // [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")]
  366. * </code></pre>
  367. * @param {Array|NodeList} arr The Array of items to invoke the method on.
  368. * @param {String} methodName The method name to invoke.
  369. * @param {...*} args Arguments to send into the method invocation.
  370. * @return {Array} The results of invoking the method on each item in the array.
  371. */
  372. invoke : function(arr, methodName){
  373. var ret = [],
  374. args = Array.prototype.slice.call(arguments, 2);
  375. Ext.each(arr, function(v,i) {
  376. if (v && typeof v[methodName] == 'function') {
  377. ret.push(v[methodName].apply(v, args));
  378. } else {
  379. ret.push(undefined);
  380. }
  381. });
  382. return ret;
  383. },
  384. <div id="method-Ext-pluck"></div>/**
  385. * Plucks the value of a property from each item in the Array
  386. * <pre><code>
  387. // Example:
  388. Ext.pluck(Ext.query("p"), "className"); // [el1.className, el2.className, ..., elN.className]
  389. * </code></pre>
  390. * @param {Array|NodeList} arr The Array of items to pluck the value from.
  391. * @param {String} prop The property name to pluck from each element.
  392. * @return {Array} The value from each item in the Array.
  393. */
  394. pluck : function(arr, prop){
  395. var ret = [];
  396. Ext.each(arr, function(v) {
  397. ret.push( v[prop] );
  398. });
  399. return ret;
  400. },
  401. <div id="method-Ext-zip"></div>/**
  402. * <p>Zips N sets together.</p>
  403. * <pre><code>
  404. // Example 1:
  405. Ext.zip([1,2,3],[4,5,6]); // [[1,4],[2,5],[3,6]]
  406. // Example 2:
  407. Ext.zip(
  408. [ "+", "-", "+"],
  409. [ 12, 10, 22],
  410. [ 43, 15, 96],
  411. function(a, b, c){
  412. return "$" + a + "" + b + "." + c
  413. }
  414. ); // ["$+12.43", "$-10.15", "$+22.96"]
  415. * </code></pre>
  416. * @param {Arrays|NodeLists} arr This argument may be repeated. Array(s) to contribute values.
  417. * @param {Function} zipper (optional) The last item in the argument list. This will drive how the items are zipped together.
  418. * @return {Array} The zipped set.
  419. */
  420. zip : function(){
  421. var parts = Ext.partition(arguments, function( val ){ return typeof val != 'function'; }),
  422. arrs = parts[0],
  423. fn = parts[1][0],
  424. len = Ext.max(Ext.pluck(arrs, "length")),
  425. ret = [];
  426. for (var i = 0; i < len; i++) {
  427. ret[i] = [];
  428. if(fn){
  429. ret[i] = fn.apply(fn, Ext.pluck(arrs, i));
  430. }else{
  431. for (var j = 0, aLen = arrs.length; j < aLen; j++){
  432. ret[i].push( arrs[j][i] );
  433. }
  434. }
  435. }
  436. return ret;
  437. },
  438. <div id="method-Ext-getCmp"></div>/**
  439. * This is shorthand reference to {@link Ext.ComponentMgr#get}.
  440. * Looks up an existing {@link Ext.Component Component} by {@link Ext.Component#id id}
  441. * @param {String} id The component {@link Ext.Component#id id}
  442. * @return Ext.Component The Component, <tt>undefined</tt> if not found, or <tt>null</tt> if a
  443. * Class was found.
  444. */
  445. getCmp : function(id){
  446. return Ext.ComponentMgr.get(id);
  447. },
  448. <div id="prop-Ext-useShims"></div>/**
  449. * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
  450. * you may want to set this to true.
  451. * @type Boolean
  452. */
  453. useShims: E.isIE6 || (E.isMac && E.isGecko2),
  454. // inpired by a similar function in mootools library
  455. <div id="method-Ext-type"></div>/**
  456. * Returns the type of object that is passed in. If the object passed in is null or undefined it
  457. * return false otherwise it returns one of the following values:<div class="mdetail-params"><ul>
  458. * <li><b>string</b>: If the object passed is a string</li>
  459. * <li><b>number</b>: If the object passed is a number</li>
  460. * <li><b>boolean</b>: If the object passed is a boolean value</li>
  461. * <li><b>date</b>: If the object passed is a Date object</li>
  462. * <li><b>function</b>: If the object passed is a function reference</li>
  463. * <li><b>object</b>: If the object passed is an object</li>
  464. * <li><b>array</b>: If the object passed is an array</li>
  465. * <li><b>regexp</b>: If the object passed is a regular expression</li>
  466. * <li><b>element</b>: If the object passed is a DOM Element</li>
  467. * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
  468. * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
  469. * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
  470. * </ul></div>
  471. * @param {Mixed} object
  472. * @return {String}
  473. */
  474. type : function(o){
  475. if(o === undefined || o === null){
  476. return false;
  477. }
  478. if(o.htmlElement){
  479. return 'element';
  480. }
  481. var t = typeof o;
  482. if(t == 'object' && o.nodeName) {
  483. switch(o.nodeType) {
  484. case 1: return 'element';
  485. case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
  486. }
  487. }
  488. if(t == 'object' || t == 'function') {
  489. switch(o.constructor) {
  490. case Array: return 'array';
  491. case RegExp: return 'regexp';
  492. case Date: return 'date';
  493. }
  494. if(typeof o.length == 'number' && typeof o.item == 'function') {
  495. return 'nodelist';
  496. }
  497. }
  498. return t;
  499. },
  500. intercept : function(o, name, fn, scope){
  501. o[name] = o[name].createInterceptor(fn, scope);
  502. },
  503. // internal
  504. callback : function(cb, scope, args, delay){
  505. if(typeof cb == 'function'){
  506. if(delay){
  507. cb.defer(delay, scope, args || []);
  508. }else{
  509. cb.apply(scope, args || []);
  510. }
  511. }
  512. }
  513. };
  514. }());
  515. /**
  516. * @class Function
  517. * These functions are available on every Function object (any JavaScript function).
  518. */
  519. Ext.apply(Function.prototype, {
  520. <div id="method-Function-createSequence"></div>/**
  521. * Create a combined function call sequence of the original function + the passed function.
  522. * The resulting function returns the results of the original function.
  523. * The passed fcn is called with the parameters of the original function. Example usage:
  524. * <pre><code>
  525. var sayHi = function(name){
  526. alert('Hi, ' + name);
  527. }
  528. sayHi('Fred'); // alerts "Hi, Fred"
  529. var sayGoodbye = sayHi.createSequence(function(name){
  530. alert('Bye, ' + name);
  531. });
  532. sayGoodbye('Fred'); // both alerts show
  533. </code></pre>
  534. * @param {Function} fcn The function to sequence
  535. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
  536. * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
  537. * @return {Function} The new function
  538. */
  539. createSequence : function(fcn, scope){
  540. var method = this;
  541. return (typeof fcn != 'function') ?
  542. this :
  543. function(){
  544. var retval = method.apply(this || window, arguments);
  545. fcn.apply(scope || this || window, arguments);
  546. return retval;
  547. };
  548. }
  549. });
  550. /**
  551. * @class String
  552. * These functions are available as static methods on the JavaScript String object.
  553. */
  554. Ext.applyIf(String, {
  555. <div id="method-String-escape"></div>/**
  556. * Escapes the passed string for ' and \
  557. * @param {String} string The string to escape
  558. * @return {String} The escaped string
  559. * @static
  560. */
  561. escape : function(string) {
  562. return string.replace(/('|\\)/g, "\\$1");
  563. },
  564. <div id="method-String-leftPad"></div>/**
  565. * Pads the left side of a string with a specified character. This is especially useful
  566. * for normalizing number and date strings. Example usage:
  567. * <pre><code>
  568. var s = String.leftPad('123', 5, '0');
  569. // s now contains the string: '00123'
  570. * </code></pre>
  571. * @param {String} string The original string
  572. * @param {Number} size The total length of the output string
  573. * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
  574. * @return {String} The padded string
  575. * @static
  576. */
  577. leftPad : function (val, size, ch) {
  578. var result = String(val);
  579. if(!ch) {
  580. ch = " ";
  581. }
  582. while (result.length < size) {
  583. result = ch + result;
  584. }
  585. return result;
  586. }
  587. });
  588. <div id="method-String-toggle"></div>/**
  589. * Utility function that allows you to easily switch a string between two alternating values. The passed value
  590. * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
  591. * they are already different, the first value passed in is returned. Note that this method returns the new value
  592. * but does not change the current string.
  593. * <pre><code>
  594. // alternate sort directions
  595. sort = sort.toggle('ASC', 'DESC');
  596. // instead of conditional logic:
  597. sort = (sort == 'ASC' ? 'DESC' : 'ASC');
  598. </code></pre>
  599. * @param {String} value The value to compare to the current string
  600. * @param {String} other The new value to use if the string already equals the first value passed in
  601. * @return {String} The new value
  602. */
  603. String.prototype.toggle = function(value, other){
  604. return this == value ? other : value;
  605. };
  606. <div id="method-String-trim"></div>/**
  607. * Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
  608. * <pre><code>
  609. var s = ' foo bar ';
  610. alert('-' + s + '-'); //alerts "- foo bar -"
  611. alert('-' + s.trim() + '-'); //alerts "-foo bar-"
  612. </code></pre>
  613. * @return {String} The trimmed string
  614. */
  615. String.prototype.trim = function(){
  616. var re = /^\s+|\s+$/g;
  617. return function(){ return this.replace(re, ""); };
  618. }();
  619. // here to prevent dependency on Date.js
  620. <div id="method-Date-getElapsed"></div>/**
  621. Returns the number of milliseconds between this date and date
  622. @param {Date} date (optional) Defaults to now
  623. @return {Number} The diff in milliseconds
  624. @member Date getElapsed
  625. */
  626. Date.prototype.getElapsed = function(date) {
  627. return Math.abs((date || new Date()).getTime()-this.getTime());
  628. };
  629. <div id="cls-Number"></div>/**
  630. * @class Number
  631. */
  632. Ext.applyIf(Number.prototype, {
  633. <div id="method-Number-constrain"></div>/**
  634. * Checks whether or not the current number is within a desired range. If the number is already within the
  635. * range it is returned, otherwise the min or max value is returned depending on which side of the range is
  636. * exceeded. Note that this method returns the constrained value but does not change the current number.
  637. * @param {Number} min The minimum number in the range
  638. * @param {Number} max The maximum number in the range
  639. * @return {Number} The constrained value if outside the range, otherwise the current value
  640. */
  641. constrain : function(min, max){
  642. return Math.min(Math.max(this, min), max);
  643. }
  644. });
  645. </pre>
  646. </body>
  647. </html>