├── .hsdoc
├── LICENSE.txt
├── README.markdown
├── docs
├── API
│ └── Options.md
├── demo.js
├── iframe.html
└── intro.md
├── jquery.zoomer.js
└── package.json
/.hsdoc:
--------------------------------------------------------------------------------
1 | title: "jQuery Zoomer"
2 | description: "Zoom up your iFrames"
3 | source: "*.js"
4 | examples: "**/*.md"
5 | assets: "{jquery.zoomer.js,docs/iframe.html,docs/demo.js}"
6 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | Copyright (c) 2012 HubSpot
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | ## jQuery Zoomer
2 |
3 | Zoom up any iFrame.
4 |
5 | ### Browser support
6 |
7 | Tested and working: Chrome, FF3.6+, IE8+
8 |
9 | ### Usage
10 |
11 | ````javascript
12 | $('iframe').zoomer({ width: 200, zoom: 0.5 });
13 | ````
14 |
15 | ### Demo
16 |
17 | http://hubspot.github.com/jquery-zoomer
18 |
--------------------------------------------------------------------------------
/docs/API/Options.md:
--------------------------------------------------------------------------------
1 | ## API Documentation
2 |
3 | ### Options
4 |
5 |
6 |
7 | Name
8 | Default [Description]
9 |
10 |
11 | width 'auto'
12 | height 'auto'
13 | zoom 0.4
14 | tranformOrigin '0 0'
15 | loadingType 'message'
Other option: 'spinner'
16 | loadingMessage 'Generating preview...'
Message displayed while the iFrame is loading
17 | spinnerURL 'http://oi46.tinypic.com/6y375z.jpg'
Requires loadingType: 'spinner'
18 | message 'Open Page'
The text displayed on hover
19 | ieMessageButtonClass 'btn btn-secondary'
Class name added to the Open Page button in IE
20 | messageURL false
Use a different URL on click then the src
of the iFrame
21 | onComplete function($iframe) {}
Callback function after the iFrame has loaded and been zoomed
22 |
23 |
24 |
25 | ### Methods
26 |
27 |
28 |
29 | Name
30 | Description
31 |
32 |
33 | $iframe.zoomer('fadeIn') Fades out the loading message to reveal the iFrame beneath.
34 | $iframe.zoomer('fadeOut') Fades in the loading message to hide the iFrame beneath.
35 | $iframe.zoomer('src', newSrc) Changes the src of the iFrame seamlessly. (Fades in the loading message, sets the iFrame src to newSrc
and then fades out the loading message after the iFrame finishes loading and gets zoomed.)
36 | $iframe.zoomer('refresh') Alias to calling $iframe.zoomer('src', currentSrc)
37 | $iframe.zoomer('zoomedBodyHeight') Returns the height of the iFrame in zoomed space. (Example: if iFrame contents have height of 800px
and zoom is set to 0.5
, returns 400
.)
38 |
39 |
--------------------------------------------------------------------------------
/docs/demo.js:
--------------------------------------------------------------------------------
1 | $(function(){
2 | $('iframe.demo').zoomer({ width: 300, height: 300, zoom: 0.6 });
3 | });
--------------------------------------------------------------------------------
/docs/iframe.html:
--------------------------------------------------------------------------------
1 | jQuery Zoomer
29 |
30 |
31 |
32 |
Demo iFrame
33 |
34 |
I'm inside an iFrame.
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/docs/intro.md:
--------------------------------------------------------------------------------
1 | ## What is jQuery Zoomer?
2 |
3 | jQuery Zoomer is a library which lets you zoom up your iframes using CSS transforms.
4 |
5 | ### Browser support
6 |
7 | Tested and working: Chrome, FF3.6+, IE8+
8 |
9 | ### Usage
10 |
11 | ````javascript
12 | $('iframe.zoomer').zoomer({
13 | zoom: 0.5,
14 | width: 200
15 | });
16 | ````
17 | (Note: this example has already been run on the iFrame below.)
18 |
19 | ### Demo
20 |
21 |
22 |
Click the iFrame to open the URL in a separate browser window/tab.
23 |
31 |
32 |
33 |
34 |
35 |
36 | Once a Zoomer has already been zoomed, you can adjust the zoom amount by later calling:
37 |
38 | ```javascript
39 | zoom = 0.25; // Change me to any number 0–1 and then hit "Run"
40 |
41 | $iframe = $('iframe.demo');
42 | $iframe.data().zoomer.zoom = zoom;
43 | $iframe.zoomer('refresh');
44 | ```
45 |
46 | ### Full Reference
47 |
48 | For a full reference, see our [API documentation](http://github.hubspot.com/jquery-zoomer/api/options).
--------------------------------------------------------------------------------
/jquery.zoomer.js:
--------------------------------------------------------------------------------
1 | /*
2 | * jQuery Zoomer v1.1
3 | *
4 | * By HubSpot >('_')<
5 | *
6 | * Licensed under the MIT license:
7 | * http://www.opensource.org/licenses/mit-license.php
8 | *
9 | * Example usage:
10 |
11 | $('iframe').zoomer({ width: 200, zoom: 0.5 });
12 |
13 | *
14 | */
15 |
16 | (function($){
17 |
18 | var methods,
19 | pluginName = 'zoomer',
20 | defaults = {
21 | width: 'auto',
22 | height: 'auto',
23 | zoom: 0.4,
24 | tranformOrigin: '0 0',
25 | //loading
26 | loadingType: 'message', // other type: 'spinner'
27 | loadingMessage: 'Generating preview...',
28 | spinnerURL: 'http://oi46.tinypic.com/6y375z.jpg', // requires loadingType: 'spinner'
29 | //hover
30 | message: 'Open Page',
31 | ieMessageButtonClass: 'btn btn-secondary', // used in IE only
32 | messageURL: false,
33 | onComplete: function() {}
34 | },
35 | visible = {
36 | visibility: 'visible'
37 | },
38 | invisible = {
39 | visibility: 'hidden'
40 | },
41 | unselectable = {
42 | '-webkit-user-select': 'none',
43 | '-khtml-user-select': 'none',
44 | '-moz-user-select': 'none',
45 | '-o-user-select': 'none',
46 | 'user-select': 'none',
47 | 'overflow': 'hidden'
48 | },
49 | absolute = {
50 | top: 0,
51 | position: 'absolute'
52 | },
53 | relative = {
54 | position: 'relative'
55 | },
56 | isMSIE = navigator.userAgent.match(/MSIE/),
57 | MSIEVersion = navigator.userAgent.match(/MSIE (\d\.\d+)/) ? parseInt(RegExp.$1, 10) : null
58 | ;
59 |
60 | methods = {
61 |
62 | init: function(opts) {
63 | return this.each(function(){
64 | var $el = $(this),
65 | options = $.extend({}, defaults, opts)
66 | ;
67 |
68 | options.src = $el.attr('src');
69 |
70 | $el.data(pluginName, options);
71 |
72 | $el[pluginName]('zoomer');
73 | });
74 | },
75 |
76 | zoomer: function() {
77 | var $el = $(this), options = $el.data(pluginName);
78 |
79 | $el
80 | .css(invisible)
81 | .css(unselectable)
82 | ;
83 |
84 | if (options.zoom === 'auto') {
85 | if (options.width === 'auto' && options.height === 'auto') {
86 | $.error('jQuery.zoomer: You must set either zoom or height and width.');
87 | return;
88 | }
89 | options.zoom = options.width / $(window).width();
90 | }
91 |
92 | if (options.width === 'auto') {
93 | options.width = $(window).height() * options.zoom;
94 | }
95 |
96 | if (options.height === 'auto') {
97 | options.height = $(window).height() * options.zoom;
98 | }
99 |
100 | if (options.loadingType === 'spinner') {
101 | options.loadingMessage = ' ';
102 | }
103 |
104 | //fix bug in older version of chrome:
105 | //http://stackoverflow.com/questions/5159713/
106 | if (navigator.userAgent.indexOf('Chrome/10.0.648') > -1) {
107 | options.zoom = Math.sqrt(1 / options.zoom);
108 | }
109 |
110 | options.externalSrc = true;
111 |
112 | try {
113 | if ($el.get(0).contentWindow.document) {
114 | options.externalSrc = false;
115 | }
116 | } catch (e) {}
117 |
118 | $el[pluginName]('setUpWrapper');
119 |
120 | $el[pluginName]('zoom');
121 |
122 | return $el;
123 | },
124 |
125 | setUpWrapper: function() {
126 | var $el = $(this), options = $el.data(pluginName);
127 |
128 | if (!$el.parents('.zoomer-wrapper').length) {
129 | $el
130 | .wrap(
131 | $('
')
132 | .addClass('zoomer-wrapper')
133 | .css(unselectable)
134 | .css(relative)
135 | )
136 | .wrap(
137 | $('
')
138 | .addClass('zoomer-small')
139 | .css(invisible)
140 | .css(unselectable)
141 | )
142 | ;
143 | }
144 |
145 | options.zoomerWrapper = $el.parents('.zoomer-wrapper');
146 |
147 | options.zoomerSmall = $el.parents('.zoomer-small');
148 |
149 | options.zoomerCover = $('
')
150 | .addClass('zoomer-cover')
151 | .css(unselectable)
152 | .css(absolute)
153 | .css({
154 | textAlign: 'center',
155 | fontSize: '15px'
156 | })
157 | ;
158 |
159 | options.zoomerLink = $(' ')
160 | .attr('target', '_blank')
161 | .html(options.message)
162 | .css({
163 | height: options.height,
164 | width: options.width,
165 | color: '#444',
166 | display: 'block',
167 | lineHeight: (parseInt(options.height, 10) - parseInt((options.height - 80) / 10, 10)) + 'px',
168 | textDecoration: 'none'
169 | })
170 | .css('background', '-moz-radial-gradient(center center, circle farthest-corner, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.4) 100%) repeat scroll 0 0 transparent')
171 | .css('background-image', '-webkit-gradient(radial, center center, 0, center center, ' + parseInt(options.width, 10) + ', from(rgba(255, 255, 255, 0.95)), to(rgba(255, 255, 255, 0.4)))')
172 | .mousedown(function(){
173 | $(this).css('box-shadow', 'inset 0px 2px 8px rgba(100, 100, 100, 0.4)');
174 | })
175 | .bind('mouseout mouseup', function(){
176 | $(this).css('box-shadow', 'none');
177 | })
178 | .hide()
179 | ;
180 |
181 | if (isMSIE) {
182 | options.zoomerLink.css({
183 | backgroundColor: 'rgba(255, 255, 255, 0.5)'
184 | });
185 | }
186 |
187 | if (options.click) {
188 | options.zoomerLink
189 | .attr('href', options.messageURL || options.src || '#')
190 | .unbind('click').bind('click', options.click)
191 | ;
192 | } else {
193 | options.zoomerLink.attr('href', options.messageURL || options.src);
194 | }
195 |
196 | options.zoomerCover
197 | .append(options.zoomerLink)
198 | .hover(function(){
199 | options.zoomerLink.show();
200 | $(this).css('box-shadow', 'inset 2px 2px ' + (parseInt(options.width, 10) * 2) + 'px rgba(255, 255, 255, 0.2)');
201 | }, function(){
202 | options.zoomerLink.hide();
203 | $(this).css('box-shadow', 'none');
204 | })
205 | .mousedown(function(){
206 | $(this).css('box-shadow', 'inset 2px 2px ' + (parseInt(options.width, 10) * 2) + 'px rgba(200, 200, 200, 0.8)');
207 | })
208 | .bind('mouseout mouseup', function(){
209 | $(this).css('box-shadow', 'none');
210 | })
211 | ;
212 |
213 | options.zoomerLoader = $('
')
214 | .addClass('zoomer-loader')
215 | .css(invisible)
216 | .css(unselectable)
217 | .css(absolute)
218 | .css({
219 | textAlign: 'center',
220 | fontSize: '15px',
221 | lineHeight: (parseInt(options.height, 10) - parseInt((options.height - 80) / 10, 10)) + 'px',
222 | background: '#fff'
223 | })
224 | .html(options.loadingMessage)
225 | ;
226 |
227 | options.zoomerWrapper
228 | .append(options.zoomerCover)
229 | .append(options.zoomerLoader)
230 | ;
231 |
232 | if (isMSIE) { options.zoomerLoader.css(invisible); }
233 |
234 | return $el[pluginName]('updateWrapper')[pluginName]('fadeOut');
235 | },
236 |
237 | updateWrapper: function() {
238 | var $el = $(this), options = $el.data(pluginName);
239 |
240 | $.each([options.zoomerWrapper.get(0), options.zoomerCover.get(0), options.zoomerLoader.get(0), options.zoomerSmall.get(0)], function(){
241 | $(this).css({
242 | height: options.height,
243 | width: options.width
244 | });
245 | });
246 |
247 | return $el;
248 | },
249 |
250 | fadeIn: function() {
251 | var $el = $(this), options = $el.data(pluginName);
252 |
253 | if (isMSIE) { return $el; }
254 |
255 | $el.css(invisible);
256 |
257 | options.zoomerSmall
258 | .stop()
259 | .css('opacity', 0)
260 | .css(visible)
261 | .animate({ 'opacity': 1 }, 150, function(){
262 | $el
263 | .css(visible)
264 | .css('opacity', 0)
265 | .animate({ 'opacity': 1 }, 500)
266 | ;
267 | })
268 | ;
269 |
270 | options.zoomerLoader
271 | .show()
272 | .animate({ 'opacity': 0 }, 300, function(){
273 | $(this).hide();
274 | })
275 | ;
276 |
277 | return $el;
278 | },
279 |
280 | fadeOut: function() {
281 | var $el = $(this), options = $el.data(pluginName);
282 |
283 | if (isMSIE) { return $el; }
284 |
285 | options.zoomerSmall
286 | .stop()
287 | .animate({ 'opacity': 0 }, 300, function(){
288 | $(this).css('visibility', 'hidden');
289 | })
290 | ;
291 |
292 | options.zoomerLoader
293 | .css('opacity', 0)
294 | .css(visible)
295 | .show()
296 | .animate({ opacity: 1 }, 100)
297 | ;
298 |
299 | return $el;
300 | },
301 |
302 | zoom: function() {
303 | var $el = $(this), options = $el.data(pluginName);
304 |
305 | if (isMSIE) {
306 | setTimeout(function(){
307 | $el
308 | .css({
309 | zoom: options.zoom,
310 | height: parseInt((options.height / options.zoom) * (1 / (MSIEVersion >= 9 ? 1 : options.zoom)), 10),
311 | width: parseInt((options.width / options.zoom) * (1 / (MSIEVersion >= 9 ? 1 : options.zoom)), 10)
312 | })
313 | .css(visible)
314 | ;
315 |
316 | options.zoomerLink.remove();
317 |
318 | options.zoomerCover
319 | .unbind('hover mouseover mouseout')
320 | .addClass(options.ieMessageButtonClass)
321 | .html(options.message)
322 | .css({
323 | width: 94,
324 | height: 14,
325 | fontSize: 12,
326 | padding: '6px 18px 6px 18px',
327 | top: parseInt(options.height - (12 + (2 * 6) + 2 + 10), 10),
328 | left: parseInt((options.width - (94 + (2 * 18))) / 2, 10)
329 | })
330 | .show()
331 | ;
332 |
333 | if (!options.click) {
334 | options.click = function() {
335 | location.href = options.messageURL || options.src;
336 | };
337 | }
338 |
339 | options.zoomerCover.unbind('click').bind('click', options.click);
340 |
341 | options.onComplete($el);
342 | }, 1000);
343 |
344 | return $el;
345 | }
346 |
347 | if (options.externalSrc) {
348 | $el
349 | .css({
350 | height: options.height / options.zoom,
351 | width: options.width / options.zoom,
352 | 'transform-origin': options.tranformOrigin,
353 | '-webkit-transform-origin': options.tranformOrigin,
354 | '-moz-transform-origin': options.tranformOrigin,
355 | '-o-transform-origin': options.tranformOrigin,
356 | 'transform': 'scale(' + options.zoom + ')',
357 | '-webkit-transform': 'scale(' + options.zoom + ')',
358 | '-moz-transform': 'scale(' + options.zoom + ')',
359 | '-o-transform': 'scale(' + options.zoom + ')'
360 | })
361 | .css(visible)
362 | ;
363 |
364 | $el[pluginName]('fadeIn');
365 |
366 | options.onComplete($el);
367 |
368 | return $el;
369 | }
370 |
371 | $el
372 | .css({
373 | height: options.height / options.zoom,
374 | width: options.width / options.zoom
375 | })
376 | .load(function(){
377 | $el.contents().find('html').css({
378 | 'transform-origin': options.tranformOrigin,
379 | '-webkit-transform-origin': options.tranformOrigin,
380 | '-moz-transform-origin': options.tranformOrigin,
381 | '-o-transform-origin': options.tranformOrigin,
382 | 'transform': 'scale(' + options.zoom + ')',
383 | '-webkit-transform': 'scale(' + options.zoom + ')',
384 | '-moz-transform': 'scale(' + options.zoom + ')',
385 | '-o-transform': 'scale(' + options.zoom + ')'
386 | });
387 |
388 | $el[pluginName]('fadeIn');
389 |
390 | options.onComplete($el);
391 | })
392 | ;
393 |
394 | return $el;
395 | },
396 |
397 | src: function(src) {
398 | var $el = $(this),
399 | options = $el.data(pluginName)
400 | ;
401 |
402 | options.src = src;
403 |
404 | $el[pluginName]('fadeOut').attr('src', src);
405 |
406 | return $el;
407 | },
408 |
409 | refresh: function() {
410 | var $el = $(this), options = $el.data(pluginName);
411 |
412 | return $el[pluginName]('src', options.src);
413 | },
414 |
415 | zoomedBodyHeight: function() {
416 | var $el = $(this), options = $el.data(pluginName);
417 |
418 | if (options.externalSrc) {
419 | return $.error('jQuery.zoomer: cannot access bodyHeight of an external iFrame');
420 | }
421 |
422 | return options.zoom * $($el.get(0).contentWindow.document).height();
423 | }
424 | };
425 |
426 | $.fn[pluginName] = function(options) {
427 | if (methods[options]) {
428 | return methods[options].apply(this, Array.prototype.slice.call(arguments, 1));
429 | } else if (typeof options === 'object' || ! options) {
430 | return methods.init.apply(this, arguments);
431 | } else {
432 | $.error('jQuery.' + pluginName + ': Method ' + options + ' does not exist');
433 | }
434 | };
435 |
436 | })(jQuery);
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery-zoomer",
3 | "description": "Zoom up your iFrames",
4 | "main": "jquery.zoomer.js",
5 | "keywords": [
6 | "jQuery Zoomer transform CSS"
7 | ],
8 | "author": {
9 | "name": "Adam Schwartz",
10 | "email": "aschwartzm@hubspot.com"
11 | },
12 | "license": "MIT"
13 | }
--------------------------------------------------------------------------------