alertifyjs-rails 0.1.3 → 0.1.4

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.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # alertifyjs-rails
2
2
 
3
- This gem provides [alertify.js](http://alertifyjs.com/) (v0.6.1) for Rails.
3
+ This gem provides [alertify.js](http://alertifyjs.com/) (v0.7) for Rails.
4
4
 
5
5
 
6
6
  ## Installation
@@ -43,6 +43,8 @@ In order to get the CSS, add the following line to `app/assets/stylesheets/appli
43
43
 
44
44
  flash helper, add the following line in layout
45
45
 
46
- ```html
47
- <div id="flash_messages"><%= alertify_flash %></div>
46
+ ```html
47
+ <head>
48
+ <%= alertify_flash %>
49
+ </head>
48
50
  ```
@@ -1,6 +1,6 @@
1
1
  module Alertifyjs #:nodoc:
2
2
  module Rails #:nodoc:
3
- VERSION = "0.1.3"
4
- ALERTIFYJS_VERSION = "0.6.1"
3
+ VERSION = "0.1.4"
4
+ ALERTIFYJS_VERSION = "0.7.0"
5
5
  end
6
6
  end
@@ -7,7 +7,7 @@
7
7
  * @license MIT <http://opensource.org/licenses/mit-license.php>
8
8
  * @link http://alertifyjs.com
9
9
  * @module AlertifyJS
10
- * @version 0.6.1
10
+ * @version 0.7.0
11
11
  */
12
12
  ( function ( window ) {
13
13
  'use strict';
@@ -61,6 +61,9 @@
61
61
  }
62
62
  };
63
63
 
64
+ //holds open dialogs instances
65
+ var openDialogs = [];
66
+
64
67
  /**
65
68
  * [Helper] Adds the specified class(es) to the element.
66
69
  *
@@ -239,9 +242,7 @@
239
242
  * @return {Object} base dialog prototype
240
243
  */
241
244
  var dialog = (function () {
242
- //holds open dialogs instances
243
- var openInstances = [],
244
- //holds the list of used keys.
245
+ var //holds the list of used keys.
245
246
  usedKeys = [],
246
247
  //dummy variable, used to trigger dom reflow.
247
248
  reflow = null,
@@ -487,10 +488,9 @@
487
488
  if(typeof instance.build === 'function'){
488
489
  instance.build();
489
490
  }
490
-
491
491
  }
492
492
 
493
- //add to DOM tree.
493
+ //add to the end of the DOM tree.
494
494
  document.body.appendChild(instance.elements.root);
495
495
  }
496
496
 
@@ -500,8 +500,8 @@
500
500
  */
501
501
  function ensureNoOverflow(){
502
502
  var requiresNoOverflow = 0;
503
- for(var x=0;x<openInstances.length;x+=1){
504
- var instance = openInstances[x];
503
+ for(var x=0;x<openDialogs.length;x+=1){
504
+ var instance = openDialogs[x];
505
505
  if(instance.isModal() || instance.isMaximized()){
506
506
  requiresNoOverflow+=1;
507
507
  }
@@ -579,9 +579,9 @@
579
579
  function bringToFront(event, instance){
580
580
 
581
581
  // Do not bring to front if preceeded by an open modal
582
- var index = openInstances.indexOf(instance);
583
- for(var x=index+1;x<openInstances.length;x+=1){
584
- if(openInstances[x].isModal()){
582
+ var index = openDialogs.indexOf(instance);
583
+ for(var x=index+1;x<openDialogs.length;x+=1){
584
+ if(openDialogs[x].isModal()){
585
585
  return;
586
586
  }
587
587
  }
@@ -589,6 +589,9 @@
589
589
  // Bring to front by making it the last child.
590
590
  if(document.body.lastChild !== instance.elements.root){
591
591
  document.body.appendChild(instance.elements.root);
592
+ //also make sure its at the end of the list
593
+ openDialogs.splice(openDialogs.indexOf(instance),1);
594
+ openDialogs.push(instance);
592
595
  setFocus(instance);
593
596
  }
594
597
 
@@ -1049,7 +1052,7 @@
1049
1052
  cancelKeyup = false;
1050
1053
  return;
1051
1054
  }
1052
- var instance = openInstances[openInstances.length - 1];
1055
+ var instance = openDialogs[openDialogs.length - 1];
1053
1056
  var keyCode = event.keyCode;
1054
1057
  if (usedKeys.indexOf(keyCode) > -1) {
1055
1058
  triggerCallback(instance, function (button) {
@@ -1067,7 +1070,7 @@
1067
1070
  * @return {undefined}
1068
1071
  */
1069
1072
  function keydownHandler(event) {
1070
- var instance = openInstances[openInstances.length - 1];
1073
+ var instance = openDialogs[openDialogs.length - 1];
1071
1074
  var keyCode = event.keyCode;
1072
1075
  if (keyCode < keys.F12 + 1 && keyCode > keys.F1 - 1 && usedKeys.indexOf(keyCode) > -1) {
1073
1076
  event.preventDefault();
@@ -1125,9 +1128,9 @@
1125
1128
 
1126
1129
  // should work on last modal if triggered from document.body
1127
1130
  if (!instance) {
1128
- for (var x = openInstances.length - 1; x > -1; x -= 1) {
1129
- if (openInstances[x].isModal()) {
1130
- instance = openInstances[x];
1131
+ for (var x = openDialogs.length - 1; x > -1; x -= 1) {
1132
+ if (openDialogs[x].isModal()) {
1133
+ instance = openDialogs[x];
1131
1134
  break;
1132
1135
  }
1133
1136
  }
@@ -1574,8 +1577,8 @@
1574
1577
  * @return {undefined}
1575
1578
  */
1576
1579
  function windowResize(/*event*/) {
1577
- for (var x = 0; x < openInstances.length; x += 1) {
1578
- var instance = openInstances[x];
1580
+ for (var x = 0; x < openDialogs.length; x += 1) {
1581
+ var instance = openDialogs[x];
1579
1582
  resetMove(instance);
1580
1583
  resetResize(instance);
1581
1584
  }
@@ -1589,7 +1592,7 @@
1589
1592
  */
1590
1593
  function bindEvents(instance) {
1591
1594
  // if first dialog, hook body handlers
1592
- if (openInstances.length === 1) {
1595
+ if (openDialogs.length === 1) {
1593
1596
  //global
1594
1597
  on(window, 'resize', windowResize);
1595
1598
  on(document.body, 'keyup', keyupHandler);
@@ -1644,7 +1647,7 @@
1644
1647
  */
1645
1648
  function unbindEvents(instance) {
1646
1649
  // if last dialog, remove body handlers
1647
- if (openInstances.length === 1) {
1650
+ if (openDialogs.length === 1) {
1648
1651
  //global
1649
1652
  off(window, 'resize', windowResize);
1650
1653
  off(document.body, 'keyup', keyupHandler);
@@ -1920,7 +1923,7 @@
1920
1923
 
1921
1924
  // add to open dialogs
1922
1925
  this.__internal.isOpen = true;
1923
- openInstances.push(this);
1926
+ openDialogs.push(this);
1924
1927
 
1925
1928
  // save last focused element
1926
1929
  if(alertify.defaults.maintainFocus){
@@ -2018,7 +2021,7 @@
2018
2021
  }
2019
2022
 
2020
2023
  //remove from open dialogs
2021
- openInstances.splice(openInstances.indexOf(this),1);
2024
+ openDialogs.splice(openDialogs.indexOf(this),1);
2022
2025
  this.__internal.isOpen = false;
2023
2026
 
2024
2027
  ensureNoOverflow();
@@ -2026,11 +2029,21 @@
2026
2029
  }
2027
2030
  return this;
2028
2031
  },
2032
+ /**
2033
+ * Close all open dialogs except this.
2034
+ *
2035
+ * @return {undefined}
2036
+ */
2037
+ closeOthers:function(){
2038
+ alertify.closeAll(this);
2039
+ return this;
2040
+ }
2029
2041
  };
2030
2042
  } () );
2031
2043
  var notifier = (function () {
2032
2044
  var reflow,
2033
2045
  element,
2046
+ openInstances = [],
2034
2047
  classes = {
2035
2048
  base: 'alertify-notifier',
2036
2049
  message: 'ajs-message',
@@ -2061,7 +2074,15 @@
2061
2074
  document.body.appendChild(element);
2062
2075
  }
2063
2076
  }
2064
-
2077
+
2078
+ function pushInstance(instance) {
2079
+ instance.__internal.pushed = true;
2080
+ openInstances.push(instance);
2081
+ }
2082
+ function popInstance(instance) {
2083
+ openInstances.splice(openInstances.indexOf(instance), 1);
2084
+ instance.__internal.pushed = false;
2085
+ }
2065
2086
  /**
2066
2087
  * Helper: update the notifier instance position
2067
2088
  *
@@ -2139,7 +2160,7 @@
2139
2160
  push: function (_content, _wait) {
2140
2161
  if (!this.__internal.pushed) {
2141
2162
 
2142
- this.__internal.pushed = true;
2163
+ pushInstance(this);
2143
2164
  clearTimers(this);
2144
2165
 
2145
2166
  var content, wait;
@@ -2211,7 +2232,7 @@
2211
2232
  this.callback.call(this, clicked);
2212
2233
  }
2213
2234
  }
2214
- this.__internal.pushed = false;
2235
+ popInstance(this);
2215
2236
  }
2216
2237
  }
2217
2238
  return this;
@@ -2242,6 +2263,14 @@
2242
2263
  this.element.appendChild(content);
2243
2264
  }
2244
2265
  return this;
2266
+ },
2267
+ /*
2268
+ * Dismisses all open notifications except this.
2269
+ *
2270
+ */
2271
+ dismissOthers: function () {
2272
+ notifier.dismissAll(this);
2273
+ return this;
2245
2274
  }
2246
2275
  });
2247
2276
  }
@@ -2305,6 +2334,21 @@
2305
2334
  var div = document.createElement('div');
2306
2335
  div.className = classes.message + ((typeof type === 'string' && type !== '') ? ' ajs-' + type : '');
2307
2336
  return create(div, callback);
2337
+ },
2338
+ /**
2339
+ * Dismisses all open notifications.
2340
+ *
2341
+ * @param {Object} excpet [optional] The notification object to exclude from dismissal.
2342
+ *
2343
+ */
2344
+ dismissAll: function (except) {
2345
+ var clone = openInstances.slice(0);
2346
+ for (var x = 0; x < clone.length; x += 1) {
2347
+ var instance = clone[x];
2348
+ if (except === undefined || except !== instance) {
2349
+ instance.dismiss();
2350
+ }
2351
+ }
2308
2352
  }
2309
2353
  };
2310
2354
  })();
@@ -2450,6 +2494,22 @@
2450
2494
  };
2451
2495
  }
2452
2496
  },
2497
+ /**
2498
+ * Close all open dialogs.
2499
+ *
2500
+ * @param {Object} excpet [optional] The dialog object to exclude from closing.
2501
+ *
2502
+ * @return {undefined}
2503
+ */
2504
+ closeAll: function (except) {
2505
+ var clone = openDialogs.slice(0);
2506
+ for (var x = 0; x < clone.length; x += 1) {
2507
+ var instance = clone[x];
2508
+ if (except === undefined || except !== instance) {
2509
+ instance.close();
2510
+ }
2511
+ }
2512
+ },
2453
2513
  /**
2454
2514
  * Gets or Sets dialog settings/options. if the dialog is transient, this call does nothing.
2455
2515
  *
@@ -2544,8 +2604,15 @@
2544
2604
  */
2545
2605
  warning: function (message, wait, callback) {
2546
2606
  return notifier.create('warning', callback).push(message, wait);
2607
+ },
2608
+ /**
2609
+ * Dismisses all open notifications
2610
+ *
2611
+ * @return {undefined}
2612
+ */
2613
+ dismissAll: function () {
2614
+ notifier.dismissAll();
2547
2615
  }
2548
-
2549
2616
  };
2550
2617
  }
2551
2618
  var alertify = new Alertify();
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alertifyjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-24 00:00:00.000000000 Z
12
+ date: 2014-10-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Use Alertify.js (alertifyjs.com) with Rails 3 and 4
15
15
  email: