PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Aplicacion/Contenido/js/facebox.js

#
JavaScript | 334 lines | 203 code | 43 blank | 88 comment | 44 complexity | c3222cb1e60ec161d3592184637ef3c4 MD5 | raw file
  1. /*
  2. * Facebox (for jQuery)
  3. * version: 1.2 (05/05/2008)
  4. * @requires jQuery v1.2 or later
  5. *
  6. * Examples at http://famspam.com/facebox/
  7. *
  8. * Licensed under the MIT:
  9. * http://www.opensource.org/licenses/mit-license.php
  10. *
  11. * Copyright 2007, 2008 Chris Wanstrath [ chris@ozmm.org ]
  12. *
  13. * Usage:
  14. *
  15. * jQuery(document).ready(function() {
  16. * jQuery('a[rel*=facebox]').facebox()
  17. * })
  18. *
  19. * <a href="#terms" rel="facebox">Terms</a>
  20. * Loads the #terms div in the box
  21. *
  22. * <a href="terms.html" rel="facebox">Terms</a>
  23. * Loads the terms.html page in the box
  24. *
  25. * <a href="terms.png" rel="facebox">Terms</a>
  26. * Loads the terms.png image in the box
  27. *
  28. *
  29. * You can also use it programmatically:
  30. *
  31. * jQuery.facebox('some html')
  32. *
  33. * The above will open a facebox with "some html" as the content.
  34. *
  35. * jQuery.facebox(function($) {
  36. * $.get('blah.html', function(data) { $.facebox(data) })
  37. * })
  38. *
  39. * The above will show a loading screen before the passed function is called,
  40. * allowing for a better ajaxy experience.
  41. *
  42. * The facebox function can also display an ajax page or image:
  43. *
  44. * jQuery.facebox({ ajax: 'remote.html' })
  45. * jQuery.facebox({ image: 'dude.jpg' })
  46. *
  47. * Want to close the facebox? Trigger the 'close.facebox' document event:
  48. *
  49. * jQuery(document).trigger('close.facebox')
  50. *
  51. * Facebox also has a bunch of other hooks:
  52. *
  53. * loading.facebox
  54. * beforeReveal.facebox
  55. * reveal.facebox (aliased as 'afterReveal.facebox')
  56. * init.facebox
  57. *
  58. * Simply bind a function to any of these hooks:
  59. *
  60. * $(document).bind('reveal.facebox', function() { ...stuff to do after the facebox and contents are revealed... })
  61. *
  62. */
  63. imageObj = new Image();
  64. images = new Array();
  65. images[0] = IMAGE_URL + 'facebox/b.png';
  66. images[1] = IMAGE_URL + 'facebox/bl.png';
  67. images[2] = IMAGE_URL + 'facebox/br.png';
  68. images[3] = IMAGE_URL + 'facebox/tl.png';
  69. images[4] = IMAGE_URL + 'facebox/tr.png';
  70. images[5] = IMAGE_URL + 'facebox/closelabel.gif';
  71. images[6] = IMAGE_URL + 'facebox/loading.gif';
  72. var i = 0;
  73. for (i = 0; i <= 6; i++) {
  74. imageObj.src = images[i];
  75. }
  76. (function($) {
  77. $.facebox = function(data, klass) {
  78. $.facebox.loading()
  79. if (data.ajax) fillFaceboxFromAjax(data.ajax)
  80. else if (data.image) fillFaceboxFromImage(data.image)
  81. else if (data.div) fillFaceboxFromHref(data.div)
  82. else if ($.isFunction(data)) data.call($)
  83. else $.facebox.reveal(data, klass)
  84. }
  85. /*
  86. * Public, $.facebox methods
  87. */
  88. $.extend($.facebox, {
  89. settings: {
  90. opacity : 0,
  91. overlay : true,
  92. loadingImage : IMAGE_URL + 'facebox/loading.gif',
  93. closeImage : IMAGE_URL + 'facebox/closelabel.gif',
  94. imageTypes : [ 'png', 'jpg', 'jpeg', 'gif' ],
  95. faceboxHtml : '\
  96. <div id="facebox" style="display:none;"> \
  97. <div class="popup"> \
  98. <table> \
  99. <tbody> \
  100. <tr> \
  101. <td class="tl"/><td class="b"/><td class="tr"/> \
  102. </tr> \
  103. <tr> \
  104. <td class="b"/> \
  105. <td class="body"> \
  106. <div class="content"> \
  107. </div> \
  108. <div class="footer"> \
  109. <a href="#" class="close"> \
  110. <img src=' + IMAGE_URL + '"facebox/closelabel.gif" title="close" class="close_image" /> \
  111. </a> \
  112. </div> \
  113. </td> \
  114. <td class="b"/> \
  115. </tr> \
  116. <tr> \
  117. <td class="bl"/><td class="b"/><td class="br"/> \
  118. </tr> \
  119. </tbody> \
  120. </table> \
  121. </div> \
  122. </div>'
  123. },
  124. loading: function() {
  125. init()
  126. if ($('#facebox .loading').length == 1) return true
  127. showOverlay()
  128. $('#facebox .content').empty()
  129. $('#facebox .body').children().hide().end().
  130. append('<div class="loading"><img src="'+$.facebox.settings.loadingImage+'"/></div>')
  131. $('#facebox').css({
  132. top: getPageScroll()[1] + (getPageHeight() / 10),
  133. left: 385.5
  134. }).show()
  135. $(document).bind('keydown.facebox', function(e) {
  136. if (e.keyCode == 27) $.facebox.close()
  137. return true
  138. })
  139. $(document).trigger('loading.facebox')
  140. },
  141. reveal: function(data, klass) {
  142. $(document).trigger('beforeReveal.facebox')
  143. if (klass) $('#facebox .content').addClass(klass)
  144. $('#facebox .content').append(data)
  145. $('#facebox .loading').remove()
  146. $('#facebox .body').children().fadeIn('normal')
  147. $('#facebox').css('left', $(window).width() / 2 - ($('#facebox table').width() / 2))
  148. $(document).trigger('reveal.facebox').trigger('afterReveal.facebox')
  149. },
  150. close: function() {
  151. $(document).trigger('close.facebox')
  152. return false
  153. }
  154. })
  155. /*
  156. * Public, $.fn methods
  157. */
  158. $.fn.facebox = function(settings) {
  159. init(settings)
  160. function clickHandler() {
  161. $.facebox.loading(true)
  162. // support for rel="facebox.inline_popup" syntax, to add a class
  163. // also supports deprecated "facebox[.inline_popup]" syntax
  164. var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
  165. if (klass) klass = klass[1]
  166. fillFaceboxFromHref(this.href, klass)
  167. return false
  168. }
  169. return this.click(clickHandler)
  170. }
  171. /*
  172. * Private methods
  173. */
  174. // called one time to setup facebox on this page
  175. function init(settings) {
  176. if ($.facebox.settings.inited) return true
  177. else $.facebox.settings.inited = true
  178. $(document).trigger('init.facebox')
  179. makeCompatible()
  180. var imageTypes = $.facebox.settings.imageTypes.join('|')
  181. $.facebox.settings.imageTypesRegexp = new RegExp('\.' + imageTypes + '$', 'i')
  182. if (settings) $.extend($.facebox.settings, settings)
  183. $('body').append($.facebox.settings.faceboxHtml)
  184. var preload = [ new Image(), new Image() ]
  185. preload[0].src = $.facebox.settings.closeImage
  186. preload[1].src = $.facebox.settings.loadingImage
  187. $('#facebox').find('.b:first, .bl, .br, .tl, .tr').each(function() {
  188. preload.push(new Image())
  189. preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
  190. })
  191. $('#facebox .close').click($.facebox.close)
  192. $('#facebox .close_image').attr('src', $.facebox.settings.closeImage)
  193. }
  194. // getPageScroll() by quirksmode.com
  195. function getPageScroll() {
  196. var xScroll, yScroll;
  197. if (self.pageYOffset) {
  198. yScroll = self.pageYOffset;
  199. xScroll = self.pageXOffset;
  200. } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
  201. yScroll = document.documentElement.scrollTop;
  202. xScroll = document.documentElement.scrollLeft;
  203. } else if (document.body) {// all other Explorers
  204. yScroll = document.body.scrollTop;
  205. xScroll = document.body.scrollLeft;
  206. }
  207. return new Array(xScroll,yScroll)
  208. }
  209. // Adapted from getPageSize() by quirksmode.com
  210. function getPageHeight() {
  211. var windowHeight
  212. if (self.innerHeight) { // all except Explorer
  213. windowHeight = self.innerHeight;
  214. } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
  215. windowHeight = document.documentElement.clientHeight;
  216. } else if (document.body) { // other Explorers
  217. windowHeight = document.body.clientHeight;
  218. }
  219. return windowHeight
  220. }
  221. // Backwards compatibility
  222. function makeCompatible() {
  223. var $s = $.facebox.settings
  224. $s.loadingImage = $s.loading_image || $s.loadingImage
  225. $s.closeImage = $s.close_image || $s.closeImage
  226. $s.imageTypes = $s.image_types || $s.imageTypes
  227. $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml
  228. }
  229. // Figures out what you want to display and displays it
  230. // formats are:
  231. // div: #id
  232. // image: blah.extension
  233. // ajax: anything else
  234. function fillFaceboxFromHref(href, klass) {
  235. // div
  236. if (href.match(/#/)) {
  237. var url = window.location.href.split('#')[0]
  238. var target = href.replace(url,'')
  239. $.facebox.reveal($(target).clone().show(), klass)
  240. // image
  241. } else if (href.match($.facebox.settings.imageTypesRegexp)) {
  242. fillFaceboxFromImage(href, klass)
  243. // ajax
  244. } else {
  245. fillFaceboxFromAjax(href, klass)
  246. }
  247. }
  248. function fillFaceboxFromImage(href, klass) {
  249. var image = new Image()
  250. image.onload = function() {
  251. $.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
  252. }
  253. image.src = href
  254. }
  255. function fillFaceboxFromAjax(href, klass) {
  256. $.get(href, function(data) { $.facebox.reveal(data, klass) })
  257. }
  258. function skipOverlay() {
  259. return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null
  260. }
  261. function showOverlay() {
  262. if (skipOverlay()) return
  263. if ($('facebox_overlay').length == 0)
  264. $("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')
  265. $('#facebox_overlay').hide().addClass("facebox_overlayBG")
  266. .css('opacity', $.facebox.settings.opacity)
  267. .click(function() { $(document).trigger('close.facebox') })
  268. .fadeIn(200)
  269. return false
  270. }
  271. function hideOverlay() {
  272. if (skipOverlay()) return
  273. $('#facebox_overlay').fadeOut(200, function(){
  274. $("#facebox_overlay").removeClass("facebox_overlayBG")
  275. $("#facebox_overlay").addClass("facebox_hide")
  276. $("#facebox_overlay").remove()
  277. })
  278. return false
  279. }
  280. /*
  281. * Bindings
  282. */
  283. $(document).bind('close.facebox', function() {
  284. $(document).unbind('keydown.facebox')
  285. $('#facebox').fadeOut(function() {
  286. $('#facebox .content').removeClass().addClass('content')
  287. hideOverlay()
  288. $('#facebox .loading').remove()
  289. })
  290. })
  291. })(jQuery);