lazybox 1.0.2 → 1.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 14ba4ad8d9f02ddba95764fc533c30d8fad8d2da
4
+ data.tar.gz: 3df0f542f3d540f5143bc602aa4d84d16b856350
5
+ SHA512:
6
+ metadata.gz: 4e79db94d9770028368d53b3533a3b58866da7c52b99f0cdf3f4215760b7aede668bfc2ebe9ed189864d67bd34de00f2afee46d8caa13b9973e8df184dbd92cc
7
+ data.tar.gz: 9f6fa44ffb06c4c6b77a124f080667572862198a62427c1ed8fcab842a775ce2a1734fc849526df74cdb8e6e8098012bc258eb61e11d101ab7f2a3574d4ccc99
data/README.md CHANGED
@@ -12,6 +12,11 @@ LazyBox implemented using only css and jquery without images.
12
12
  This is high perfomance modal dialogs. All unpacked files take only 5 kb.
13
13
  This is simplest solution for popup windows and custom confirmation dialogs.
14
14
 
15
+ Upgrade to 1.1.0
16
+ -
17
+
18
+ After you upgrate the lazybox to 1.1.0 version you should add `render_lazybox` helper to your layout.
19
+
15
20
  Installing
16
21
  ----------
17
22
 
@@ -23,10 +28,46 @@ gem 'lazybox'
23
28
 
24
29
  Then run `bundle install` to update your application's bundle.
25
30
 
31
+ Add to your layout helper `render_lazybox`:
32
+
33
+ ```slim
34
+ ...
35
+ render_lazybox
36
+ body
37
+ html
38
+ ```
39
+
26
40
  Include in your `application.css`:
27
41
 
28
- ```css
29
- *= require lazybox
42
+ ```scss
43
+ @include 'lazybox';
44
+ ```
45
+
46
+ There are a lot of variables you can customise:
47
+
48
+ ```scss
49
+ $lazy-transition: .3s;
50
+ $lazy-z-index: 1000;
51
+ $lazy-overlay: rgba(black, .7);
52
+ $lazy-bg: white;
53
+ $lazy-border: 1px solid #ccc;
54
+ $lazy-shadow: 0 1px 5px #333;
55
+ $lazy-padding: 20px;
56
+ $lazy-start: scale(.7);
57
+ $lazy-end: scale(1);
58
+ $lazy-close: '×';
59
+ ```
60
+
61
+ Use `$lazy-start` and `$lazy-end` to contol the animation, `$lazy-close` to set close image.
62
+
63
+ You should set the variable before you include the `lazybox`
64
+
65
+ ```scss
66
+ $lazy-start: rotate(180);
67
+ $lazy-end: rotate(0);
68
+ $lazy-close: url(url-to-image);
69
+
70
+ @include 'lazybox';
30
71
  ```
31
72
 
32
73
  And in `application.js`:
@@ -90,7 +131,7 @@ $.lazybox.settings = {cancelClass: "button gray", submitClass: 'button gray', ov
90
131
  or instance settings
91
132
 
92
133
  ```javascript
93
- $.lazybox("<div>It works!</div>",{onTop: true, opacity: 0.7, modal: false})
134
+ $.lazybox("<div>It works!</div>",{modal: true, close: false})
94
135
  ```
95
136
 
96
137
  ###Images
@@ -104,7 +145,7 @@ Include in your `app/assets/javascripts/application.js`:
104
145
  $(document).ready(function() {
105
146
  $('a[rel*=lazybox]').lazybox();
106
147
  // or with options
107
- $('a[rel*=lazybox]').lazybox({overlay: true, esc: true, close: true, modal: true, klass: 'class'});
148
+ $('a[rel*=lazybox]').lazybox({esc: true, close: true, modal: true, klass: 'class'});
108
149
  });
109
150
  ```
110
151
 
@@ -117,33 +158,6 @@ If there are more than one link to image you can click on image in the lazybox t
117
158
  = image_tag image2.url, height: 100
