1
0

progress.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  1. /*!
  2. * # Semantic UI 2.3.3 - Progress
  3. * http://github.com/semantic-org/semantic-ui/
  4. *
  5. *
  6. * Released under the MIT license
  7. * http://opensource.org/licenses/MIT
  8. *
  9. */
  10. ;(function ($, window, document, undefined) {
  11. 'use strict';
  12. window = (typeof window != 'undefined' && window.Math == Math)
  13. ? window
  14. : (typeof self != 'undefined' && self.Math == Math)
  15. ? self
  16. : Function('return this')()
  17. ;
  18. var
  19. global = (typeof window != 'undefined' && window.Math == Math)
  20. ? window
  21. : (typeof self != 'undefined' && self.Math == Math)
  22. ? self
  23. : Function('return this')()
  24. ;
  25. $.fn.progress = function(parameters) {
  26. var
  27. $allModules = $(this),
  28. moduleSelector = $allModules.selector || '',
  29. time = new Date().getTime(),
  30. performance = [],
  31. query = arguments[0],
  32. methodInvoked = (typeof query == 'string'),
  33. queryArguments = [].slice.call(arguments, 1),
  34. returnedValue
  35. ;
  36. $allModules
  37. .each(function() {
  38. var
  39. settings = ( $.isPlainObject(parameters) )
  40. ? $.extend(true, {}, $.fn.progress.settings, parameters)
  41. : $.extend({}, $.fn.progress.settings),
  42. className = settings.className,
  43. metadata = settings.metadata,
  44. namespace = settings.namespace,
  45. selector = settings.selector,
  46. error = settings.error,
  47. eventNamespace = '.' + namespace,
  48. moduleNamespace = 'module-' + namespace,
  49. $module = $(this),
  50. $bar = $(this).find(selector.bar),
  51. $progress = $(this).find(selector.progress),
  52. $label = $(this).find(selector.label),
  53. element = this,
  54. instance = $module.data(moduleNamespace),
  55. animating = false,
  56. transitionEnd,
  57. module
  58. ;
  59. module = {
  60. initialize: function() {
  61. module.debug('Initializing progress bar', settings);
  62. module.set.duration();
  63. module.set.transitionEvent();
  64. module.read.metadata();
  65. module.read.settings();
  66. module.instantiate();
  67. },
  68. instantiate: function() {
  69. module.verbose('Storing instance of progress', module);
  70. instance = module;
  71. $module
  72. .data(moduleNamespace, module)
  73. ;
  74. },
  75. destroy: function() {
  76. module.verbose('Destroying previous progress for', $module);
  77. clearInterval(instance.interval);
  78. module.remove.state();
  79. $module.removeData(moduleNamespace);
  80. instance = undefined;
  81. },
  82. reset: function() {
  83. module.remove.nextValue();
  84. module.update.progress(0);
  85. },
  86. complete: function() {
  87. if(module.percent === undefined || module.percent < 100) {
  88. module.remove.progressPoll();
  89. module.set.percent(100);
  90. }
  91. },
  92. read: {
  93. metadata: function() {
  94. var
  95. data = {
  96. percent : $module.data(metadata.percent),
  97. total : $module.data(metadata.total),
  98. value : $module.data(metadata.value)
  99. }
  100. ;
  101. if(data.percent) {
  102. module.debug('Current percent value set from metadata', data.percent);
  103. module.set.percent(data.percent);
  104. }
  105. if(data.total) {
  106. module.debug('Total value set from metadata', data.total);
  107. module.set.total(data.total);
  108. }
  109. if(data.value) {
  110. module.debug('Current value set from metadata', data.value);
  111. module.set.value(data.value);
  112. module.set.progress(data.value);
  113. }
  114. },
  115. settings: function() {
  116. if(settings.total !== false) {
  117. module.debug('Current total set in settings', settings.total);
  118. module.set.total(settings.total);
  119. }
  120. if(settings.value !== false) {
  121. module.debug('Current value set in settings', settings.value);
  122. module.set.value(settings.value);
  123. module.set.progress(module.value);
  124. }
  125. if(settings.percent !== false) {
  126. module.debug('Current percent set in settings', settings.percent);
  127. module.set.percent(settings.percent);
  128. }
  129. }
  130. },
  131. bind: {
  132. transitionEnd: function(callback) {
  133. var
  134. transitionEnd = module.get.transitionEnd()
  135. ;
  136. $bar
  137. .one(transitionEnd + eventNamespace, function(event) {
  138. clearTimeout(module.failSafeTimer);
  139. callback.call(this, event);
  140. })
  141. ;
  142. module.failSafeTimer = setTimeout(function() {
  143. $bar.triggerHandler(transitionEnd);
  144. }, settings.duration + settings.failSafeDelay);
  145. module.verbose('Adding fail safe timer', module.timer);
  146. }
  147. },
  148. increment: function(incrementValue) {
  149. var
  150. maxValue,
  151. startValue,
  152. newValue
  153. ;
  154. if( module.has.total() ) {
  155. startValue = module.get.value();
  156. incrementValue = incrementValue || 1;
  157. newValue = startValue + incrementValue;
  158. }
  159. else {
  160. startValue = module.get.percent();
  161. incrementValue = incrementValue || module.get.randomValue();
  162. newValue = startValue + incrementValue;
  163. maxValue = 100;
  164. module.debug('Incrementing percentage by', startValue, newValue);
  165. }
  166. newValue = module.get.normalizedValue(newValue);
  167. module.set.progress(newValue);
  168. },
  169. decrement: function(decrementValue) {
  170. var
  171. total = module.get.total(),
  172. startValue,
  173. newValue
  174. ;
  175. if(total) {
  176. startValue = module.get.value();
  177. decrementValue = decrementValue || 1;
  178. newValue = startValue - decrementValue;
  179. module.debug('Decrementing value by', decrementValue, startValue);
  180. }
  181. else {
  182. startValue = module.get.percent();
  183. decrementValue = decrementValue || module.get.randomValue();
  184. newValue = startValue - decrementValue;
  185. module.debug('Decrementing percentage by', decrementValue, startValue);
  186. }
  187. newValue = module.get.normalizedValue(newValue);
  188. module.set.progress(newValue);
  189. },
  190. has: {
  191. progressPoll: function() {
  192. return module.progressPoll;
  193. },
  194. total: function() {
  195. return (module.get.total() !== false);
  196. }
  197. },
  198. get: {
  199. text: function(templateText) {
  200. var
  201. value = module.value || 0,
  202. total = module.total || 0,
  203. percent = (animating)
  204. ? module.get.displayPercent()
  205. : module.percent || 0,
  206. left = (module.total > 0)
  207. ? (total - value)
  208. : (100 - percent)
  209. ;
  210. templateText = templateText || '';
  211. templateText = templateText
  212. .replace('{value}', value)
  213. .replace('{total}', total)
  214. .replace('{left}', left)
  215. .replace('{percent}', percent)
  216. ;
  217. module.verbose('Adding variables to progress bar text', templateText);
  218. return templateText;
  219. },
  220. normalizedValue: function(value) {
  221. if(value < 0) {
  222. module.debug('Value cannot decrement below 0');
  223. return 0;
  224. }
  225. if(module.has.total()) {
  226. if(value > module.total) {
  227. module.debug('Value cannot increment above total', module.total);
  228. return module.total;
  229. }
  230. }
  231. else if(value > 100 ) {
  232. module.debug('Value cannot increment above 100 percent');
  233. return 100;
  234. }
  235. return value;
  236. },
  237. updateInterval: function() {
  238. if(settings.updateInterval == 'auto') {
  239. return settings.duration;
  240. }
  241. return settings.updateInterval;
  242. },
  243. randomValue: function() {
  244. module.debug('Generating random increment percentage');
  245. return Math.floor((Math.random() * settings.random.max) + settings.random.min);
  246. },
  247. numericValue: function(value) {
  248. return (typeof value === 'string')
  249. ? (value.replace(/[^\d.]/g, '') !== '')
  250. ? +(value.replace(/[^\d.]/g, ''))
  251. : false
  252. : value
  253. ;
  254. },
  255. transitionEnd: function() {
  256. var
  257. element = document.createElement('element'),
  258. transitions = {
  259. 'transition' :'transitionend',
  260. 'OTransition' :'oTransitionEnd',
  261. 'MozTransition' :'transitionend',
  262. 'WebkitTransition' :'webkitTransitionEnd'
  263. },
  264. transition
  265. ;
  266. for(transition in transitions){
  267. if( element.style[transition] !== undefined ){
  268. return transitions[transition];
  269. }
  270. }
  271. },
  272. // gets current displayed percentage (if animating values this is the intermediary value)
  273. displayPercent: function() {
  274. var
  275. barWidth = $bar.width(),
  276. totalWidth = $module.width(),
  277. minDisplay = parseInt($bar.css('min-width'), 10),
  278. displayPercent = (barWidth > minDisplay)
  279. ? (barWidth / totalWidth * 100)
  280. : module.percent
  281. ;
  282. return (settings.precision > 0)
  283. ? Math.round(displayPercent * (10 * settings.precision)) / (10 * settings.precision)
  284. : Math.round(displayPercent)
  285. ;
  286. },
  287. percent: function() {
  288. return module.percent || 0;
  289. },
  290. value: function() {
  291. return module.nextValue || module.value || 0;
  292. },
  293. total: function() {
  294. return module.total || false;
  295. }
  296. },
  297. create: {
  298. progressPoll: function() {
  299. module.progressPoll = setTimeout(function() {
  300. module.update.toNextValue();
  301. module.remove.progressPoll();
  302. }, module.get.updateInterval());
  303. },
  304. },
  305. is: {
  306. complete: function() {
  307. return module.is.success() || module.is.warning() || module.is.error();
  308. },
  309. success: function() {
  310. return $module.hasClass(className.success);
  311. },
  312. warning: function() {
  313. return $module.hasClass(className.warning);
  314. },
  315. error: function() {
  316. return $module.hasClass(className.error);
  317. },
  318. active: function() {
  319. return $module.hasClass(className.active);
  320. },
  321. visible: function() {
  322. return $module.is(':visible');
  323. }
  324. },
  325. remove: {
  326. progressPoll: function() {
  327. module.verbose('Removing progress poll timer');
  328. if(module.progressPoll) {
  329. clearTimeout(module.progressPoll);
  330. delete module.progressPoll;
  331. }
  332. },
  333. nextValue: function() {
  334. module.verbose('Removing progress value stored for next update');
  335. delete module.nextValue;
  336. },
  337. state: function() {
  338. module.verbose('Removing stored state');
  339. delete module.total;
  340. delete module.percent;
  341. delete module.value;
  342. },
  343. active: function() {
  344. module.verbose('Removing active state');
  345. $module.removeClass(className.active);
  346. },
  347. success: function() {
  348. module.verbose('Removing success state');
  349. $module.removeClass(className.success);
  350. },
  351. warning: function() {
  352. module.verbose('Removing warning state');
  353. $module.removeClass(className.warning);
  354. },
  355. error: function() {
  356. module.verbose('Removing error state');
  357. $module.removeClass(className.error);
  358. }
  359. },
  360. set: {
  361. barWidth: function(value) {
  362. if(value > 100) {
  363. module.error(error.tooHigh, value);
  364. }
  365. else if (value < 0) {
  366. module.error(error.tooLow, value);
  367. }
  368. else {
  369. $bar
  370. .css('width', value + '%')
  371. ;
  372. $module
  373. .attr('data-percent', parseInt(value, 10))
  374. ;
  375. }
  376. },
  377. duration: function(duration) {
  378. duration = duration || settings.duration;
  379. duration = (typeof duration == 'number')
  380. ? duration + 'ms'
  381. : duration
  382. ;
  383. module.verbose('Setting progress bar transition duration', duration);
  384. $bar
  385. .css({
  386. 'transition-duration': duration
  387. })
  388. ;
  389. },
  390. percent: function(percent) {
  391. percent = (typeof percent == 'string')
  392. ? +(percent.replace('%', ''))
  393. : percent
  394. ;
  395. // round display percentage
  396. percent = (settings.precision > 0)
  397. ? Math.round(percent * (10 * settings.precision)) / (10 * settings.precision)
  398. : Math.round(percent)
  399. ;
  400. module.percent = percent;
  401. if( !module.has.total() ) {
  402. module.value = (settings.precision > 0)
  403. ? Math.round( (percent / 100) * module.total * (10 * settings.precision)) / (10 * settings.precision)
  404. : Math.round( (percent / 100) * module.total * 10) / 10
  405. ;
  406. if(settings.limitValues) {
  407. module.value = (module.value > 100)
  408. ? 100
  409. : (module.value < 0)
  410. ? 0
  411. : module.value
  412. ;
  413. }
  414. }
  415. module.set.barWidth(percent);
  416. module.set.labelInterval();
  417. module.set.labels();
  418. settings.onChange.call(element, percent, module.value, module.total);
  419. },
  420. labelInterval: function() {
  421. var
  422. animationCallback = function() {
  423. module.verbose('Bar finished animating, removing continuous label updates');
  424. clearInterval(module.interval);
  425. animating = false;
  426. module.set.labels();
  427. }
  428. ;
  429. clearInterval(module.interval);
  430. module.bind.transitionEnd(animationCallback);
  431. animating = true;
  432. module.interval = setInterval(function() {
  433. var
  434. isInDOM = $.contains(document.documentElement, element)
  435. ;
  436. if(!isInDOM) {
  437. clearInterval(module.interval);
  438. animating = false;
  439. }
  440. module.set.labels();
  441. }, settings.framerate);
  442. },
  443. labels: function() {
  444. module.verbose('Setting both bar progress and outer label text');
  445. module.set.barLabel();
  446. module.set.state();
  447. },
  448. label: function(text) {
  449. text = text || '';
  450. if(text) {
  451. text = module.get.text(text);
  452. module.verbose('Setting label to text', text);
  453. $label.text(text);
  454. }
  455. },
  456. state: function(percent) {
  457. percent = (percent !== undefined)
  458. ? percent
  459. : module.percent
  460. ;
  461. if(percent === 100) {
  462. if(settings.autoSuccess && !(module.is.warning() || module.is.error() || module.is.success())) {
  463. module.set.success();
  464. module.debug('Automatically triggering success at 100%');
  465. }
  466. else {
  467. module.verbose('Reached 100% removing active state');
  468. module.remove.active();
  469. module.remove.progressPoll();
  470. }
  471. }
  472. else if(percent > 0) {
  473. module.verbose('Adjusting active progress bar label', percent);
  474. module.set.active();
  475. }
  476. else {
  477. module.remove.active();
  478. module.set.label(settings.text.active);
  479. }
  480. },
  481. barLabel: function(text) {
  482. if(text !== undefined) {
  483. $progress.text( module.get.text(text) );
  484. }
  485. else if(settings.label == 'ratio' && module.total) {
  486. module.verbose('Adding ratio to bar label');
  487. $progress.text( module.get.text(settings.text.ratio) );
  488. }
  489. else if(settings.label == 'percent') {
  490. module.verbose('Adding percentage to bar label');
  491. $progress.text( module.get.text(settings.text.percent) );
  492. }
  493. },
  494. active: function(text) {
  495. text = text || settings.text.active;
  496. module.debug('Setting active state');
  497. if(settings.showActivity && !module.is.active() ) {
  498. $module.addClass(className.active);
  499. }
  500. module.remove.warning();
  501. module.remove.error();
  502. module.remove.success();
  503. text = settings.onLabelUpdate('active', text, module.value, module.total);
  504. if(text) {
  505. module.set.label(text);
  506. }
  507. module.bind.transitionEnd(function() {
  508. settings.onActive.call(element, module.value, module.total);
  509. });
  510. },
  511. success : function(text) {
  512. text = text || settings.text.success || settings.text.active;
  513. module.debug('Setting success state');
  514. $module.addClass(className.success);
  515. module.remove.active();
  516. module.remove.warning();
  517. module.remove.error();
  518. module.complete();
  519. if(settings.text.success) {
  520. text = settings.onLabelUpdate('success', text, module.value, module.total);
  521. module.set.label(text);
  522. }
  523. else {
  524. text = settings.onLabelUpdate('active', text, module.value, module.total);
  525. module.set.label(text);
  526. }
  527. module.bind.transitionEnd(function() {
  528. settings.onSuccess.call(element, module.total);
  529. });
  530. },
  531. warning : function(text) {
  532. text = text || settings.text.warning;
  533. module.debug('Setting warning state');
  534. $module.addClass(className.warning);
  535. module.remove.active();
  536. module.remove.success();
  537. module.remove.error();
  538. module.complete();
  539. text = settings.onLabelUpdate('warning', text, module.value, module.total);
  540. if(text) {
  541. module.set.label(text);
  542. }
  543. module.bind.transitionEnd(function() {
  544. settings.onWarning.call(element, module.value, module.total);
  545. });
  546. },
  547. error : function(text) {
  548. text = text || settings.text.error;
  549. module.debug('Setting error state');
  550. $module.addClass(className.error);
  551. module.remove.active();
  552. module.remove.success();
  553. module.remove.warning();
  554. module.complete();
  555. text = settings.onLabelUpdate('error', text, module.value, module.total);
  556. if(text) {
  557. module.set.label(text);
  558. }
  559. module.bind.transitionEnd(function() {
  560. settings.onError.call(element, module.value, module.total);
  561. });
  562. },
  563. transitionEvent: function() {
  564. transitionEnd = module.get.transitionEnd();
  565. },
  566. total: function(totalValue) {
  567. module.total = totalValue;
  568. },
  569. value: function(value) {
  570. module.value = value;
  571. },
  572. progress: function(value) {
  573. if(!module.has.progressPoll()) {
  574. module.debug('First update in progress update interval, immediately updating', value);
  575. module.update.progress(value);
  576. module.create.progressPoll();
  577. }
  578. else {
  579. module.debug('Updated within interval, setting next update to use new value', value);
  580. module.set.nextValue(value);
  581. }
  582. },
  583. nextValue: function(value) {
  584. module.nextValue = value;
  585. }
  586. },
  587. update: {
  588. toNextValue: function() {
  589. var
  590. nextValue = module.nextValue
  591. ;
  592. if(nextValue) {
  593. module.debug('Update interval complete using last updated value', nextValue);
  594. module.update.progress(nextValue);
  595. module.remove.nextValue();
  596. }
  597. },
  598. progress: function(value) {
  599. var
  600. percentComplete
  601. ;
  602. value = module.get.numericValue(value);
  603. if(value === false) {
  604. module.error(error.nonNumeric, value);
  605. }
  606. value = module.get.normalizedValue(value);
  607. if( module.has.total() ) {
  608. module.set.value(value);
  609. percentComplete = (value / module.total) * 100;
  610. module.debug('Calculating percent complete from total', percentComplete);
  611. module.set.percent( percentComplete );
  612. }
  613. else {
  614. percentComplete = value;
  615. module.debug('Setting value to exact percentage value', percentComplete);
  616. module.set.percent( percentComplete );
  617. }
  618. }
  619. },
  620. setting: function(name, value) {
  621. module.debug('Changing setting', name, value);
  622. if( $.isPlainObject(name) ) {
  623. $.extend(true, settings, name);
  624. }
  625. else if(value !== undefined) {
  626. if($.isPlainObject(settings[name])) {
  627. $.extend(true, settings[name], value);
  628. }
  629. else {
  630. settings[name] = value;
  631. }
  632. }
  633. else {
  634. return settings[name];
  635. }
  636. },
  637. internal: function(name, value) {
  638. if( $.isPlainObject(name) ) {
  639. $.extend(true, module, name);
  640. }
  641. else if(value !== undefined) {
  642. module[name] = value;
  643. }
  644. else {
  645. return module[name];
  646. }
  647. },
  648. debug: function() {
  649. if(!settings.silent && settings.debug) {
  650. if(settings.performance) {
  651. module.performance.log(arguments);
  652. }
  653. else {
  654. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  655. module.debug.apply(console, arguments);
  656. }
  657. }
  658. },
  659. verbose: function() {
  660. if(!settings.silent && settings.verbose && settings.debug) {
  661. if(settings.performance) {
  662. module.performance.log(arguments);
  663. }
  664. else {
  665. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  666. module.verbose.apply(console, arguments);
  667. }
  668. }
  669. },
  670. error: function() {
  671. if(!settings.silent) {
  672. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  673. module.error.apply(console, arguments);
  674. }
  675. },
  676. performance: {
  677. log: function(message) {
  678. var
  679. currentTime,
  680. executionTime,
  681. previousTime
  682. ;
  683. if(settings.performance) {
  684. currentTime = new Date().getTime();
  685. previousTime = time || currentTime;
  686. executionTime = currentTime - previousTime;
  687. time = currentTime;
  688. performance.push({
  689. 'Name' : message[0],
  690. 'Arguments' : [].slice.call(message, 1) || '',
  691. 'Element' : element,
  692. 'Execution Time' : executionTime
  693. });
  694. }
  695. clearTimeout(module.performance.timer);
  696. module.performance.timer = setTimeout(module.performance.display, 500);
  697. },
  698. display: function() {
  699. var
  700. title = settings.name + ':',
  701. totalTime = 0
  702. ;
  703. time = false;
  704. clearTimeout(module.performance.timer);
  705. $.each(performance, function(index, data) {
  706. totalTime += data['Execution Time'];
  707. });
  708. title += ' ' + totalTime + 'ms';
  709. if(moduleSelector) {
  710. title += ' \'' + moduleSelector + '\'';
  711. }
  712. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  713. console.groupCollapsed(title);
  714. if(console.table) {
  715. console.table(performance);
  716. }
  717. else {
  718. $.each(performance, function(index, data) {
  719. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  720. });
  721. }
  722. console.groupEnd();
  723. }
  724. performance = [];
  725. }
  726. },
  727. invoke: function(query, passedArguments, context) {
  728. var
  729. object = instance,
  730. maxDepth,
  731. found,
  732. response
  733. ;
  734. passedArguments = passedArguments || queryArguments;
  735. context = element || context;
  736. if(typeof query == 'string' && object !== undefined) {
  737. query = query.split(/[\. ]/);
  738. maxDepth = query.length - 1;
  739. $.each(query, function(depth, value) {
  740. var camelCaseValue = (depth != maxDepth)
  741. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  742. : query
  743. ;
  744. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  745. object = object[camelCaseValue];
  746. }
  747. else if( object[camelCaseValue] !== undefined ) {
  748. found = object[camelCaseValue];
  749. return false;
  750. }
  751. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  752. object = object[value];
  753. }
  754. else if( object[value] !== undefined ) {
  755. found = object[value];
  756. return false;
  757. }
  758. else {
  759. module.error(error.method, query);
  760. return false;
  761. }
  762. });
  763. }
  764. if ( $.isFunction( found ) ) {
  765. response = found.apply(context, passedArguments);
  766. }
  767. else if(found !== undefined) {
  768. response = found;
  769. }
  770. if($.isArray(returnedValue)) {
  771. returnedValue.push(response);
  772. }
  773. else if(returnedValue !== undefined) {
  774. returnedValue = [returnedValue, response];
  775. }
  776. else if(response !== undefined) {
  777. returnedValue = response;
  778. }
  779. return found;
  780. }
  781. };
  782. if(methodInvoked) {
  783. if(instance === undefined) {
  784. module.initialize();
  785. }
  786. module.invoke(query);
  787. }
  788. else {
  789. if(instance !== undefined) {
  790. instance.invoke('destroy');
  791. }
  792. module.initialize();
  793. }
  794. })
  795. ;
  796. return (returnedValue !== undefined)
  797. ? returnedValue
  798. : this
  799. ;
  800. };
  801. $.fn.progress.settings = {
  802. name : 'Progress',
  803. namespace : 'progress',
  804. silent : false,
  805. debug : false,
  806. verbose : false,
  807. performance : true,
  808. random : {
  809. min : 2,
  810. max : 5
  811. },
  812. duration : 300,
  813. updateInterval : 'auto',
  814. autoSuccess : true,
  815. showActivity : true,
  816. limitValues : true,
  817. label : 'percent',
  818. precision : 0,
  819. framerate : (1000 / 30), /// 30 fps
  820. percent : false,
  821. total : false,
  822. value : false,
  823. // delay in ms for fail safe animation callback
  824. failSafeDelay : 100,
  825. onLabelUpdate : function(state, text, value, total){
  826. return text;
  827. },
  828. onChange : function(percent, value, total){},
  829. onSuccess : function(total){},
  830. onActive : function(value, total){},
  831. onError : function(value, total){},
  832. onWarning : function(value, total){},
  833. error : {
  834. method : 'The method you called is not defined.',
  835. nonNumeric : 'Progress value is non numeric',
  836. tooHigh : 'Value specified is above 100%',
  837. tooLow : 'Value specified is below 0%'
  838. },
  839. regExp: {
  840. variable: /\{\$*[A-z0-9]+\}/g
  841. },
  842. metadata: {
  843. percent : 'percent',
  844. total : 'total',
  845. value : 'value'
  846. },
  847. selector : {
  848. bar : '> .bar',
  849. label : '> .label',
  850. progress : '.bar > .progress'
  851. },
  852. text : {
  853. active : false,
  854. error : false,
  855. success : false,
  856. warning : false,
  857. percent : '{percent}%',
  858. ratio : '{value} of {total}'
  859. },
  860. className : {
  861. active : 'active',
  862. error : 'error',
  863. success : 'success',
  864. warning : 'warning'
  865. }
  866. };
  867. })( jQuery, window, document );