├── .gitignore
├── .travis.yml
├── Gemfile
├── README.md
├── Rakefile
├── app
└── assets
│ ├── javascripts
│ └── lazybox.coffee
│ └── stylesheets
│ └── lazybox.scss
├── gemfiles
└── Gemfile.ci
├── lazybox.gemspec
├── lib
├── lazybox.rb
└── lazybox
│ └── version.rb
└── specs
├── SpecRunner.html
├── lazybox_spec.js.coffee
└── lib
└── jasmine-1.2.0
├── MIT.LICENSE
├── jasmine-html.js
├── jasmine-jquery.js
├── jasmine.css
└── jasmine.js
/.gitignore:
--------------------------------------------------------------------------------
1 | *.gem
2 | .bundle
3 | Gemfile.lock
4 | pkg/*
5 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: ruby
2 | rvm:
3 | - 1.9.3
4 | - 2.0.0
5 | gemfile: gemfiles/Gemfile.ci
6 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source "http://rubygems.org"
2 |
3 | # Specify your gem's dependencies in lazybox.gemspec
4 | gemspec
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | LazyBox [](https://travis-ci.org/galulex/lazybox) [](http://badge.fury.io/rb/webhostinghub-glyphs-rails) [](http://coderwall.com/galulex)
2 | =
3 |
4 | [Live Demo](http://lazybox.herokuapp.com/)
5 |
6 | [Demo Source](https://github.com/galulex/lazybox_demo)
7 |
8 | Lazybox is a jQuery-based, lightbox that can display entire remote pages, images and confirmation dialogs.
9 | Replace standard rails confirmations with lazybox just added several rows to your project. Use lazybox with rails assets pipeline.
10 |
11 | LazyBox implemented using only css and jquery without images.
12 | This is high perfomance modal dialogs. All unpacked files take only 5 kb.
13 | This is simplest solution for popup windows and custom confirmation dialogs.
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 |
20 | Installing
21 | ----------
22 |
23 | Add it to your Gemfile:
24 |
25 | ```ruby
26 | gem 'lazybox'
27 | ```
28 |
29 | Then run `bundle install` to update your application's bundle.
30 |
31 | Add to your layout helper `render_lazybox`:
32 |
33 | ```slim
34 | ...
35 | render_lazybox
36 | body
37 | html
38 | ```
39 |
40 | Include in your `application.css`:
41 |
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';
71 | ```
72 |
73 | And in `application.js`:
74 |
75 | ```javascript
76 | //= require lazybox
77 | ```
78 |
79 | Usage
80 | -----
81 |
82 | ### Remote pages
83 | Usual remote link:
84 |
85 | ```haml
86 | - link_to 'Lazybox', new_model_path, remote: true
87 | ```
88 |
89 | In your controller:
90 |
91 | ```ruby
92 | def new
93 | @model = Model.new
94 | end
95 |
96 | def create
97 | @model = Model.new(params[:model])
98 | render action: :new unless @model.save
99 | end
100 | ```
101 |
102 | `new.js.haml`
103 |
104 | ```haml
105 | $.lazybox("#{j(render partial: 'form')}");
106 | ```
107 |
108 | `create.js.haml`
109 |
110 | ```haml
111 | $.lazybox.close()
112 | window.location.reload()
113 | ```
114 |
115 | ### Confirmations
116 |
117 | You can replace standard rails confirmations with lazybox
118 |
119 | And in `application.js`:
120 |
121 | ```javascript
122 | $.rails.allowAction = $.lazybox.confirm;
123 | ```
124 |
125 | for options use global lazybox settings:
126 |
127 | ```javascript
128 | $.lazybox.settings = {cancelClass: "button gray", submitClass: 'button gray', overlay: false}
129 | ```
130 |
131 | or instance settings
132 |
133 | ```javascript
134 | $.lazybox("
It works!
",{modal: true, close: false})
135 | ```
136 |
137 | ### Images
138 |
139 | ```haml
140 | - link_to 'Image', image.url, rel: :lazybox
141 | ```
142 | Include in your `app/assets/javascripts/application.js`:
143 |
144 | ```javascript
145 | $(document).ready(function() {
146 | $('a[rel*=lazybox]').lazybox();
147 | // or with options
148 | $('a[rel*=lazybox]').lazybox({esc: true, close: true, modal: true, klass: 'class'});
149 | });
150 | ```
151 |
152 | If there are more than one link to image you can click on image in the lazybox to show the next one (version < 0.2.6)
153 |
154 | ```haml
155 | = link_to image.url, rel: :lazybox do
156 | = image_tag image.url, height: 100
157 | = link_to image2.url, rel: :lazybox do
158 | = image_tag image2.url, height: 100
159 | ```
160 |
161 | We can use lazybox with `turbolinks` to show page loading spinner:
162 |
163 | ```coffeescript
164 | $(document).on 'page:fetch', -> $.lazybox("", { klass: 'spinner', close: false, esc: false })
165 | ```
166 |
167 | ```css
168 | #lazybox.spinner {
169 | background: transparent;
170 | border: none;
171 | box-shadow: none;
172 | }
173 | ```
174 |
175 | Turbolinks spinner
176 | ------------------
177 |
178 | ```coffee
179 | $(document).on 'page:fetch', -> $.lazybox("", { klass: 'spinner', close: false, esc: false })
180 | $(document).on 'page:change', -> $.lazybox.close()
181 | ```
182 |
183 | ```scss
184 | #lazybox.spinner {
185 | background: transparent;
186 | box-shadow: none;
187 | .fa-spinner { font-size: 128px; }
188 | }
189 | ```
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 |
204 | Options
205 | -------
206 |
207 | esc: true|false //default true. Close lazybox on esc press
208 | close: true|false //default true. Show close lazybox button
209 | modal: true|false //default true. Close lazybox on overlay click
210 | klass: 'class' Set class for lazybox. ...
211 | //confirmation options
212 | cancelText: //default 'Cancel'. Cancel button text
213 | submitText: //default 'Ok'. Confirm button text
214 | cancelClass: //default 'button'. Cancel button class
215 | submitClass: //default 'button'. Confirm button class
216 |
217 | Events
218 | ------
219 |
220 | $.lazybox.show()
221 | $.lazybox.close()
222 |
223 | Browser Compatibility
224 | ---------------------
225 |
226 | 
227 | 
228 | 
229 | 
230 | 
231 |
232 | ### If you want to support IE < 9 you have to use version 0.2.*.
233 |
234 | Copyright© Alex Galushka
235 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env rake
2 |
3 | require "bundler/gem_tasks"
4 | require "rake/testtask"
5 |
6 | Rake::TestTask.new(:test) do |t|
7 | t.libs << "lib"
8 | t.libs << "test"
9 | t.pattern = "test/**/*_test.rb"
10 | t.verbose = false
11 | end
12 |
13 | task default: :test
14 |
--------------------------------------------------------------------------------
/app/assets/javascripts/lazybox.coffee:
--------------------------------------------------------------------------------
1 | (($) ->
2 | defaults =
3 | esc: true
4 | close: true
5 | modal: false
6 | klass: ''
7 | cancelText: 'Cancel'
8 | cancelClass: 'btn'
9 | submitText: 'Ok'
10 | submitClass: 'btn'
11 |
12 | $.lazybox = (html, options) -> $.lazybox.show(html, options)
13 |
14 | $.extend $.lazybox,
15 | settings: $.extend {}, defaults
16 |
17 | show: (content, options) ->
18 | options = init(options)
19 | $('#lazy_body').html(content)
20 | $('#lazy_overlay').addClass('active')
21 |
22 | close: -> $('#lazy_overlay').removeClass()
23 |
24 | confirm: (element) ->
25 | options = $.extend defaults, $.lazybox.settings
26 | message = element.data('confirm')
27 | return true unless message
28 | $.lazybox.show(''+message+'
', { klass: 'confirm' })
29 | element.clone().attr('class', options.submitClass).removeAttr('data-confirm').text(options.submitText).appendTo('.lazy_buttons')
30 | $('.lazy_buttons').append(' ')
31 | $('