118
159
  ```
119
160
 
120
- Custom close image
121
- ------------------
122
-
123
- Set 'closeImg' option to true.
124
-
125
- `application.js`:
126
-
127
- ```javascript
128
- $(document).ready(function() {
129
- $('.images a').lazybox({closeImg: true});
130
- });
131
- ```
132
-
133
- Style your close:
134
-
135
- `application.css`
136
-
137
- ```css
138
- #lazybox_close.img {
139
- background: url('close.png') no-repeat;
140
- width: 32px;
141
- height: 32px;
142
- top: -17px;
143
- right: -17px;
144
- }
145
- ```
146
-
147
161
  We can use lazybox with `turbolinks` to show page loading spinner:
148
162
 
149
163
  ```coffeescript
@@ -174,14 +188,25 @@ Turbolinks spinner
174
188
  }
175
189
  ```
176
190
 
191
+ Display on page load
192
+ -
193
+
194
+ You can show lazybox with some content on page load. To do this you should `content_for` helper:
195
+
196
+ `index.haml`
197
+
198
+ ```haml
199
+ content_for :lazybox do
200
+ This text appears on page load
201
+ ```
202
+
203
+
177
204
  Options
178
205
  -------
179
206
 
180
207
  esc: true|false //default true. Close lazybox on esc press
181
208
  close: true|false //default true. Show close lazybox button
182
209
  modal: true|false //default true. Close lazybox on overlay click
183
- closeImg: true|false //default false. Use image for close link
184
- onTop: true|false //default false. Show lazybox on top instead of on center. It will use slide animation instead of fade.
185
210
  klass: 'class' Set class for lazybox. <div id='lazybox' class='class'>...</div>
186
211
  //confirmation options
187
212
  cancelText: //default 'Cancel'. Cancel button text
@@ -198,7 +223,7 @@ Events
198
223
  Browser Compatibility
199
224
  ---------------------
200
225
 
201
- IE10 +
226
+ IE9 +
202
227
  Chrome
203
228
  Firefox
204
229
  Opera
@@ -3,15 +3,12 @@
3
3
  esc: true
4
4
  close: true
5
5
  modal: false
6
- onTop: false
6
+ klass: ''
7
7
  cancelText: 'Cancel'
8
8
  cancelClass: 'btn'
9
9
  submitText: 'Ok'
10
10
  submitClass: 'btn'
11
11
 
12
- html = "<div id='lazy_overlay'><div id='lazybox'><a id='lazy_close' href=''></a><div id='lazy_body'></div></div></div>"
13
- box = overlay = close = null
14
-
15
12
  $.lazybox = (html, options) -> $.lazybox.show(html, options)
16
13
 
17
14
  $.extend $.lazybox,
@@ -20,23 +17,22 @@
20
17
  show: (content, options) ->
21
18
  options = init(options)
22
19
  $('#lazy_body').html(content)
23
- setTimeout (-> overlay.addClass('visible')), 1
24
- close.addClass('visible') if options.close && !box.hasClass('visible')
20
+ $('#lazy_overlay').addClass('active')
25
21
 
26
- close: -> overlay.removeClass('visible') if overlay
22
+ close: -> $('#lazy_overlay').removeClass()
27
23
 
28
24
  confirm: (element) ->
29
25
  options = $.extend defaults, $.lazybox.settings
30
26
  message = element.data('confirm')
31
- return true if !message
27
+ return true unless message
32
28
  $.lazybox.show('<p>'+message+'</p><div class="lazy_buttons"></div>', { klass: 'confirm' })
33
29
  element.clone().attr('class', options.submitClass).removeAttr('data-confirm').text(options.submitText).appendTo('.lazy_buttons')
34
30
  $('.lazy_buttons').append(' ')
35
- $('<a>', { href: '', text: options.cancelText, 'class': 'cancel ' + options.cancelClass }).appendTo('.lazy_buttons')
31
+ $('<button>', { text: options.cancelText, 'class': 'cancel ' + options.cancelClass }).appendTo('.lazy_buttons')
36
32
  return false
37
33
 
38
34
  $.fn.lazybox = (options) ->
39
- $(document).on 'click', this.selector, (e) ->
35
+ $(document).on 'click', @.selector, (e) ->
40
36
  a = $(e.currentTarget)
41
37
  href = a.attr('href')
42
38
  imagesRegexp = new RegExp('\\.(png|jpg|jpeg|gif)(\\?.*)?$', 'i')
@@ -53,25 +49,15 @@
53
49
 
54
50
  init = (options) ->
55
51
  options = $.extend {}, defaults, $.lazybox.settings, options
56
- $('body:not(:has(#lazybox))').append(html)
57
- box = $('#lazybox')
58
- overlay = $('#lazy_overlay')
59
- close = $('#lazy_close')
60
- if options.klass then box.attr('class', options.klass) else box.removeClass()
61
- if options.onTop then overlay.addClass('top') else overlay.removeClass('top')
62
- if options.close
63
- if options.closeImg then close.addClass('img') else close.removeClass('img')
64
- else
65
- close.removeClass()
66
- if options.modal
67
- overlay.unbind()
68
- else
69
- overlay.bind 'click', (e) ->
70
- $.lazybox.close() if e.target == @
71
- $(document).keyup (e) -> $.lazybox.close() if e.keyCode == 27 and options.esc
72
- box.on 'click', '#lazy_close, .lazy_buttons a.cancel', (e) ->
73
- $.lazybox.close()
74
- e.preventDefault()
52
+ $('#lazybox').attr('class', options.klass)
53
+ $('#lazy_close').toggleClass('visible', options.close)
54
+ $('#lazy_overlay').one 'click', $.lazybox.close unless options.modal
55
+ $(document).on 'keyup.lazy', (e) ->
56
+ if e.keyCode == 27 and options.esc
57
+ $.lazybox.close()
58
+ $(document).off('keyup.lazy')
75
59
  return options
76
60
 
77
61
  ) jQuery
62
+
63
+ $(document).on 'click', '#lazy_close, .lazy_buttons .cancel', $.lazybox.close
@@ -0,0 +1,96 @@
1
+ // Generated by CoffeeScript 1.4.0
2
+ (function() {
3
+
4
+ (function($) {
5
+ var defaults, init;
6
+ defaults = {
7
+ esc: true,
8
+ close: true,
9
+ modal: false,
10
+ klass: '',
11
+ cancelText: 'Cancel',
12
+ cancelClass: 'btn',
13
+ submitText: 'Ok',
14
+ submitClass: 'btn'
15
+ };
16
+ $.lazybox = function(html, options) {
17
+ return $.lazybox.show(html, options);
18
+ };
19
+ $.extend($.lazybox, {
20
+ settings: $.extend({}, defaults),
21
+ show: function(content, options) {
22
+ options = init(options);
23
+ $('#lazy_body').html(content);
24
+ return $('#lazy_overlay').addClass('active');
25
+ },
26
+ close: function() {
27
+ return $('#lazy_overlay').removeClass();
28
+ },
29
+ confirm: function(element) {
30
+ var message, options;
31
+ options = $.extend(defaults, $.lazybox.settings);
32
+ message = element.data('confirm');
33
+ if (!message) {
34
+ return true;
35
+ }
36
+ $.lazybox.show('<p>' + message + '</p><div class="lazy_buttons"></div>', {
37
+ klass: 'confirm'
38
+ });
39
+ element.clone().attr('class', options.submitClass).removeAttr('data-confirm').text(options.submitText).appendTo('.lazy_buttons');
40
+ $('.lazy_buttons').append(' ');
41
+ $('<button>', {
42
+ text: options.cancelText,
43
+ 'class': 'cancel ' + options.cancelClass
44
+ }).appendTo('.lazy_buttons');
45
+ return false;
46
+ }
47
+ });
48
+ $.fn.lazybox = function(options) {
49
+ return $(document).on('click', this.selector, function(e) {
50
+ var a, href, imagesRegexp, img;
51
+ a = $(e.currentTarget);
52
+ href = a.attr('href');
53
+ imagesRegexp = new RegExp('\\.(png|jpg|jpeg|gif)(\\?.*)?$', 'i');
54
+ e.preventDefault();
55
+ if (href.match(imagesRegexp)) {
56
+ img = new Image();
57
+ img.onload = function(element) {
58
+ return $.lazybox.show(img, options);
59
+ };
60
+ return $(img).attr({
61
+ 'class': 'lazy-img',
62
+ src: href
63
+ });
64
+ } else {
65
+ return $.ajax({
66
+ url: href,
67
+ success: function(data) {
68
+ return $.lazybox.show(data, options);
69
+ },
70
+ error: function() {
71
+ return $.lazybox.close();
72
+ }
73
+ });
74
+ }
75
+ });
76
+ };
77
+ return init = function(options) {
78
+ options = $.extend({}, defaults, $.lazybox.settings, options);
79
+ $('#lazybox').attr('class', options.klass);
80
+ $('#lazy_close').toggleClass('visible', options.close);
81
+ if (!options.modal) {
82
+ $('#lazy_overlay').one('click', $.lazybox.close);
83
+ }
84
+ $(document).on('keyup.lazy', function(e) {
85
+ if (e.keyCode === 27 && options.esc) {
86
+ $.lazybox.close();
87
+ return $(document).off('keyup.lazy');
88
+ }
89
+ });
90
+ return options;
91
+ };
92
+ })(jQuery);
93
+
94
+ $(document).on('click', '#lazy_close, .lazy_buttons .cancel', $.lazybox.close);
95
+
96
+ }).call(this);
@@ -1,61 +1,77 @@
1
- $lazyOpacity: 0.7;
2
- $lazyTransition: 0.3s;
3
- $lazy-z-index: 1000;
1
+ $lazy-transition: .3s !default;
2
+ $lazy-z-index: 1000 !default;
3
+ $lazy-overlay: rgba(black, .7) !default;
4
+ $lazy-bg: white !default;
5
+ $lazy-border: 1px solid #ccc !default;
6
+ $lazy-shadow: 0 1px 5px #333 !default;
7
+ $lazy-padding: 20px !default;
8
+ $lazy-start: scale(.7) !default;
9
+ $lazy-end: scale(1) !default;
10
+ $lazy-close: '×' !default;
4
11
 
5
12
  #lazy_overlay {
6
13
  visibility: hidden;
7
14
  z-index: $lazy-z-index;
8
- background: rgba(0, 0, 0, $lazyOpacity);
9
- bottom: 0px;
10
- left: 0px;
15
+ background: $lazy-overlay;
16
+ bottom: 0;
17
+ left: 0;
11
18
  position: fixed;
12
- right: 0px;
13
- top: 0px;
19
+ right: 0;
20
+ top: 0;
14
21
  opacity: 0;
15
- -webkit-transition: $lazyTransition;
16
- transition: $lazyTransition;
17
- &.visible { visibility: visible; opacity: 1; }
18
- display: -webkit-box;
19
- display: -moz-box;
20
- display: -ms-flexbox;
21
- display: -webkit-flex;
22
- display: flex;
23
- align-items: center;
24
- justify-content: center;
25
- &.top { align-items: flex-start; }
26
- &.top #lazybox {
27
- border-top-right-radius: 0;
28
- border-top-left-radius: 0;
22
+ transition: opacity $lazy-transition, visibility $lazy-transition;
23
+ &.active {
24
+ visibility: visible;
25
+ opacity: 1;
26
+ + #lazybox {
27
+ visibility: visible;
28
+ transform: translate(-50%, -50%) $lazy-end;
29
+ opacity: 1;
30
+ }
29
31
  }
30
32
  }
31
33
 
32
34
  #lazybox {
33
- background-color: #fff;
34
- border-radius: 5px;
35
- border: 1px solid #ccc;
36
- box-shadow: 0 1px 5px #333;
37
- padding: 20px;
38
- position: relative;
35
+ visibility: hidden;
36
+ opacity: 0;
37
+ top: 50%;
38
+ left: 50%;
39
+ transform: translate(-50%, -50%) $lazy-start;
40
+ background-color: $lazy-bg;
41
+ border: $lazy-border;
42
+ box-shadow: $lazy-shadow;
43
+ padding: $lazy-padding;
44
+ position: fixed;
45
+ box-sizing: border-box;
46
+ z-index: $lazy-z-index + 1;
47
+ overflow: auto;
48
+ max-height: 100vh;
49
+ max-width: 100vw;
50
+ transition: opacity $lazy-transition ease-in-out, transform $lazy-transition ease-in-out, visibility $lazy-transition;
39
51
  &.confirm { max-width: 300px; }
40
52
  .lazy_buttons { margin-top: 15px; text-align: right; }
41
53
  .lazy-img { display: block; }
42
- #lazybox_body { position: relative; }
54
+ #lazy_body {
55
+ position: relative;
56
+ }
43
57
  }
44
58
 
45
- a#lazy_close {
59
+ #lazy_close {
60
+ border: none;
46
61
  background: transparent;
47
62
  color: gray;
48
63
  cursor: pointer;
49
64
  display: none;
50
65
  font: bold 26px/100% Arial, Helvetica, sans-serif;
51
- height: 25px;
52
66
  position: absolute;
53
- right: 0;
67
+ right: 5px;
54
68
  text-align: center;
55
69
  top: 0;
56
- width: 25px;
57
- &:after { content: '×'; }
58
- &.img:after { content: ''; }
70
+ padding: 0;
71
+ margin: 0;
72
+ transition: color .3s;
73
+ &:after { content: $lazy-close; }
59
74
  &:hover { color: black; }
60
75
  &.visible { display: block; }
76
+ &:focus { outline: none; }
61
77
  }
@@ -1,4 +1,23 @@
1
1
  module Lazybox
2
+
2
3
  class Engine < Rails::Engine
3
4
  end
5
+
6
+ module Helper
7
+
8
+ def render_lazybox
9
+ content_tag(:div, '', id: :lazy_overlay, class: ('active' if content_for(:lazybox))) +
10
+ content_tag(:div, id: :lazybox) do
11
+ button_tag('', id: :lazy_close, class: :visible) +
12
+ content_tag(:div, id: :lazy_body) do
13
+ content_for(:lazybox)
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+
21
+ ActiveSupport.on_load(:action_view) do
22
+ include Lazybox::Helper
4
23
  end
@@ -1,3 +1,3 @@
1
1
  module Lazybox
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazybox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alex Galushka
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-07-14 00:00:00.000000000 Z
11
+ date: 2014-12-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: jquery-rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: Lazybox is a jQuery-based, lightbox that can display entire remote pages,
@@ -37,33 +34,32 @@ extensions: []
37
34
  extra_rdoc_files: []
38
35
  files:
39
36
  - README.md
40
- - lib/lazybox/version.rb
41
- - lib/lazybox.rb
42
- - app/assets/stylesheets/lazybox.css.scss
43
37
  - app/assets/javascripts/lazybox.js.coffee
38
+ - app/assets/javascripts/lazybox.js.js
39
+ - app/assets/stylesheets/lazybox.css.scss
40
+ - lib/lazybox.rb
41
+ - lib/lazybox/version.rb
44
42
  homepage: https://github.com/galulex/lazybox
45
43
  licenses: []
44
+ metadata: {}
46
45
  post_install_message:
47
46
  rdoc_options: []
48
47
  require_paths:
49
48
  - lib
50
49
  required_ruby_version: !ruby/object:Gem::Requirement
51
- none: false
52
50
  requirements:
53
- - - ! '>='
51
+ - - ">="
54
52
  - !ruby/object:Gem::Version
55
53
  version: '0'
56
54
  required_rubygems_version: !ruby/object:Gem::Requirement
57
- none: false
58
55
  requirements:
59
- - - ! '>='
56
+ - - ">="
60
57
  - !ruby/object:Gem::Version
61
58
  version: '0'
62
59
  requirements: []
63
60
  rubyforge_project:
64
- rubygems_version: 1.8.23
61
+ rubygems_version: 2.2.2
65
62
  signing_key:
66
- specification_version: 3
63
+ specification_version: 4
67
64
  summary: Use LazyBox for popup windows with Rails
68
65
  test_files: []
69
- has_rdoc: