lazybox 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/app/assets/javascripts/lazybox.js.coffee +1 -1
- data/app/assets/javascripts/lazybox.js.js +188 -0
- data/lib/lazybox/version.rb +1 -1
- metadata +5 -4
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
LazyBox [![Build Status](https://travis-ci.org/galulex/lazybox.png?branch=master)](https://travis-ci.org/galulex/lazybox) [![Gem Version](https://badge.fury.io/rb/lazybox.png)](http://badge.fury.io/rb/webhostinghub-glyphs-rails) [![endorse](http://api.coderwall.com/galulex/endorsecount.png)](http://coderwall.com/galulex)
|
2
2
|
=
|
3
3
|
|
4
|
+
[Live Demo](http://lazybox.herokuapp.com/)
|
5
|
+
|
4
6
|
[Demo Source](https://github.com/galulex/lazybox_demo)
|
5
7
|
|
6
8
|
Lazybox is a jQuery-based, lightbox that can display entire remote pages, images and confirmation dialogs.
|
@@ -34,7 +34,7 @@
|
|
34
34
|
|
35
35
|
close: (speed) ->
|
36
36
|
speed = speed || defaults.speed
|
37
|
-
effect = if (box.position().top - window.scrollY
|
37
|
+
effect = if (box.position().top - window.scrollY <= 0) then 'slideUp' else 'fadeOut'
|
38
38
|
box[effect](speed)
|
39
39
|
overlay.fadeOut(speed+200)
|
40
40
|
|
@@ -0,0 +1,188 @@
|
|
1
|
+
// Generated by CoffeeScript 1.4.0
|
2
|
+
(function() {
|
3
|
+
|
4
|
+
(function($) {
|
5
|
+
var box, close, defaults, html, init, overlay,
|
6
|
+
_this = this;
|
7
|
+
defaults = {
|
8
|
+
overlay: true,
|
9
|
+
esc: true,
|
10
|
+
close: true,
|
11
|
+
modal: true,
|
12
|
+
opacity: 0.3,
|
13
|
+
onTop: false,
|
14
|
+
speed: 300,
|
15
|
+
fixed: false,
|
16
|
+
cancelText: 'Cancel',
|
17
|
+
cancelClass: 'button',
|
18
|
+
submitText: 'Ok',
|
19
|
+
submitClass: 'button'
|
20
|
+
};
|
21
|
+
html = "<div id='lazybox'><div id='lazybox_body'></div></div>";
|
22
|
+
box = $('#lazybox');
|
23
|
+
overlay = $('#lazybox_overlay');
|
24
|
+
close = $('#lazybox_close');
|
25
|
+
$.lazybox = function(html, options) {
|
26
|
+
return $.lazybox.show(html, options);
|
27
|
+
};
|
28
|
+
$.extend($.lazybox, {
|
29
|
+
settings: $.extend({}, defaults),
|
30
|
+
show: function(content, options) {
|
31
|
+
var effect;
|
32
|
+
options = init(options);
|
33
|
+
$('#lazybox_body').html(content);
|
34
|
+
$.lazybox.center(options.onTop, options.fixed);
|
35
|
+
effect = options.onTop ? 'slideDown' : 'fadeIn';
|
36
|
+
box[effect](options.speed);
|
37
|
+
return options;
|
38
|
+
},
|
39
|
+
close: function(speed) {
|
40
|
+
var effect;
|
41
|
+
speed = speed || defaults.speed;
|
42
|
+
effect = box.position().top - window.scrollY === 0 ? 'slideUp' : 'fadeOut';
|
43
|
+
box[effect](speed);
|
44
|
+
return overlay.fadeOut(speed + 200);
|
45
|
+
},
|
46
|
+
center: function(onTop, fixed) {
|
47
|
+
var y;
|
48
|
+
if (fixed) {
|
49
|
+
y = onTop ? 0 : (box.outerHeight()) / 2;
|
50
|
+
if (y < 20 && !onTop) {
|
51
|
+
y = 20;
|
52
|
+
}
|
53
|
+
return box.css({
|
54
|
+
'margin-left': -box.outerWidth() / 2,
|
55
|
+
'margin-top': -y,
|
56
|
+
top: (onTop ? 0 : '49%'),
|
57
|
+
position: 'fixed',
|
58
|
+
left: '49%'
|
59
|
+
});
|
60
|
+
} else {
|
61
|
+
y = onTop ? 0 : (($(window).height() - $('#lazybox').outerHeight()) / 2) + $(window).scrollTop();
|
62
|
+
if (y < 20 && !onTop) {
|
63
|
+
y = 20;
|
64
|
+
}
|
65
|
+
return box.css({
|
66
|
+
top: y,
|
67
|
+
left: (($(window).width() - box.outerWidth()) / 2) + $(window).scrollLeft(),
|
68
|
+
position: 'absolute',
|
69
|
+
margin: 0
|
70
|
+
});
|
71
|
+
}
|
72
|
+
},
|
73
|
+
confirm: function(element) {
|
74
|
+
var message, options;
|
75
|
+
options = $.extend(defaults, $.lazybox.settings);
|
76
|
+
message = element.data('confirm');
|
77
|
+
if (!message) {
|
78
|
+
return true;
|
79
|
+
}
|
80
|
+
$.lazybox.show('<p>' + message + '</p><div class="lazy_buttons"></div>', {
|
81
|
+
klass: 'confirm'
|
82
|
+
});
|
83
|
+
element.clone().attr('class', options.submitClass).removeAttr('data-confirm').text(options.submitText).appendTo('.lazy_buttons');
|
84
|
+
$('.lazy_buttons').append(' ');
|
85
|
+
$('<a>', {
|
86
|
+
href: '',
|
87
|
+
text: options.cancelText,
|
88
|
+
'class': options.cancelClass
|
89
|
+
}).appendTo('.lazy_buttons');
|
90
|
+
return false;
|
91
|
+
}
|
92
|
+
});
|
93
|
+
$.fn.lazybox = function(options) {
|
94
|
+
var _this = this;
|
95
|
+
return $(document).on('click', this.selector, function(e) {
|
96
|
+
var a, href, imagesRegexp, img;
|
97
|
+
a = $(e.currentTarget);
|
98
|
+
href = a.attr('href');
|
99
|
+
imagesRegexp = new RegExp('\\.(png|jpg|jpeg|gif)(\\?.*)?$', 'i');
|
100
|
+
e.preventDefault();
|
101
|
+
if (href.match(imagesRegexp)) {
|
102
|
+
img = new Image();
|
103
|
+
img.onload = function(element) {
|
104
|
+
var nextLink, prevLink;
|
105
|
+
options = $.lazybox.show(img, options);
|
106
|
+
nextLink = a.is(':last-child') ? a.siblings('a[rel*=lazybox]:first') : a.next('a[rel*=lazybox]:first');
|
107
|
+
prevLink = a.is(':first-child') ? a.siblings('a[rel*=lazybox]:last') : a.prev('a[rel*=lazybox]:first');
|
108
|
+
if (nextLink.length && prevLink.length) {
|
109
|
+
$('#lazybox_body:not(:has(a#next_lazy_img))').append("<a id='prev_lazy_img' href=''><b>‹</b></a><a id='next_lazy_img' href=''><b>›</b></a>");
|
110
|
+
return $('#next_lazy_img, #prev_lazy_img').bind('click', function(event) {
|
111
|
+
event.preventDefault();
|
112
|
+
return box.fadeOut(options.speed, function() {
|
113
|
+
if (event.currentTarget.id === 'next_lazy_img') {
|
114
|
+
return nextLink.click();
|
115
|
+
} else {
|
116
|
+
return prevLink.click();
|
117
|
+
}
|
118
|
+
});
|
119
|
+
});
|
120
|
+
}
|
121
|
+
};
|
122
|
+
return $(img).attr({
|
123
|
+
'class': 'lazy_img',
|
124
|
+
src: href
|
125
|
+
});
|
126
|
+
} else {
|
127
|
+
return $.ajax({
|
128
|
+
url: href,
|
129
|
+
success: function(data) {
|
130
|
+
return $.lazybox.show(data, options);
|
131
|
+
},
|
132
|
+
error: function() {
|
133
|
+
return $.lazybox.close(options.speed);
|
134
|
+
}
|
135
|
+
});
|
136
|
+
}
|
137
|
+
});
|
138
|
+
};
|
139
|
+
return init = function(options) {
|
140
|
+
var _this = this;
|
141
|
+
options = $.extend($.extend({}, defaults), $.lazybox.settings, options);
|
142
|
+
if (options.overlay) {
|
143
|
+
$('body:not(:has(#lazybox_overlay))').append("<div id='lazybox_overlay'></div>");
|
144
|
+
overlay = $('#lazybox_overlay');
|
145
|
+
overlay.css({
|
146
|
+
filter: 'alpha(opacity=' + options.opacity * 100 + ')',
|
147
|
+
opacity: options.opacity
|
148
|
+
}).fadeIn(options.speed + 200);
|
149
|
+
}
|
150
|
+
$('body:not(:has(#lazybox))').append(html);
|
151
|
+
box = $('#lazybox');
|
152
|
+
if (options.klass) {
|
153
|
+
box.attr('class', options.klass);
|
154
|
+
} else {
|
155
|
+
box.removeClass();
|
156
|
+
}
|
157
|
+
if (options.close) {
|
158
|
+
box.not(':has(#lazybox_close)').prepend($("<a id='lazybox_close' title='close'></a>"));
|
159
|
+
close = $('#lazybox_close');
|
160
|
+
if (options.closeImg) {
|
161
|
+
close.attr('class', 'img').text('');
|
162
|
+
} else {
|
163
|
+
close.removeClass().text('×');
|
164
|
+
}
|
165
|
+
} else {
|
166
|
+
close.remove();
|
167
|
+
}
|
168
|
+
if (!options.modal && options.overlay) {
|
169
|
+
overlay.bind('click', function() {
|
170
|
+
return $.lazybox.close(options.speed);
|
171
|
+
});
|
172
|
+
} else {
|
173
|
+
overlay.unbind();
|
174
|
+
}
|
175
|
+
$(document).keyup(function(e) {
|
176
|
+
if (e.keyCode === 27 && options.esc) {
|
177
|
+
return $.lazybox.close(options.speed);
|
178
|
+
}
|
179
|
+
});
|
180
|
+
box.on('click', '#lazybox_close, .lazy_buttons a', function(e) {
|
181
|
+
$.lazybox.close(options.speed);
|
182
|
+
return e.preventDefault();
|
183
|
+
});
|
184
|
+
return options;
|
185
|
+
};
|
186
|
+
})(jQuery);
|
187
|
+
|
188
|
+
}).call(this);
|
data/lib/lazybox/version.rb
CHANGED
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.6
|
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: 2013-
|
12
|
+
date: 2013-09-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jquery-rails
|
@@ -37,10 +37,11 @@ extensions: []
|
|
37
37
|
extra_rdoc_files: []
|
38
38
|
files:
|
39
39
|
- README.md
|
40
|
-
- lib/lazybox.rb
|
41
40
|
- lib/lazybox/version.rb
|
42
|
-
-
|
41
|
+
- lib/lazybox.rb
|
43
42
|
- app/assets/stylesheets/lazybox.css.scss
|
43
|
+
- app/assets/javascripts/lazybox.js.js
|
44
|
+
- app/assets/javascripts/lazybox.js.coffee
|
44
45
|
homepage: https://github.com/galulex/lazybox
|
45
46
|
licenses: []
|
46
47
|
post_install_message:
|