lazybox 0.2.2 → 0.2.3
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/lib/lazybox/version.rb +1 -1
- data/vendor/assets/javascripts/lazybox.js.coffee +2 -2
- data/vendor/assets/javascripts/lazybox.js.js +173 -0
- metadata +7 -10
- data/.gitignore +0 -4
- data/Gemfile +0 -4
- data/Rakefile +0 -1
- data/lazybox.gemspec +0 -20
data/lib/lazybox/version.rb
CHANGED
@@ -52,14 +52,14 @@
|
|
52
52
|
options = $.extend defaults, $.lazybox.settings
|
53
53
|
message = element.data('confirm')
|
54
54
|
return true if !message
|
55
|
-
$.lazybox.show('<p>'+message+'</p><div class="lazy_buttons"
|
55
|
+
$.lazybox.show('<p>'+message+'</p><div class="lazy_buttons"></div>', { klass: 'confirm' })
|
56
56
|
element.clone().attr('class', options.submitClass).removeAttr('data-confirm').text(options.submitText).appendTo('.lazy_buttons')
|
57
57
|
$('.lazy_buttons').append(' ')
|
58
58
|
$('<a>', { href: '', text: options.cancelText, 'class': options.cancelClass }).appendTo('.lazy_buttons')
|
59
59
|
return false
|
60
60
|
|
61
61
|
$.fn.lazybox = (options) ->
|
62
|
-
|
62
|
+
$(document).on 'click', this.selector, (e) =>
|
63
63
|
a = $(e.currentTarget)
|
64
64
|
href = a.attr('href')
|
65
65
|
imagesRegexp = new RegExp('\\.(png|jpg|jpeg|gif)(\\?.*)?$', 'i')
|
@@ -0,0 +1,173 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
(function($) {
|
4
|
+
var box, close, defaults, html, init, overlay,
|
5
|
+
_this = this;
|
6
|
+
defaults = {
|
7
|
+
overlay: true,
|
8
|
+
esc: true,
|
9
|
+
close: true,
|
10
|
+
modal: true,
|
11
|
+
opacity: 0.3,
|
12
|
+
onTop: false,
|
13
|
+
speed: 300,
|
14
|
+
fixed: false,
|
15
|
+
cancelText: 'Cancel',
|
16
|
+
cancelClass: 'button',
|
17
|
+
submitText: 'Ok',
|
18
|
+
submitClass: 'button'
|
19
|
+
};
|
20
|
+
html = "<div id='lazybox'><div id='lazybox_body'></div></div>";
|
21
|
+
box = $('#lazybox');
|
22
|
+
overlay = $('#lazybox_overlay');
|
23
|
+
close = $('#lazybox_close');
|
24
|
+
$.lazybox = function(html, options) {
|
25
|
+
return $.lazybox.show(html, options);
|
26
|
+
};
|
27
|
+
$.extend($.lazybox, {
|
28
|
+
settings: $.extend({}, defaults),
|
29
|
+
show: function(content, options) {
|
30
|
+
var effect;
|
31
|
+
options = init(options);
|
32
|
+
$('#lazybox_body').html(content);
|
33
|
+
$.lazybox.center(options.onTop, options.fixed);
|
34
|
+
effect = options.onTop ? 'slideDown' : 'fadeIn';
|
35
|
+
box[effect](options.speed);
|
36
|
+
return options;
|
37
|
+
},
|
38
|
+
close: function(speed) {
|
39
|
+
var effect;
|
40
|
+
speed = speed || defaults.speed;
|
41
|
+
effect = box.position().top === 0 ? 'slideUp' : 'fadeOut';
|
42
|
+
box[effect](speed);
|
43
|
+
return overlay.fadeOut(speed + 200);
|
44
|
+
},
|
45
|
+
center: function(onTop, fixed) {
|
46
|
+
var y;
|
47
|
+
if (fixed) {
|
48
|
+
y = onTop ? 0 : (box.outerHeight()) / 2;
|
49
|
+
if (y < 20 && !onTop) y = 20;
|
50
|
+
return box.css({
|
51
|
+
'margin-left': -box.outerWidth() / 2,
|
52
|
+
'margin-top': -y,
|
53
|
+
top: (onTop ? 0 : '49%'),
|
54
|
+
position: 'fixed',
|
55
|
+
left: '49%'
|
56
|
+
});
|
57
|
+
} else {
|
58
|
+
y = onTop ? 0 : (($(window).height() - $('#lazybox').outerHeight()) / 2) + $(window).scrollTop();
|
59
|
+
if (y < 20 && !onTop) y = 20;
|
60
|
+
return box.css({
|
61
|
+
top: y,
|
62
|
+
left: (($(window).width() - box.outerWidth()) / 2) + $(window).scrollLeft(),
|
63
|
+
position: 'absolute',
|
64
|
+
margin: 0
|
65
|
+
});
|
66
|
+
}
|
67
|
+
},
|
68
|
+
confirm: function(element) {
|
69
|
+
var message, options;
|
70
|
+
options = $.extend(defaults, $.lazybox.settings);
|
71
|
+
message = element.data('confirm');
|
72
|
+
if (!message) return true;
|
73
|
+
$.lazybox.show('<p>' + message + '</p><div class="lazy_buttons"></div>', {
|
74
|
+
klass: 'confirm'
|
75
|
+
});
|
76
|
+
element.clone().attr('class', options.submitClass).removeAttr('data-confirm').text(options.submitText).appendTo('.lazy_buttons');
|
77
|
+
$('.lazy_buttons').append(' ');
|
78
|
+
$('<a>', {
|
79
|
+
href: '',
|
80
|
+
text: options.cancelText,
|
81
|
+
'class': options.cancelClass
|
82
|
+
}).appendTo('.lazy_buttons');
|
83
|
+
return false;
|
84
|
+
}
|
85
|
+
});
|
86
|
+
$.fn.lazybox = function(options) {
|
87
|
+
var _this = this;
|
88
|
+
return $(document).on('click', this.selector, function(e) {
|
89
|
+
var a, href, imagesRegexp, img;
|
90
|
+
a = $(e.currentTarget);
|
91
|
+
href = a.attr('href');
|
92
|
+
imagesRegexp = new RegExp('\\.(png|jpg|jpeg|gif)(\\?.*)?$', 'i');
|
93
|
+
e.preventDefault();
|
94
|
+
if (href.match(imagesRegexp)) {
|
95
|
+
img = new Image();
|
96
|
+
img.onload = function(element) {
|
97
|
+
var nextLink,
|
98
|
+
_this = this;
|
99
|
+
options = $.lazybox.show(img, options);
|
100
|
+
nextLink = a.is(':last-child') ? a.siblings('a[rel*=lazybox]:first') : a.next('a[rel*=lazybox]:first');
|
101
|
+
if (nextLink.length !== 0) {
|
102
|
+
return $('#lazybox img').bind('click', function() {
|
103
|
+
return box.fadeOut(options.speed, function() {
|
104
|
+
return nextLink.click();
|
105
|
+
});
|
106
|
+
});
|
107
|
+
}
|
108
|
+
};
|
109
|
+
return $(img).attr({
|
110
|
+
'class': 'lazy_img',
|
111
|
+
src: href
|
112
|
+
});
|
113
|
+
} else {
|
114
|
+
return $.ajax({
|
115
|
+
url: href,
|
116
|
+
success: function(data) {
|
117
|
+
return $.lazybox.show(data, options);
|
118
|
+
},
|
119
|
+
error: function() {
|
120
|
+
return $.lazybox.close(options.speed);
|
121
|
+
}
|
122
|
+
});
|
123
|
+
}
|
124
|
+
});
|
125
|
+
};
|
126
|
+
return init = function(options) {
|
127
|
+
var _this = this;
|
128
|
+
options = $.extend($.extend({}, defaults), $.lazybox.settings, options);
|
129
|
+
if (options.overlay) {
|
130
|
+
$('body:not(:has(#lazybox_overlay))').append("<div id='lazybox_overlay'></div>");
|
131
|
+
overlay = $('#lazybox_overlay');
|
132
|
+
overlay.css({
|
133
|
+
filter: 'alpha(opacity=' + options.opacity * 100 + ')',
|
134
|
+
opacity: options.opacity
|
135
|
+
}).fadeIn(options.speed + 200);
|
136
|
+
}
|
137
|
+
$('body:not(:has(#lazybox))').append(html);
|
138
|
+
box = $('#lazybox');
|
139
|
+
if (options.klass) {
|
140
|
+
box.attr('class', options.klass);
|
141
|
+
} else {
|
142
|
+
box.removeClass();
|
143
|
+
}
|
144
|
+
if (options.close) {
|
145
|
+
box.not(':has(#lazybox_close)').prepend($("<a id='lazybox_close' title='close'></a>"));
|
146
|
+
close = $('#lazybox_close');
|
147
|
+
if (options.closeImg) {
|
148
|
+
close.attr('class', 'img').text('');
|
149
|
+
} else {
|
150
|
+
close.removeClass().text('×');
|
151
|
+
}
|
152
|
+
} else {
|
153
|
+
close.remove();
|
154
|
+
}
|
155
|
+
if (!options.modal && options.overlay) {
|
156
|
+
overlay.bind('click', function() {
|
157
|
+
return $.lazybox.close(options.speed);
|
158
|
+
});
|
159
|
+
} else {
|
160
|
+
overlay.unbind();
|
161
|
+
}
|
162
|
+
$(document).keyup(function(e) {
|
163
|
+
if (e.keyCode === 27 && options.esc) return $.lazybox.close(options.speed);
|
164
|
+
});
|
165
|
+
box.on('click', '#lazybox_close, .lazy_buttons a', function(e) {
|
166
|
+
$.lazybox.close(options.speed);
|
167
|
+
return e.preventDefault();
|
168
|
+
});
|
169
|
+
return options;
|
170
|
+
};
|
171
|
+
})(jQuery);
|
172
|
+
|
173
|
+
}).call(this);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazybox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &19446660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *19446660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: jquery-rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &19446240 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *19446240
|
36
36
|
description: Lazybox is a jQuery-based, lightbox that can display entire remote pages,
|
37
37
|
images and confirmation dialogs. Replace standard rails confirmations with lazybox
|
38
38
|
just added several rows to your project. Use lazybox with rails assets pipeline.
|
@@ -42,14 +42,11 @@ executables: []
|
|
42
42
|
extensions: []
|
43
43
|
extra_rdoc_files: []
|
44
44
|
files:
|
45
|
-
- .gitignore
|
46
|
-
- Gemfile
|
47
45
|
- README.md
|
48
|
-
- Rakefile
|
49
|
-
- lazybox.gemspec
|
50
46
|
- lib/lazybox.rb
|
51
47
|
- lib/lazybox/version.rb
|
52
48
|
- vendor/assets/javascripts/lazybox.js.coffee
|
49
|
+
- vendor/assets/javascripts/lazybox.js.js
|
53
50
|
- vendor/assets/stylesheets/lazybox.css.scss
|
54
51
|
homepage: https://github.com/galulex/lazybox
|
55
52
|
licenses: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
data/lazybox.gemspec
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path("../lib/lazybox/version", __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.name = "lazybox"
|
6
|
-
s.version = Lazybox::VERSION
|
7
|
-
s.authors = ["Alex Galushka"]
|
8
|
-
s.email = ["sexmcs@gmail.com"]
|
9
|
-
s.homepage = "https://github.com/galulex/lazybox"
|
10
|
-
s.summary = "Use LazyBox for popup windows with Rails"
|
11
|
-
s.description = "Lazybox is a jQuery-based, lightbox that can display entire remote pages, images and confirmation dialogs. Replace standard rails confirmations with lazybox just added several rows to your project. Use lazybox with rails assets pipeline."
|
12
|
-
s.platform = Gem::Platform::RUBY
|
13
|
-
|
14
|
-
s.files = `git ls-files`.split("\n")
|
15
|
-
s.require_path = "lib"
|
16
|
-
|
17
|
-
s.add_development_dependency "rails", "~> 3.1"
|
18
|
-
s.add_development_dependency "jquery-rails"
|
19
|
-
end
|
20
|
-
|