ohsnap-rails 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d95eed1dea9ffbc82f9ed1c25ef17beea944f332
4
- data.tar.gz: f1d95145527848bc555709dc847f6de5554dd019
3
+ metadata.gz: a6106a98633b12a09570fadefd08f27002f00e64
4
+ data.tar.gz: cf6daf70d733e3699bf2fd0be836cc9c561c18ad
5
5
  SHA512:
6
- metadata.gz: 7ff1dcdbad751128fc4785382a0e1efe59544a8eb36c1aa0e752fbff5f67227613d8fb429d69f131d6edbb1a1275eb2bee56dbafeece052ad46d63f944540615
7
- data.tar.gz: 7668ba439e4c06617bd9a08a1b121efbb886738c50b743177fc879e0282baa6f9a89fe9f3aca2064e464aa541bb291f4d01dc0a1b2aa79421f0316d074ff8b7e
6
+ metadata.gz: 153dc53f32d8aa533b94a885da1541a7afa7048d004397da559422258a5054f57388ac30b54fa4125242ad03f7c528fbda526b7ab069e65d1146353dc592845a
7
+ data.tar.gz: 7102bd382e2f069ecd7b754a4f4e45afb8ebb6abfc111ce649fb822b2ae9470867878170342430ddceee7ef580ce9cd2ced663ca5958a2c3b9bc24e3b92601d6
data/.DS_Store CHANGED
Binary file
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Ohsnap
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/ohsnap-rails.svg)](https://badge.fury.io/rb/ohsnap-rails)
4
+
3
5
  A ruby gem for ohsnap.js [library by justin domingue](https://github.com/justindomingue)
4
6
 
5
7
  A simple notification jQuery/Zepto library designed to be used in mobile apps
@@ -1,5 +1,5 @@
1
1
  module Ohsnap
2
2
  module Rails
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -4,27 +4,45 @@
4
4
  *
5
5
  * author: Justin Domingue
6
6
  * date: september 18, 2015
7
- * version: 0.1.4
7
+ * version: 1.0.0
8
8
  * copyright - nice copyright over here
9
9
  */
10
10
 
11
11
  /* Shows a toast on the page
12
12
  * Params:
13
13
  * text: text to show
14
- * color: color of the toast. one of red, green, blue, orange, yellow or custom
14
+ * options: object that can override the following options
15
+ * color: alert will have class 'alert-color'. Default null
16
+ * icon: class of the icon to show before the alert. Default null
17
+ * duration: duration of the notification in ms. Default 5000ms
18
+ * container-id: id of the alert container. Default 'ohsnap'
19
+ * fade-duration: duration of the fade in/out of the alerts. Default 'fast'
15
20
  */
16
- function ohSnap(text, color, icon) {
17
- var icon_markup = "",
18
- html,
19
- time = '5000',
20
- $container = $('#ohsnap');
21
-
22
- if (icon) {
23
- icon_markup = "<span class='" + icon + "'></span> ";
21
+ function ohSnap(text, options) {
22
+ var defaultOptions = {
23
+ 'color' : null, // color is CSS class `alert-color`
24
+ 'icon' : null, // class of the icon to show before the alert text
25
+ 'duration' : '5000', // duration of the notification in ms
26
+ 'container-id': 'ohsnap', // id of the alert container
27
+ 'fade-duration': 'fast', // duration of the fade in/out of the alerts. fast, slow or integer in ms
28
+ }
29
+
30
+ options = (typeof options == 'object') ? $.extend(defaultOptions, options) : defaultOptions;
31
+
32
+ var $container = $('#'+options['container-id']),
33
+ icon_markup = "",
34
+ color_markup = "";
35
+
36
+ if (options.icon) {
37
+ icon_markup = "<span class='" + options.icon + "'></span> ";
38
+ }
39
+
40
+ if (options.color) {
41
+ color_markup = 'alert-' + options.color;
24
42
  }
25
43
 
26
44
  // Generate the HTML
27
- html = $('<div class="alert alert-' + color + '">' + icon_markup + text + '</div>').fadeIn('fast');
45
+ var html = $('<div class="alert ' + color_markup + '">' + icon_markup + text + '</div>').fadeIn(options['fade-duration']);
28
46
 
29
47
  // Append the label to the container
30
48
  $container.append(html);
@@ -34,23 +52,33 @@ function ohSnap(text, color, icon) {
34
52
  ohSnapX($(this));
35
53
  });
36
54
 
37
- // After 'time' seconds, the animation fades out
55
+ // After 'duration' seconds, the animation fades out
38
56
  setTimeout(function() {
39
57
  ohSnapX(html);
40
- }, time);
58
+ }, options.duration);
41
59
  }
42
60
 
43
- function ohSnapX(element) {
44
- // Called without argument, the function removes all alerts
45
- // element must be a jQuery object
61
+ /* Removes a toast from the page
62
+ * params:
63
+ * Called without arguments, the function removes all alerts
64
+ * element: a jQuery object to remove
65
+ * options:
66
+ * duration: duration of the alert fade out - 'fast', 'slow' or time in ms. Default 'fast'
67
+ */
68
+ function ohSnapX(element, options) {
69
+ defaultOptions = {
70
+ 'duration': 'fast'
71
+ }
72
+
73
+ options = (typeof options == 'object') ? $.extend(defaultOptions, options) : defaultOptions;
46
74
 
47
75
  if (typeof element !== "undefined") {
48
- element.fadeOut('fast', function() {
76
+ element.fadeOut(options.duration, function() {
49
77
  $(this).remove();
50
78
  });
51
79
  } else {
52
- $('.alert').fadeOut('fast', function() {
80
+ $('.alert').fadeOut(options.duration, function() {
53
81
  $(this).remove();
54
82
  });
55
83
  }
56
- }
84
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohsnap-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rahul Lakhaney
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-02 00:00:00.000000000 Z
11
+ date: 2016-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,3 +85,4 @@ signing_key:
85
85
  specification_version: 4
86
86
  summary: Ruby gem for ohsnap.
87
87
  test_files: []
88
+ has_rdoc: