cybele 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/README.md +16 -2
  4. data/dump.rdb +1 -0
  5. data/lib/cybele/app_builder.rb +213 -220
  6. data/lib/cybele/generators/app_generator.rb +31 -20
  7. data/lib/cybele/version.rb +2 -2
  8. data/templates/.env.local.erb +11 -0
  9. data/templates/.env.production.erb +11 -0
  10. data/templates/.env.staging.erb +11 -0
  11. data/templates/README.md.erb +22 -0
  12. data/templates/app/assets/javascripts/application.js.coffee +63 -1
  13. data/templates/app/assets/javascripts/hq/application.js.coffee +93 -0
  14. data/templates/app/assets/stylesheets/application.css.sass +15 -4
  15. data/templates/app/assets/stylesheets/hq/application.css.sass +92 -0
  16. data/templates/app/controllers/application_controller.rb.erb +48 -0
  17. data/templates/app/controllers/concerns/basic_authentication.rb +18 -0
  18. data/templates/app/controllers/hq/admins_controller.rb +64 -0
  19. data/templates/app/controllers/hq/application_controller.rb +11 -0
  20. data/templates/app/controllers/hq/audits_controller.rb +16 -0
  21. data/templates/app/controllers/hq/cities_controller.rb +54 -0
  22. data/templates/app/controllers/hq/countries_controller.rb +54 -0
  23. data/templates/app/controllers/hq/dashboard_controller.rb +4 -1
  24. data/templates/app/controllers/hq/passwords_controller.rb +10 -0
  25. data/templates/app/controllers/hq/registrations_controller.rb +21 -0
  26. data/templates/app/controllers/hq/sessions_controller.rb +1 -1
  27. data/templates/app/controllers/hq/users_controller.rb +64 -0
  28. data/templates/app/controllers/user/dashboard_controller.rb +8 -0
  29. data/templates/app/controllers/user/passwords_controller.rb +10 -0
  30. data/templates/app/controllers/user/profiles_controller.rb +34 -0
  31. data/templates/app/controllers/user/registrations_controller.rb +20 -0
  32. data/templates/app/controllers/user/sessions_controller.rb +16 -0
  33. data/templates/app/controllers/user/user_application_controller.rb +20 -0
  34. data/templates/app/helpers/application_helper.rb.erb +27 -0
  35. data/templates/app/mailers/admin_mailer.rb +10 -0
  36. data/templates/app/mailers/base_mailer.rb +4 -0
  37. data/templates/app/mailers/user_mailer.rb +10 -0
  38. data/templates/app/models/admin.rb +51 -0
  39. data/templates/app/models/audit.rb +3 -0
  40. data/templates/app/models/city.rb +12 -0
  41. data/templates/app/models/country.rb +12 -0
  42. data/templates/app/models/user.rb +54 -0
  43. data/templates/app/views/admin_mailer/login_info.html.haml +13 -0
  44. data/templates/app/views/devise/confirmations/new.html.haml +6 -5
  45. data/templates/app/views/devise/mailer/confirmation_instructions.html.haml +5 -3
  46. data/templates/app/views/devise/mailer/reset_password_instructions.html.haml +2 -2
  47. data/templates/app/views/devise/passwords/edit.html.haml +3 -3
  48. data/templates/app/views/devise/passwords/new.html.haml +3 -3
  49. data/templates/app/views/devise/registrations/edit.html.haml +5 -11
  50. data/templates/app/views/devise/registrations/new.html.haml +18 -6
  51. data/templates/app/views/devise/sessions/new.html.haml +1 -1
  52. data/templates/app/views/devise/shared/_links.haml +3 -1
  53. data/templates/app/views/devise/unlocks/new.html.haml +4 -4
  54. data/templates/app/views/hq/admins/_admin.html.haml +21 -0
  55. data/templates/app/views/hq/admins/_blank.html.haml +9 -0
  56. data/templates/app/views/hq/admins/_filters.html.haml +20 -0
  57. data/templates/app/views/hq/admins/_form.html.haml +17 -0
  58. data/templates/app/views/hq/admins/_list.html.haml +15 -0
  59. data/templates/app/views/hq/admins/edit.html.haml +3 -0
  60. data/templates/app/views/hq/admins/index.html.haml +18 -0
  61. data/templates/app/views/hq/admins/new.html.haml +5 -0
  62. data/templates/app/views/hq/admins/show.html.haml +19 -0
  63. data/templates/app/views/hq/audits/_filters.html.haml +32 -0
  64. data/templates/app/views/hq/audits/_list.html.haml +37 -0
  65. data/templates/app/views/hq/audits/index.html.haml +5 -0
  66. data/templates/app/views/hq/audits/show.html.haml +5 -0
  67. data/templates/app/views/hq/cities/_blank.html.haml +9 -0
  68. data/templates/app/views/hq/cities/_city.html.haml +12 -0
  69. data/templates/app/views/hq/cities/_filters.html.haml +15 -0
  70. data/templates/app/views/hq/cities/_form.html.haml +15 -0
  71. data/templates/app/views/hq/cities/_list.html.haml +13 -0
  72. data/templates/app/views/hq/cities/edit.html.haml +3 -0
  73. data/templates/app/views/hq/cities/index.html.haml +18 -0
  74. data/templates/app/views/hq/cities/new.html.haml +3 -0
  75. data/templates/app/views/hq/cities/show.html.haml +13 -0
  76. data/templates/app/views/hq/countries/_blank.html.haml +9 -0
  77. data/templates/app/views/hq/countries/_country.html.haml +11 -0
  78. data/templates/app/views/hq/countries/_filters.html.haml +14 -0
  79. data/templates/app/views/hq/countries/_form.html.haml +14 -0
  80. data/templates/app/views/hq/countries/_list.html.haml +12 -0
  81. data/templates/app/views/hq/countries/edit.html.haml +3 -0
  82. data/templates/app/views/hq/countries/index.html.haml +18 -0
  83. data/templates/app/views/hq/countries/new.html.haml +3 -0
  84. data/templates/app/views/hq/countries/show.html.haml +14 -0
  85. data/templates/app/views/hq/dashboard/index.html.haml +8 -0
  86. data/templates/app/views/hq/passwords/edit.html.haml +12 -0
  87. data/templates/app/views/hq/passwords/new.html.haml +9 -0
  88. data/templates/app/views/hq/registrations/edit.html.haml +19 -0
  89. data/templates/app/views/hq/sessions/new.html.haml +7 -5
  90. data/templates/app/views/hq/users/_blank.html.haml +9 -0
  91. data/templates/app/views/hq/users/_filters.html.haml +20 -0
  92. data/templates/app/views/hq/users/_form.html.haml +18 -0
  93. data/templates/app/views/hq/users/_list.html.haml +15 -0
  94. data/templates/app/views/hq/users/_user.html.haml +20 -0
  95. data/templates/app/views/hq/users/edit.html.haml +3 -0
  96. data/templates/app/views/hq/users/index.html.haml +18 -0
  97. data/templates/app/views/hq/users/new.html.haml +5 -0
  98. data/templates/app/views/hq/users/show.html.haml +20 -0
  99. data/templates/app/views/layouts/application.html.haml.erb +16 -8
  100. data/templates/app/views/layouts/hq/application.html.haml.erb +55 -0
  101. data/templates/app/views/layouts/hq/login.html.haml.erb +35 -0
  102. data/templates/app/views/layouts/hq/partials/_dock.html.haml.erb +36 -0
  103. data/templates/app/views/layouts/hq/partials/_footer.html.haml.erb +0 -0
  104. data/templates/app/views/layouts/hq/partials/_navbar.html.haml.erb +22 -0
  105. data/templates/app/views/layouts/hq/partials/_trackers.html.haml.erb +0 -0
  106. data/templates/app/views/layouts/mailer.html.haml.erb +321 -0
  107. data/templates/app/views/layouts/mailer.text.haml +1 -0
  108. data/templates/app/views/layouts/partials/_footer.html.haml.erb +0 -0
  109. data/templates/app/views/layouts/partials/_trackers.html.haml.erb +0 -0
  110. data/templates/app/views/layouts/partials/_warnings.html.haml.erb +3 -0
  111. data/templates/app/views/user/dashboard/index.html.haml +8 -0
  112. data/templates/app/views/user/passwords/edit.html.haml +12 -0
  113. data/templates/app/views/user/passwords/new.html.haml +10 -0
  114. data/templates/app/views/{user_profiles → user/profiles}/_form.html.haml +4 -5
  115. data/templates/app/views/user/profiles/edit.html.haml +3 -0
  116. data/templates/app/views/user/profiles/show.html.haml +15 -0
  117. data/templates/app/views/user/registrations/edit.html.haml +19 -0
  118. data/templates/app/views/user/sessions/new.html.haml +11 -0
  119. data/templates/app/views/user_mailer/login_info.html.haml +13 -0
  120. data/templates/app/views/welcome/index.html.haml.erb +4 -4
  121. data/templates/config/initializers/devise_async.rb +6 -0
  122. data/templates/config/initializers/sidekiq.rb +13 -0
  123. data/templates/config/locales/email.tr.yml +28 -0
  124. data/templates/config/locales/models.tr.yml +72 -41
  125. data/templates/config/locales/responders.tr.yml +4 -1
  126. data/templates/config/locales/show_for.tr.yml +1 -3
  127. data/templates/config/locales/simple_form.tr.yml +8 -22
  128. data/templates/config/locales/tr.yml +33 -2
  129. data/templates/config/locales/view.tr.yml +64 -18
  130. data/templates/config/routes.erb +51 -0
  131. data/templates/config/schedule.yml +16 -0
  132. data/templates/config/settings/production.yml +0 -17
  133. data/templates/config/settings/staging.yml +0 -17
  134. data/templates/config/sidekiq.yml +13 -0
  135. data/templates/cybele_Gemfile +42 -5
  136. data/templates/cybele_gitignore +3 -1
  137. data/templates/cybele_version.txt +1 -0
  138. data/templates/env.sample.erb +11 -0
  139. data/templates/lib/data/cities.yml +163 -0
  140. data/templates/lib/tasks/dev.rake +29 -5
  141. data/templates/lib/tasks/sidekiq.rake +26 -0
  142. data/templates/lib/templates/rails/responders_controller/controller.rb +27 -22
  143. data/templates/public/images/favicon.png +0 -0
  144. data/templates/public/images/mail-logo.png +0 -0
  145. data/templates/public/images/missing_cover.png +0 -0
  146. data/templates/public/images/missing_cover@2x.png +0 -0
  147. data/templates/public/images/missing_logo.png +0 -0
  148. data/templates/public/images/missing_logo@2x.png +0 -0
  149. data/templates/public/images/sprite.png +0 -0
  150. data/templates/ruby-version +1 -1
  151. data/templates/vendor/assets/javascripts/jquery.datetimepicker.js +1871 -0
  152. data/templates/vendor/assets/javascripts/jquery.maskedinput.min.js +7 -0
  153. data/templates/vendor/assets/javascripts/nprogress.js +491 -0
  154. data/templates/vendor/assets/javascripts/trix.js +25 -0
  155. data/templates/vendor/assets/stylesheets/jquery.datetimepicker.css +418 -0
  156. data/templates/vendor/assets/stylesheets/nprogress.css +74 -0
  157. data/templates/vendor/assets/stylesheets/trix.css +209 -0
  158. metadata +125 -24
  159. data/templates/app/controllers/application_controller.rb +0 -19
  160. data/templates/app/controllers/hq/admin_profiles_controller.rb +0 -56
  161. data/templates/app/controllers/user_profiles_controller.rb +0 -56
  162. data/templates/app/views/hq/admin_profiles/_form.html.haml +0 -15
  163. data/templates/app/views/hq/admin_profiles/edit.html.haml +0 -3
  164. data/templates/app/views/hq/admin_profiles/new.html.haml +0 -3
  165. data/templates/app/views/hq/admin_profiles/show.html.haml +0 -13
  166. data/templates/app/views/hq/dashboard/index.html.haml.erb +0 -3
  167. data/templates/app/views/user_profiles/edit.html.haml +0 -3
  168. data/templates/app/views/user_profiles/new.html.haml +0 -3
  169. data/templates/app/views/user_profiles/show.html.haml +0 -13
  170. data/templates/config/locales/en.yml +0 -2
  171. data/templates/config/locales/models.en.yml +0 -54
  172. data/templates/config/locales/responders.en.yml +0 -10
  173. data/templates/config/locales/show_for.en.yml +0 -7
  174. data/templates/config/locales/simple_form.en.yml +0 -30
  175. data/templates/config/locales/view.en.yml +0 -51
@@ -0,0 +1,7 @@
1
+ /*
2
+ jQuery Masked Input Plugin
3
+ Copyright (c) 2007 - 2015 Josh Bush (digitalbush.com)
4
+ Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license)
5
+ Version: 1.4.1
6
+ */
7
+ !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){var b,c=navigator.userAgent,d=/iphone/i.test(c),e=/chrome/i.test(c),f=/android/i.test(c);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(c,g){var h,i,j,k,l,m,n,o;if(!c&&this.length>0){h=a(this[0]);var p=h.data(a.mask.dataName);return p?p():void 0}return g=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},g),i=a.mask.definitions,j=[],k=n=c.length,l=null,a.each(c.split(""),function(a,b){"?"==b?(n--,k=a):i[b]?(j.push(new RegExp(i[b])),null===l&&(l=j.length-1),k>a&&(m=j.length-1)):j.push(null)}),this.trigger("unmask").each(function(){function h(){if(g.completed){for(var a=l;m>=a;a++)if(j[a]&&C[a]===p(a))return;g.completed.call(B)}}function p(a){return g.placeholder.charAt(a<g.placeholder.length?a:0)}function q(a){for(;++a<n&&!j[a];);return a}function r(a){for(;--a>=0&&!j[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);n>c;c++)if(j[c]){if(!(n>d&&j[c].test(C[d])))break;C[c]=C[d],C[d]=p(d),d=q(d)}z(),B.caret(Math.max(l,a))}}function t(a){var b,c,d,e;for(b=a,c=p(a);n>b;b++)if(j[b]){if(d=q(b),e=C[b],C[b]=c,!(n>d&&j[d].test(e)))break;c=e}}function u(){var a=B.val(),b=B.caret();if(o&&o.length&&o.length>a.length){for(A(!0);b.begin>0&&!j[b.begin-1];)b.begin--;if(0===b.begin)for(;b.begin<l&&!j[b.begin];)b.begin++;B.caret(b.begin,b.begin)}else{for(A(!0);b.begin<n&&!j[b.begin];)b.begin++;B.caret(b.begin,b.begin)}h()}function v(){A(),B.val()!=E&&B.change()}function w(a){if(!B.prop("readonly")){var b,c,e,f=a.which||a.keyCode;o=B.val(),8===f||46===f||d&&127===f?(b=B.caret(),c=b.begin,e=b.end,e-c===0&&(c=46!==f?r(c):e=q(c-1),e=46===f?q(e):e),y(c,e),s(c,e-1),a.preventDefault()):13===f?v.call(this,a):27===f&&(B.val(E),B.caret(0,A()),a.preventDefault())}}function x(b){if(!B.prop("readonly")){var c,d,e,g=b.which||b.keyCode,i=B.caret();if(!(b.ctrlKey||b.altKey||b.metaKey||32>g)&&g&&13!==g){if(i.end-i.begin!==0&&(y(i.begin,i.end),s(i.begin,i.end-1)),c=q(i.begin-1),n>c&&(d=String.fromCharCode(g),j[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),f){var k=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(k,0)}else B.caret(e);i.begin<=m&&h()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&n>c;c++)j[c]&&(C[c]=p(c))}function z(){B.val(C.join(""))}function A(a){var b,c,d,e=B.val(),f=-1;for(b=0,d=0;n>b;b++)if(j[b]){for(C[b]=p(b);d++<e.length;)if(c=e.charAt(d-1),j[b].test(c)){C[b]=c,f=b;break}if(d>e.length){y(b+1,n);break}}else C[b]===e.charAt(d)&&d++,k>b&&(f=b);return a?z():k>f+1?g.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,n)):z():(z(),B.val(B.val().substring(0,f+1))),k?b:l}var B=a(this),C=a.map(c.split(""),function(a,b){return"?"!=a?i[a]?p(b):a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return j[b]&&a!=p(b)?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(b);var a;E=B.val(),a=A(),b=setTimeout(function(){B.get(0)===document.activeElement&&(z(),a==c.replace("?","").length?B.caret(0,a):B.caret(a))},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on("input.mask paste.mask",function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),h()},0)}),e&&f&&B.off("input.mask").on("input.mask",u),A()})}})});
@@ -0,0 +1,491 @@
1
+ /* NProgress, (c) 2013, 2014 Rico Sta. Cruz - http://ricostacruz.com/nprogress
2
+ * @license MIT */
3
+
4
+ ;(function(root, factory) {
5
+
6
+ if (typeof define === 'function' && define.amd) {
7
+ define(factory);
8
+ } else if (typeof exports === 'object') {
9
+ module.exports = factory();
10
+ } else {
11
+ root.NProgress = factory();
12
+ }
13
+
14
+ })(this, function() {
15
+ var NProgress = {};
16
+
17
+ NProgress.version = '0.2.0';
18
+
19
+ var Settings = NProgress.settings = {
20
+ minimum: 0.08,
21
+ easing: 'linear',
22
+ positionUsing: '',
23
+ speed: 350,
24
+ trickle: true,
25
+ trickleSpeed: 250,
26
+ showSpinner: true,
27
+ barSelector: '[role="bar"]',
28
+ spinnerSelector: '[role="spinner"]',
29
+ parent: 'body',
30
+ template: '<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>'
31
+ };
32
+
33
+ /**
34
+ * Updates configuration.
35
+ *
36
+ * NProgress.configure({
37
+ * minimum: 0.1
38
+ * });
39
+ */
40
+ NProgress.configure = function(options) {
41
+ var key, value;
42
+ for (key in options) {
43
+ value = options[key];
44
+ if (value !== undefined && options.hasOwnProperty(key)) Settings[key] = value;
45
+ }
46
+
47
+ return this;
48
+ };
49
+
50
+ /**
51
+ * Last number.
52
+ */
53
+
54
+ NProgress.status = null;
55
+
56
+ /**
57
+ * Sets the progress bar status, where `n` is a number from `0.0` to `1.0`.
58
+ *
59
+ * NProgress.set(0.4);
60
+ * NProgress.set(1.0);
61
+ */
62
+
63
+ NProgress.set = function(n) {
64
+ var started = NProgress.isStarted();
65
+
66
+ n = clamp(n, Settings.minimum, 1);
67
+ NProgress.status = (n === 1 ? null : n);
68
+
69
+ var progress = NProgress.render(!started),
70
+ bar = progress.querySelector(Settings.barSelector),
71
+ speed = Settings.speed,
72
+ ease = Settings.easing;
73
+
74
+ progress.offsetWidth; /* Repaint */
75
+
76
+ queue(function(next) {
77
+ // Set positionUsing if it hasn't already been set
78
+ if (Settings.positionUsing === '') Settings.positionUsing = NProgress.getPositioningCSS();
79
+
80
+ // Add transition
81
+ css(bar, barPositionCSS(n, speed, ease));
82
+
83
+ if (n === 1) {
84
+ // Fade out
85
+ css(progress, {
86
+ transition: 'none',
87
+ opacity: 1
88
+ });
89
+ progress.offsetWidth; /* Repaint */
90
+
91
+ setTimeout(function() {
92
+ css(progress, {
93
+ transition: 'all ' + speed + 'ms linear',
94
+ opacity: 0
95
+ });
96
+ setTimeout(function() {
97
+ NProgress.remove();
98
+ next();
99
+ }, speed);
100
+ }, speed);
101
+ } else {
102
+ setTimeout(next, speed);
103
+ }
104
+ });
105
+
106
+ return this;
107
+ };
108
+
109
+ NProgress.isStarted = function() {
110
+ return typeof NProgress.status === 'number';
111
+ };
112
+
113
+ /**
114
+ * Shows the progress bar.
115
+ * This is the same as setting the status to 0%, except that it doesn't go backwards.
116
+ *
117
+ * NProgress.start();
118
+ *
119
+ */
120
+ NProgress.start = function() {
121
+ if (!NProgress.status) NProgress.set(0);
122
+
123
+ var work = function() {
124
+ setTimeout(function() {
125
+ if (!NProgress.status) return;
126
+ NProgress.trickle();
127
+ work();
128
+ }, Settings.trickleSpeed);
129
+ };
130
+
131
+ if (Settings.trickle) work();
132
+
133
+ return this;
134
+ };
135
+
136
+ /**
137
+ * Hides the progress bar.
138
+ * This is the *sort of* the same as setting the status to 100%, with the
139
+ * difference being `done()` makes some placebo effect of some realistic motion.
140
+ *
141
+ * NProgress.done();
142
+ *
143
+ * If `true` is passed, it will show the progress bar even if its hidden.
144
+ *
145
+ * NProgress.done(true);
146
+ */
147
+
148
+ NProgress.done = function(force) {
149
+ if (!force && !NProgress.status) return this;
150
+
151
+ return NProgress.inc(0.3 + 0.5 * Math.random()).set(1);
152
+ };
153
+
154
+ /**
155
+ * Increments by a random amount.
156
+ */
157
+
158
+ NProgress.inc = function(amount) {
159
+ var n = NProgress.status;
160
+
161
+ if (!n) {
162
+ return NProgress.start();
163
+ } else if(n > 1) {
164
+ return;
165
+ } else {
166
+ if (typeof amount !== 'number') {
167
+ if (n >= 0 && n < 0.25) {
168
+ // Start out between 3 - 6% increments
169
+ amount = (Math.random() * (5 - 3 + 1) + 3) / 100;
170
+ } else if (n >= 0.25 && n < 0.65) {
171
+ // increment between 0 - 3%
172
+ amount = (Math.random() * 3) / 100;
173
+ } else if (n >= 0.65 && n < 0.9) {
174
+ // increment between 0 - 2%
175
+ amount = (Math.random() * 2) / 100;
176
+ } else if (n >= 0.9 && n < 0.99) {
177
+ // finally, increment it .5 %
178
+ amount = 0.005;
179
+ } else {
180
+ // after 99%, don't increment:
181
+ amount = 0;
182
+ }
183
+ }
184
+
185
+ n = clamp(n + amount, 0, 0.994);
186
+ return NProgress.set(n);
187
+ }
188
+ };
189
+
190
+ NProgress.trickle = function() {
191
+ return NProgress.inc();
192
+ };
193
+
194
+ /**
195
+ * Waits for all supplied jQuery promises and
196
+ * increases the progress as the promises resolve.
197
+ *
198
+ * @param $promise jQUery Promise
199
+ */
200
+ (function() {
201
+ var initial = 0, current = 0;
202
+
203
+ NProgress.promise = function($promise) {
204
+ if (!$promise || $promise.state() === "resolved") {
205
+ return this;
206
+ }
207
+
208
+ if (current === 0) {
209
+ NProgress.start();
210
+ }
211
+
212
+ initial++;
213
+ current++;
214
+
215
+ $promise.always(function() {
216
+ current--;
217
+ if (current === 0) {
218
+ initial = 0;
219
+ NProgress.done();
220
+ } else {
221
+ NProgress.set((initial - current) / initial);
222
+ }
223
+ });
224
+
225
+ return this;
226
+ };
227
+
228
+ })();
229
+
230
+ /**
231
+ * (Internal) renders the progress bar markup based on the `template`
232
+ * setting.
233
+ */
234
+
235
+ NProgress.render = function(fromStart) {
236
+ if (NProgress.isRendered()) return document.getElementById('nprogress');
237
+
238
+ addClass(document.documentElement, 'nprogress-busy');
239
+
240
+ var progress = document.createElement('div');
241
+ progress.id = 'nprogress';
242
+ progress.innerHTML = Settings.template;
243
+
244
+ var bar = progress.querySelector(Settings.barSelector),
245
+ perc = fromStart ? '-100' : toBarPerc(NProgress.status || 0),
246
+ parent = document.querySelector(Settings.parent),
247
+ spinner;
248
+
249
+ css(bar, {
250
+ transition: 'all 0 linear',
251
+ transform: 'translate3d(' + perc + '%,0,0)'
252
+ });
253
+
254
+ if (!Settings.showSpinner) {
255
+ spinner = progress.querySelector(Settings.spinnerSelector);
256
+ spinner && removeElement(spinner);
257
+ }
258
+
259
+ if (parent != document.body) {
260
+ addClass(parent, 'nprogress-custom-parent');
261
+ }
262
+
263
+ parent.appendChild(progress);
264
+ return progress;
265
+ };
266
+
267
+ /**
268
+ * Removes the element. Opposite of render().
269
+ */
270
+
271
+ NProgress.remove = function() {
272
+ removeClass(document.documentElement, 'nprogress-busy');
273
+ removeClass(document.querySelector(Settings.parent), 'nprogress-custom-parent');
274
+ var progress = document.getElementById('nprogress');
275
+ progress && removeElement(progress);
276
+ };
277
+
278
+ /**
279
+ * Checks if the progress bar is rendered.
280
+ */
281
+
282
+ NProgress.isRendered = function() {
283
+ return !!document.getElementById('nprogress');
284
+ };
285
+
286
+ /**
287
+ * Determine which positioning CSS rule to use.
288
+ */
289
+
290
+ NProgress.getPositioningCSS = function() {
291
+ // Sniff on document.body.style
292
+ var bodyStyle = document.body.style;
293
+
294
+ // Sniff prefixes
295
+ var vendorPrefix = ('WebkitTransform' in bodyStyle) ? 'Webkit' :
296
+ ('MozTransform' in bodyStyle) ? 'Moz' :
297
+ ('msTransform' in bodyStyle) ? 'ms' :
298
+ ('OTransform' in bodyStyle) ? 'O' : '';
299
+
300
+ if (vendorPrefix + 'Perspective' in bodyStyle) {
301
+ // Modern browsers with 3D support, e.g. Webkit, IE10
302
+ return 'translate3d';
303
+ } else if (vendorPrefix + 'Transform' in bodyStyle) {
304
+ // Browsers without 3D support, e.g. IE9
305
+ return 'translate';
306
+ } else {
307
+ // Browsers without translate() support, e.g. IE7-8
308
+ return 'margin';
309
+ }
310
+ };
311
+
312
+ /**
313
+ * Helpers
314
+ */
315
+
316
+ function clamp(n, min, max) {
317
+ if (n < min) return min;
318
+ if (n > max) return max;
319
+ return n;
320
+ }
321
+
322
+ /**
323
+ * (Internal) converts a percentage (`0..1`) to a bar translateX
324
+ * percentage (`-100%..0%`).
325
+ */
326
+
327
+ function toBarPerc(n) {
328
+ return (-1 + n) * 100;
329
+ }
330
+
331
+
332
+ /**
333
+ * (Internal) returns the correct CSS for changing the bar's
334
+ * position given an n percentage, and speed and ease from Settings
335
+ */
336
+
337
+ function barPositionCSS(n, speed, ease) {
338
+ var barCSS;
339
+
340
+ if (Settings.positionUsing === 'translate3d') {
341
+ barCSS = { transform: 'translate3d('+toBarPerc(n)+'%,0,0)' };
342
+ } else if (Settings.positionUsing === 'translate') {
343
+ barCSS = { transform: 'translate('+toBarPerc(n)+'%,0)' };
344
+ } else {
345
+ barCSS = { 'margin-left': toBarPerc(n)+'%' };
346
+ }
347
+
348
+ barCSS.transition = 'all '+speed+'ms '+ease;
349
+
350
+ return barCSS;
351
+ }
352
+
353
+ /**
354
+ * (Internal) Queues a function to be executed.
355
+ */
356
+
357
+ var queue = (function() {
358
+ var pending = [];
359
+
360
+ function next() {
361
+ var fn = pending.shift();
362
+ if (fn) {
363
+ fn(next);
364
+ }
365
+ }
366
+
367
+ return function(fn) {
368
+ pending.push(fn);
369
+ if (pending.length == 1) next();
370
+ };
371
+ })();
372
+
373
+ /**
374
+ * (Internal) Applies css properties to an element, similar to the jQuery
375
+ * css method.
376
+ *
377
+ * While this helper does assist with vendor prefixed property names, it
378
+ * does not perform any manipulation of values prior to setting styles.
379
+ */
380
+
381
+ var css = (function() {
382
+ var cssPrefixes = [ 'Webkit', 'O', 'Moz', 'ms' ],
383
+ cssProps = {};
384
+
385
+ function camelCase(string) {
386
+ return string.replace(/^-ms-/, 'ms-').replace(/-([\da-z])/gi, function(match, letter) {
387
+ return letter.toUpperCase();
388
+ });
389
+ }
390
+
391
+ function getVendorProp(name) {
392
+ var style = document.body.style;
393
+ if (name in style) return name;
394
+
395
+ var i = cssPrefixes.length,
396
+ capName = name.charAt(0).toUpperCase() + name.slice(1),
397
+ vendorName;
398
+ while (i--) {
399
+ vendorName = cssPrefixes[i] + capName;
400
+ if (vendorName in style) return vendorName;
401
+ }
402
+
403
+ return name;
404
+ }
405
+
406
+ function getStyleProp(name) {
407
+ name = camelCase(name);
408
+ return cssProps[name] || (cssProps[name] = getVendorProp(name));
409
+ }
410
+
411
+ function applyCss(element, prop, value) {
412
+ prop = getStyleProp(prop);
413
+ element.style[prop] = value;
414
+ }
415
+
416
+ return function(element, properties) {
417
+ var args = arguments,
418
+ prop,
419
+ value;
420
+
421
+ if (args.length == 2) {
422
+ for (prop in properties) {
423
+ value = properties[prop];
424
+ if (value !== undefined && properties.hasOwnProperty(prop)) applyCss(element, prop, value);
425
+ }
426
+ } else {
427
+ applyCss(element, args[1], args[2]);
428
+ }
429
+ }
430
+ })();
431
+
432
+ /**
433
+ * (Internal) Determines if an element or space separated list of class names contains a class name.
434
+ */
435
+
436
+ function hasClass(element, name) {
437
+ var list = typeof element == 'string' ? element : classList(element);
438
+ return list.indexOf(' ' + name + ' ') >= 0;
439
+ }
440
+
441
+ /**
442
+ * (Internal) Adds a class to an element.
443
+ */
444
+
445
+ function addClass(element, name) {
446
+ var oldList = classList(element),
447
+ newList = oldList + name;
448
+
449
+ if (hasClass(oldList, name)) return;
450
+
451
+ // Trim the opening space.
452
+ element.className = newList.substring(1);
453
+ }
454
+
455
+ /**
456
+ * (Internal) Removes a class from an element.
457
+ */
458
+
459
+ function removeClass(element, name) {
460
+ var oldList = classList(element),
461
+ newList;
462
+
463
+ if (!hasClass(element, name)) return;
464
+
465
+ // Replace the class name.
466
+ newList = oldList.replace(' ' + name + ' ', ' ');
467
+
468
+ // Trim the opening and closing spaces.
469
+ element.className = newList.substring(1, newList.length - 1);
470
+ }
471
+
472
+ /**
473
+ * (Internal) Gets a space separated list of the class names on the element.
474
+ * The list is wrapped with a single space on each end to facilitate finding
475
+ * matches within the list.
476
+ */
477
+
478
+ function classList(element) {
479
+ return (' ' + (element && element.className || '') + ' ').replace(/\s+/gi, ' ');
480
+ }
481
+
482
+ /**
483
+ * (Internal) Removes an element from the DOM.
484
+ */
485
+
486
+ function removeElement(element) {
487
+ element && element.parentNode && element.parentNode.removeChild(element);
488
+ }
489
+
490
+ return NProgress;
491
+ });