source: trunk/www.guidonia.net/wp/wp-content/plugins/tubepress/ui/players/colorbox/lib/jquery.colorbox.js@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 12.1 KB
Line 
1/*
2
3 ColorBox v1.1.6 - a full featured, light-weight, customizable lightbox based on jQuery 1.3
4
5 (c) 2009 Jack Moore - www.colorpowered.com - jack@colorpowered.com
6
7 Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
8
9*/
10
11
12
13(function(jQuery){
14
15var settings, loadedWidth, loadedHeight, interfaceHeight, interfaceWidth, index, related, loadingElement, $modal, modalWrap, $loadingOverlay, $overlay, $modalContent, $loaded, $close, $borderTopCenter, $borderMiddleLeft, $borderMiddleRight, $borderBottomCenter;
16
17function setModalOverlay(){
18
19 $overlay.css({"position":"absolute", width:jQuery(window).width(), height:jQuery(window).height(), top:jQuery(window).scrollTop(), left:jQuery(window).scrollLeft()});
20
21}
22
23function keypressEvents(e){
24
25 if(e.keyCode == 37){
26
27 e.preventDefault();
28
29 jQuery(document).unbind('keydown', keypressEvents);
30
31 jQuery("a#contentPrevious").click();
32
33 } else if(e.keyCode == 39){
34
35 e.preventDefault();
36
37 jQuery(document).unbind('keydown', keypressEvents);
38
39 jQuery("a#contentNext").click();
40
41 }
42
43}
44
45function clearLoading(){
46
47 if(jQuery("#colorboxInlineTemp").length > 0){
48
49 $loaded.children().insertAfter("#colorboxInlineTemp");
50
51 }
52
53 if(loadingElement){jQuery(loadingElement).remove();}
54
55}
56
57
58
59// Convert % values to pixels
60
61function setSize(size, dimension){
62
63 return (typeof size == 'string') ? (size.match(/%/) ? (dimension/100)*parseInt(size, 10) : parseInt(size, 10)) : size;
64
65}
66
67
68
69/*
70
71 Initialize the modal: store common calculations, preload the interface graphics, append the html.
72
73 This preps colorbox for a speedy open when clicked, and lightens the burdon on the browser by only
74
75 having to run once, instead of each time colorbox is opened.
76
77*/
78
79jQuery(function(){//jQuery shortcut for jQuery(document).ready(function(){});
80
81 jQuery("body").append(
82
83 $overlay = jQuery('<div id="modalBackgroundOverlay" />').hide(),
84
85 $modal = jQuery('<div id="colorbox" />').css("opacity", 0)
86
87 );
88
89
90
91 jQuery('<div id="modalWrap" />').appendTo($modal).append(
92
93 jQuery('<div><div id="borderTopLeft" /><div id="borderTopCenter" /><div id="borderTopRight" /></div>'),
94
95 $borderMiddleLeft = jQuery('<div id="borderMiddleLeft" />'),
96
97 $modalContent = jQuery('<div id="modalContent" />'),
98
99 $borderMiddleRight = jQuery('<div id="borderMiddleRight" />'),
100
101 jQuery('<div><div id="borderBottomLeft" /><div id="borderBottomCenter" /><div id="borderBottomRight" /></div>')
102
103 );
104
105 $modalContent.append(
106
107 //loaded is filled with temporary HTML to allow the CSS backgrounds for those elements to load before ColorBox is actually called.
108
109 $loaded = jQuery('<div id="modalLoadedContent"><span id="contentTitle"></span></div>'),
110
111 $loadingOverlay = jQuery('<div id="modalLoadingOverlay" />'),
112
113 $close = jQuery('<a id="modalClose" href="#"></a>')
114
115 );
116
117
118
119 jQuery(document).bind("keydown.colorClose", function(e){
120
121 if (e.keyCode == 27) {
122
123 e.preventDefault();
124
125 jQuery.fn.colorbox.close();
126
127 }
128
129 });
130
131
132
133 $close.click(function(event){
134
135 event.preventDefault();
136
137 jQuery.fn.colorbox.close();
138
139 });
140
141
142
143 $borderTopCenter = jQuery("#borderTopCenter");
144
145 $borderBottomCenter = jQuery("#borderBottomCenter");
146
147
148
149 interfaceHeight = $borderTopCenter.height()+$borderBottomCenter.height()+$modalContent.outerHeight(true) - $modalContent.height();//Subtraction needed for IE6
150
151 interfaceWidth = $borderMiddleLeft.width()+$borderMiddleRight.width()+$modalContent.outerWidth(true) - $modalContent.width();
152
153
154
155 loadedHeight = $loaded.outerHeight(true);
156
157 loadedWidth = $loaded.outerWidth(true);
158
159
160
161 $loaded.empty();
162
163 $modal.css({"padding-bottom":interfaceHeight,"padding-right":interfaceWidth}).hide();//the padding removes the need to do size conversions during the animation step.
164
165
166
167 //Archaic rollover code because IE8 is a piece of shit. Hopefully they'll fix their css-rollover bug so the following code can be removed.
168
169 jQuery("#contentPrevious, #contentNext, #modalClose").live('mouseover', function(){jQuery(this).addClass("hover");});
170
171 jQuery("#contentPrevious, #contentNext, #modalClose").live('mouseout', function(){jQuery(this).removeClass("hover");});
172
173});
174
175
176
177jQuery.fn.colorbox = function(settings, callback) {
178
179
180
181 function modalPosition(mWidth, mHeight, speed, loadedCallback){
182
183
184
185 var winHeight = document.documentElement.clientHeight;
186
187 var posTop = winHeight/2 - mHeight/2;
188
189 var posLeft = document.documentElement.clientWidth/2 - mWidth/2;
190
191 //keeps the box from expanding to an inaccessible area offscreen.
192
193 if(mHeight > winHeight){posTop -=(mHeight - winHeight);}
194
195 if(posTop < 0){posTop = 0;}
196
197 if(posLeft < 0){posLeft = 0;}
198
199
200
201 posTop+=jQuery(window).scrollTop();
202
203 posLeft+=jQuery(window).scrollLeft();
204
205
206
207 mWidth = mWidth - interfaceWidth;
208
209 mHeight = mHeight - interfaceHeight;
210
211
212
213 function modalDimensions(that){
214
215 $modalContent[0].style.width = $borderTopCenter[0].style.width = $borderBottomCenter[0].style.width = that.style.width;
216
217 $modalContent[0].style.height = $borderMiddleLeft[0].style.height = $borderMiddleRight[0].style.height = that.style.height;
218
219 }
220
221
222
223 $modal.animate({height:mHeight, width:mWidth, top:posTop, left:posLeft}, {duration: speed,
224
225 complete: function(){
226
227 if (loadedCallback) {loadedCallback();}
228
229 modalDimensions(this);
230
231 if (jQuery.browser.msie && jQuery.browser.version < 7) {setModalOverlay();}
232
233 },
234
235 step: function(){
236
237 modalDimensions(this);
238
239 }
240
241 });
242
243 }
244
245 var preloads = [];
246
247 function preload(){
248
249
250
251 return false;
252
253 }
254
255
256
257 function contentNav(){
258
259 $loadingOverlay.show();
260
261 if(jQuery(this).attr("id") == "contentPrevious"){
262
263 index = index > 0 ? index-1 : related.length-1;
264
265 } else {
266
267 index = index < related.length-1 ? index+1 : 0;
268
269 }
270
271 loadModal(related[index].href, related[index].title);
272
273 return false;
274
275 }
276
277
278
279 function centerModal (object, contentInfo){
280
281 if($modal.data("open")!==true){ return false; }
282
283
284
285 var speed = settings.transition=="none" ? 0 : settings.transitionSpeed;
286
287 $loaded.remove();
288
289 $loaded = jQuery(object);
290
291
292
293 $loaded.hide()
294
295 .appendTo('body')
296
297 .css({width:(settings.fixedWidth)?settings.fixedWidth - loadedWidth - interfaceWidth:$loaded.width()}).css({height:(settings.fixedHeight)?settings.fixedHeight - loadedHeight - interfaceHeight:$loaded.height()})
298
299 .attr({id:"modalLoadedContent"})
300
301 .append(contentInfo)
302
303 .prependTo($modalContent);
304
305
306
307 if(jQuery("#modalPhoto").length > 0 && settings.fixedHeight){
308
309 var topMargin = (parseInt($loaded[0].style.height, 10) - parseInt(jQuery("#modalPhoto")[0].style.height, 10))/2;
310
311 jQuery("#modalPhoto").css({marginTop:(topMargin > 0?topMargin:0)});
312
313 }
314
315
316
317 function setPosition(s){
318
319 modalPosition(parseInt($loaded[0].style.width, 10)+loadedWidth+interfaceWidth, parseInt($loaded[0].style.height, 10)+loadedHeight+interfaceHeight, s, function(){
320
321 if($modal.data("open")!==true){
322
323 return false;
324
325 }
326
327 $loaded.show();
328
329 $loadingOverlay.hide();
330
331 jQuery(document).bind('keydown', keypressEvents);
332
333 if (callback) {
334
335 callback();
336
337 }
338
339 if (settings.transition === "fade"){
340
341 $modal.animate({"opacity":1}, speed);
342
343 }
344
345 return true;
346
347 });
348
349 }
350
351 if (settings.transition == "fade") {
352
353 $modal.animate({"opacity":0}, speed, function(){setPosition(0);});
354
355 } else {
356
357 setPosition(speed);
358
359 }
360
361 var preloads = preload();
362
363 return true;
364
365 }
366
367
368
369 function loadModal(href, title){
370
371 clearLoading();
372
373 var contentInfo = "<p id='contentTitle'>"+title+"</p>";
374
375
376 if (settings.inline) {
377
378 loadingElement = jQuery('<div id="colorboxInlineTemp" />').hide().insertBefore(jQuery(href)[0]);
379
380 centerModal(jQuery(href).wrapAll("<div />").parent(), contentInfo);
381
382
383 }
384
385 }
386
387
388
389 settings = jQuery.extend({}, jQuery.fn.colorbox.settings, settings);
390
391
392
393 jQuery(this).unbind("click.colorbox").bind("click.colorbox", function () {
394
395 if(settings.fixedWidth){ settings.fixedWidth = setSize(settings.fixedWidth, document.documentElement.clientWidth);}
396
397 if(settings.fixedHeight){ settings.fixedHeight = setSize(settings.fixedHeight, document.documentElement.clientHeight);}
398
399 if (this.rel && 'nofollow' != this.rel) {
400
401 related = jQuery("a[rel='" + this.rel + "']");
402
403 index = jQuery(related).index(this);
404
405 }
406
407 else {
408
409 related = jQuery(this);
410
411 index = 0;
412
413 }
414
415
416
417 if ($modal.data("open") !== true) {
418
419 jQuery(document).bind('keydown', keypressEvents);
420
421 $close.html(settings.modalClose);
422
423 $overlay.css({"opacity": settings.bgOpacity}).show();
424
425 $modal.data("open", true).css({"opacity":1});
426
427
428
429 modalPosition(setSize(settings.initialWidth, document.documentElement.clientWidth), setSize(settings.initialHeight, document.documentElement.clientHeight), 0);
430
431
432
433 if (jQuery.browser.msie && jQuery.browser.version < 7) {
434
435 jQuery(window).bind("resize scroll", setModalOverlay);
436
437 }
438
439 }
440
441
442
443 loadModal(settings.href ? settings.href : related[index].href, settings.title ? settings.title : related[index].title);
444
445 jQuery("a#contentPrevious, a#contentNext").die().live("click", contentNav);
446
447
448
449 if(settings.overlayClose!==false){
450
451 $overlay.css({"cursor":"pointer"}).click(function(){jQuery.fn.colorbox.close();});
452
453 }
454
455 return false;
456
457 });
458
459
460
461 if(settings.open!==false && $modal.data("open")!==true){
462
463 jQuery(this).triggerHandler('click.colorbox');
464
465 }
466
467
468
469 return this.each(function() {
470
471 });
472
473};
474
475
476
477//public function for closing colorbox. To use this within an iframe use the following format: parent.jQuery.fn.colorbox.close();
478
479jQuery.fn.colorbox.close = function(){
480
481
482
483 jQuery('#contentTitle').remove();
484
485 clearLoading();
486
487 $overlay.css({cursor:"auto"}).fadeOut("fast");
488
489 $modal.stop(true, false).removeData("open").fadeOut("fast", function(){
490
491 $loaded.remove();
492
493 });
494
495 jQuery(document).unbind('keydown', keypressEvents);
496
497 jQuery(window).unbind('resize scroll', setModalOverlay);
498
499 return false;
500
501};
502
503
504
505/*
506
507 ColorBox Default Settings.
508
509
510
511 The colorbox() function takes one argument, an object of key/value pairs, that are used to initialize the modal.
512
513
514
515 Please do not change these settings here, instead overwrite these settings when attaching the colorbox() event to your anchors.
516
517 Example (Global) : jQuery.fn.colorbox.settings.transition = "fade"; //changes the transition to fade for all colorBox() events proceeding it's declaration.
518
519 Example (Specific) : jQuery("a[href='http://www.google.com']").colorbox({fixedWidth:"90%", fixedHeight:"450px", iframe:true});
520
521*/
522
523jQuery.fn.colorbox.settings = {
524
525 transition : "elastic", // Transition types: "elastic", "fade", or "none".
526
527 transitionSpeed : 350, // Sets the speed of the fade and elastic transitions, in milliseconds.
528
529 initialWidth : "400", // Set the initial width of the modal, prior to any content being loaded.
530
531 initialHeight : "400", // Set the initial height of the modal, prior to any content being loaded.
532
533 fixedWidth : false, // Set a fixed width for div#loaded. Example: "500px"
534
535 fixedHeight : false, // Set a fixed height for div#modalLoadedContent. Example: "500px"
536
537 inline : false, // Set this to the selector of inline content to be displayed. Example "#myHiddenDiv" or "body p".
538
539 iframe : false, // If 'true' specifies that content should be displayed in an iFrame.
540
541 href : false, // This can be used as an alternate anchor URL for ColorBox to use, or can be used to assign a URL for non-anchor elments such as images or form buttons.
542
543 title : false, // This can be used as an alternate anchor title.
544
545 bgOpacity : 0.85, // The modalBackgroundOverlay opacity level. Range: 0 to 1.
546
547 preloading : true, // Allows for preloading of 'Next' and 'Previous' content in a shared relation group (same values for the 'rel' attribute), after the current content has finished loading. Set to 'false' to disable.
548
549 contentCurrent : "image {current} of {total}", // the format of the contentCurrent information
550
551 contentPrevious : "previous", // the anchor text for the previous link in a shared relation group (same values for 'rel').
552
553 contentNext : "next", // the anchor text for the next link in a shared relation group (same 'rel' attribute').
554
555 modalClose : "close", // the anchor text for the close link. Esc will also close the modal.
556
557 open : false, //Automatically opens ColorBox. (fires the click.colorbox event without waiting for user input).
558
559 overlayClose : true //If true, enables closing ColorBox by clicking on the background overlay.
560
561};
562
563
564
565})(jQuery);
566
567
568
Note: See TracBrowser for help on using the repository browser.