script.js 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050
  1. /* http://cantbuymelove.org */
  2. /*
  3. * FancyBox - jQuery Plugin
  4. * Simple and fancy lightbox alternative
  5. *
  6. * Examples and documentation at: http://fancybox.net
  7. *
  8. * Copyright (c) 2008 - 2010 Janis Skarnelis
  9. * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
  10. *
  11. * Version: 1.3.4 (11/11/2010)
  12. * Requires: jQuery v1.3+
  13. *
  14. * Dual licensed under the MIT and GPL licenses:
  15. * http://www.opensource.org/licenses/mit-license.php
  16. * http://www.gnu.org/licenses/gpl.html
  17. */
  18. ;(function($) {
  19. var tmp, loading, overlay, wrap, outer, content, close, title, nav_left, nav_right,
  20. selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [],
  21. ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i,
  22. loadingTimer, loadingFrame = 1,
  23. titleHeight = 0, titleStr = '', start_pos, final_pos, busy = false, fx = $.extend($('<div/>')[0], { prop: 0 }),
  24. isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest,
  25. /*
  26. * Private methods
  27. */
  28. _abort = function() {
  29. loading.hide();
  30. imgPreloader.onerror = imgPreloader.onload = null;
  31. if (ajaxLoader) {
  32. ajaxLoader.abort();
  33. }
  34. tmp.empty();
  35. },
  36. _error = function() {
  37. if (false === selectedOpts.onError(selectedArray, selectedIndex, selectedOpts)) {
  38. loading.hide();
  39. busy = false;
  40. return;
  41. }
  42. selectedOpts.titleShow = false;
  43. selectedOpts.width = 'auto';
  44. selectedOpts.height = 'auto';
  45. tmp.html( '<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>' );
  46. _process_inline();
  47. },
  48. _start = function() {
  49. var obj = selectedArray[ selectedIndex ],
  50. href,
  51. type,
  52. title,
  53. str,
  54. emb,
  55. ret;
  56. _abort();
  57. selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox')));
  58. ret = selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts);
  59. if (ret === false) {
  60. busy = false;
  61. return;
  62. } else if (typeof ret == 'object') {
  63. selectedOpts = $.extend(selectedOpts, ret);
  64. }
  65. title = selectedOpts.title || (obj.nodeName ? $(obj).attr('title') : obj.title) || '';
  66. if (obj.nodeName && !selectedOpts.orig) {
  67. selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj);
  68. }
  69. if (title === '' && selectedOpts.orig && selectedOpts.titleFromAlt) {
  70. title = selectedOpts.orig.attr('alt');
  71. }
  72. href = selectedOpts.href || (obj.nodeName ? $(obj).attr('href') : obj.href) || null;
  73. if ((/^(?:javascript)/i).test(href) || href == '#') {
  74. href = null;
  75. }
  76. if (selectedOpts.type) {
  77. type = selectedOpts.type;
  78. if (!href) {
  79. href = selectedOpts.content;
  80. }
  81. } else if (selectedOpts.content) {
  82. type = 'html';
  83. } else if (href) {
  84. if (href.match(imgRegExp)) {
  85. type = 'image';
  86. } else if (href.match(swfRegExp)) {
  87. type = 'swf';
  88. } else if ($(obj).hasClass("iframe")) {
  89. type = 'iframe';
  90. } else if (href.indexOf("#") === 0) {
  91. type = 'inline';
  92. } else {
  93. type = 'ajax';
  94. }
  95. }
  96. if (!type) {
  97. _error();
  98. return;
  99. }
  100. if (type == 'inline') {
  101. obj = href.substr(href.indexOf("#"));
  102. type = $(obj).length > 0 ? 'inline' : 'ajax';
  103. }
  104. selectedOpts.type = type;
  105. selectedOpts.href = href;
  106. selectedOpts.title = title;
  107. if (selectedOpts.autoDimensions) {
  108. if (selectedOpts.type == 'html' || selectedOpts.type == 'inline' || selectedOpts.type == 'ajax') {
  109. selectedOpts.width = 'auto';
  110. selectedOpts.height = 'auto';
  111. } else {
  112. selectedOpts.autoDimensions = false;
  113. }
  114. }
  115. if (selectedOpts.modal) {
  116. selectedOpts.overlayShow = true;
  117. selectedOpts.hideOnOverlayClick = false;
  118. selectedOpts.hideOnContentClick = false;
  119. selectedOpts.enableEscapeButton = false;
  120. selectedOpts.showCloseButton = false;
  121. }
  122. selectedOpts.padding = parseInt(selectedOpts.padding, 10);
  123. selectedOpts.margin = parseInt(selectedOpts.margin, 10);
  124. tmp.css('padding', (selectedOpts.padding + selectedOpts.margin));
  125. $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() {
  126. $(this).replaceWith(content.children());
  127. });
  128. switch (type) {
  129. case 'html' :
  130. tmp.html( selectedOpts.content );
  131. _process_inline();
  132. break;
  133. case 'inline' :
  134. if ( $(obj).parent().is('#fancybox-content') === true) {
  135. busy = false;
  136. return;
  137. }
  138. $('<div class="fancybox-inline-tmp" />')
  139. .hide()
  140. .insertBefore( $(obj) )
  141. .bind('fancybox-cleanup', function() {
  142. $(this).replaceWith(content.children());
  143. }).bind('fancybox-cancel', function() {
  144. $(this).replaceWith(tmp.children());
  145. });
  146. $(obj).appendTo(tmp);
  147. _process_inline();
  148. break;
  149. case 'image':
  150. busy = false;
  151. $.fancybox.showActivity();
  152. imgPreloader = new Image();
  153. imgPreloader.onerror = function() {
  154. _error();
  155. };
  156. imgPreloader.onload = function() {
  157. busy = true;
  158. imgPreloader.onerror = imgPreloader.onload = null;
  159. _process_image();
  160. };
  161. imgPreloader.src = href;
  162. break;
  163. case 'swf':
  164. selectedOpts.scrolling = 'no';
  165. str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"><param name="movie" value="' + href + '"></param>';
  166. emb = '';
  167. $.each(selectedOpts.swf, function(name, val) {
  168. str += '<param name="' + name + '" value="' + val + '"></param>';
  169. emb += ' ' + name + '="' + val + '"';
  170. });
  171. str += '<embed src="' + href + '" type="application/x-shockwave-flash" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"' + emb + '></embed></object>';
  172. tmp.html(str);
  173. _process_inline();
  174. break;
  175. case 'ajax':
  176. busy = false;
  177. $.fancybox.showActivity();
  178. selectedOpts.ajax.win = selectedOpts.ajax.success;
  179. ajaxLoader = $.ajax($.extend({}, selectedOpts.ajax, {
  180. url : href,
  181. data : selectedOpts.ajax.data || {},
  182. error : function(XMLHttpRequest, textStatus, errorThrown) {
  183. if ( XMLHttpRequest.status > 0 ) {
  184. _error();
  185. }
  186. },
  187. success : function(data, textStatus, XMLHttpRequest) {
  188. var o = typeof XMLHttpRequest == 'object' ? XMLHttpRequest : ajaxLoader;
  189. if (o.status == 200) {
  190. if ( typeof selectedOpts.ajax.win == 'function' ) {
  191. ret = selectedOpts.ajax.win(href, data, textStatus, XMLHttpRequest);
  192. if (ret === false) {
  193. loading.hide();
  194. return;
  195. } else if (typeof ret == 'string' || typeof ret == 'object') {
  196. data = ret;
  197. }
  198. }
  199. tmp.html( data );
  200. _process_inline();
  201. }
  202. }
  203. }));
  204. break;
  205. case 'iframe':
  206. _show();
  207. break;
  208. }
  209. },
  210. _process_inline = function() {
  211. var
  212. w = selectedOpts.width,
  213. h = selectedOpts.height;
  214. if (w.toString().indexOf('%') > -1) {
  215. w = parseInt( ($(window).width() - (selectedOpts.margin * 2)) * parseFloat(w) / 100, 10) + 'px';
  216. } else {
  217. w = w == 'auto' ? 'auto' : w + 'px';
  218. }
  219. if (h.toString().indexOf('%') > -1) {
  220. h = parseInt( ($(window).height() - (selectedOpts.margin * 2)) * parseFloat(h) / 100, 10) + 'px';
  221. } else {
  222. h = h == 'auto' ? 'auto' : h + 'px';
  223. }
  224. tmp.wrapInner('<div style="width:' + w + ';height:' + h + ';overflow: ' + (selectedOpts.scrolling == 'auto' ? 'auto' : (selectedOpts.scrolling == 'yes' ? 'scroll' : 'hidden')) + ';position:relative;"></div>');
  225. selectedOpts.width = tmp.width();
  226. selectedOpts.height = tmp.height();
  227. _show();
  228. },
  229. _process_image = function() {
  230. selectedOpts.width = imgPreloader.width;
  231. selectedOpts.height = imgPreloader.height;
  232. $("<img />").attr({
  233. 'id' : 'fancybox-img',
  234. 'src' : imgPreloader.src,
  235. 'alt' : selectedOpts.title
  236. }).appendTo( tmp );
  237. _show();
  238. },
  239. _show = function() {
  240. var pos, equal;
  241. loading.hide();
  242. if (wrap.is(":visible") && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) {
  243. $.event.trigger('fancybox-cancel');
  244. busy = false;
  245. return;
  246. }
  247. busy = true;
  248. $(content.add( overlay )).unbind();
  249. $(window).unbind("resize.fb scroll.fb");
  250. $(document).unbind('keydown.fb');
  251. if (wrap.is(":visible") && currentOpts.titlePosition !== 'outside') {
  252. wrap.css('height', wrap.height());
  253. }
  254. currentArray = selectedArray;
  255. currentIndex = selectedIndex;
  256. currentOpts = selectedOpts;
  257. if (currentOpts.overlayShow) {
  258. overlay.css({
  259. 'background-color' : currentOpts.overlayColor,
  260. 'opacity' : currentOpts.overlayOpacity,
  261. 'cursor' : currentOpts.hideOnOverlayClick ? 'pointer' : 'auto',
  262. 'height' : $(document).height()
  263. });
  264. if (!overlay.is(':visible')) {
  265. if (isIE6) {
  266. $('select:not(#fancybox-tmp select)').filter(function() {
  267. return this.style.visibility !== 'hidden';
  268. }).css({'visibility' : 'hidden'}).one('fancybox-cleanup', function() {
  269. this.style.visibility = 'inherit';
  270. });
  271. }
  272. overlay.show();
  273. }
  274. } else {
  275. overlay.hide();
  276. }
  277. final_pos = _get_zoom_to();
  278. _process_title();
  279. if (wrap.is(":visible")) {
  280. $( close.add( nav_left ).add( nav_right ) ).hide();
  281. pos = wrap.position(),
  282. start_pos = {
  283. top : pos.top,
  284. left : pos.left,
  285. width : wrap.width(),
  286. height : wrap.height()
  287. };
  288. equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height);
  289. content.fadeTo(currentOpts.changeFade, 0.3, function() {
  290. var finish_resizing = function() {
  291. content.html( tmp.contents() ).fadeTo(currentOpts.changeFade, 1, _finish);
  292. };
  293. $.event.trigger('fancybox-change');
  294. content
  295. .empty()
  296. .removeAttr('filter')
  297. .css({
  298. 'border-width' : currentOpts.padding,
  299. 'width' : final_pos.width - currentOpts.padding * 2,
  300. 'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2
  301. });
  302. if (equal) {
  303. finish_resizing();
  304. } else {
  305. fx.prop = 0;
  306. $(fx).animate({prop: 1}, {
  307. duration : currentOpts.changeSpeed,
  308. easing : currentOpts.easingChange,
  309. step : _draw,
  310. complete : finish_resizing
  311. });
  312. }
  313. });
  314. return;
  315. }
  316. wrap.removeAttr("style");
  317. content.css('border-width', currentOpts.padding);
  318. if (currentOpts.transitionIn == 'elastic') {
  319. start_pos = _get_zoom_from();
  320. content.html( tmp.contents() );
  321. wrap.show();
  322. if (currentOpts.opacity) {
  323. final_pos.opacity = 0;
  324. }
  325. fx.prop = 0;
  326. $(fx).animate({prop: 1}, {
  327. duration : currentOpts.speedIn,
  328. easing : currentOpts.easingIn,
  329. step : _draw,
  330. complete : _finish
  331. });
  332. return;
  333. }
  334. if (currentOpts.titlePosition == 'inside' && titleHeight > 0) {
  335. title.show();
  336. }
  337. content
  338. .css({
  339. 'width' : final_pos.width - currentOpts.padding * 2,
  340. 'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2
  341. })
  342. .html( tmp.contents() );
  343. wrap
  344. .css(final_pos)
  345. .fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish );
  346. },
  347. _format_title = function(title) {
  348. if (title && title.length) {
  349. if (currentOpts.titlePosition == 'float') {
  350. return '<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">' + title + '</td><td id="fancybox-title-float-right"></td></tr></table>';
  351. }
  352. return '<div id="fancybox-title-' + currentOpts.titlePosition + '">' + title + '</div>';
  353. }
  354. return false;
  355. },
  356. _process_title = function() {
  357. titleStr = currentOpts.title || '';
  358. titleHeight = 0;
  359. title
  360. .empty()
  361. .removeAttr('style')
  362. .removeClass();
  363. if (currentOpts.titleShow === false) {
  364. title.hide();
  365. return;
  366. }
  367. titleStr = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(titleStr, currentArray, currentIndex, currentOpts) : _format_title(titleStr);
  368. if (!titleStr || titleStr === '') {
  369. title.hide();
  370. return;
  371. }
  372. title
  373. .addClass('fancybox-title-' + currentOpts.titlePosition)
  374. .html( titleStr )
  375. .appendTo( 'body' )
  376. .show();
  377. switch (currentOpts.titlePosition) {
  378. case 'inside':
  379. title
  380. .css({
  381. 'width' : final_pos.width - (currentOpts.padding * 2),
  382. 'marginLeft' : currentOpts.padding,
  383. 'marginRight' : currentOpts.padding
  384. });
  385. titleHeight = title.outerHeight(true);
  386. title.appendTo( outer );
  387. final_pos.height += titleHeight;
  388. break;
  389. case 'over':
  390. title
  391. .css({
  392. 'marginLeft' : currentOpts.padding,
  393. 'width' : final_pos.width - (currentOpts.padding * 2),
  394. 'bottom' : currentOpts.padding
  395. })
  396. .appendTo( outer );
  397. break;
  398. case 'float':
  399. title
  400. .css('left', parseInt((title.width() - final_pos.width - 40)/ 2, 10) * -1)
  401. .appendTo( wrap );
  402. break;
  403. default:
  404. title
  405. .css({
  406. 'width' : final_pos.width - (currentOpts.padding * 2),
  407. 'paddingLeft' : currentOpts.padding,
  408. 'paddingRight' : currentOpts.padding
  409. })
  410. .appendTo( wrap );
  411. break;
  412. }
  413. title.hide();
  414. },
  415. _set_navigation = function() {
  416. if (currentOpts.enableEscapeButton || currentOpts.enableKeyboardNav) {
  417. $(document).bind('keydown.fb', function(e) {
  418. if (e.keyCode == 27 && currentOpts.enableEscapeButton) {
  419. e.preventDefault();
  420. $.fancybox.close();
  421. } else if ((e.keyCode == 37 || e.keyCode == 39) && currentOpts.enableKeyboardNav && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') {
  422. e.preventDefault();
  423. $.fancybox[ e.keyCode == 37 ? 'prev' : 'next']();
  424. }
  425. });
  426. }
  427. if (!currentOpts.showNavArrows) {
  428. nav_left.hide();
  429. nav_right.hide();
  430. return;
  431. }
  432. if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) {
  433. nav_left.show();
  434. }
  435. if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) {
  436. nav_right.show();
  437. }
  438. },
  439. _finish = function () {
  440. if (!$.support.opacity) {
  441. content.get(0).style.removeAttribute('filter');
  442. wrap.get(0).style.removeAttribute('filter');
  443. }
  444. if (selectedOpts.autoDimensions) {
  445. content.css('height', 'auto');
  446. }
  447. wrap.css('height', 'auto');
  448. if (titleStr && titleStr.length) {
  449. title.show();
  450. }
  451. if (currentOpts.showCloseButton) {
  452. close.show();
  453. }
  454. _set_navigation();
  455. if (currentOpts.hideOnContentClick) {
  456. content.bind('click', $.fancybox.close);
  457. }
  458. if (currentOpts.hideOnOverlayClick) {
  459. overlay.bind('click', $.fancybox.close);
  460. }
  461. $(window).bind("resize.fb", $.fancybox.resize);
  462. if (currentOpts.centerOnScroll) {
  463. $(window).bind("scroll.fb", $.fancybox.center);
  464. }
  465. if (currentOpts.type == 'iframe') {
  466. $('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" ' + ($.browser.msie ? 'allowtransparency="true""' : '') + ' scrolling="' + selectedOpts.scrolling + '" src="' + currentOpts.href + '"></iframe>').appendTo(content);
  467. }
  468. wrap.show();
  469. busy = false;
  470. $.fancybox.center();
  471. currentOpts.onComplete(currentArray, currentIndex, currentOpts);
  472. _preload_images();
  473. },
  474. _preload_images = function() {
  475. var href,
  476. objNext;
  477. if ((currentArray.length -1) > currentIndex) {
  478. href = currentArray[ currentIndex + 1 ].href;
  479. if (typeof href !== 'undefined' && href.match(imgRegExp)) {
  480. objNext = new Image();
  481. objNext.src = href;
  482. }
  483. }
  484. if (currentIndex > 0) {
  485. href = currentArray[ currentIndex - 1 ].href;
  486. if (typeof href !== 'undefined' && href.match(imgRegExp)) {
  487. objNext = new Image();
  488. objNext.src = href;
  489. }
  490. }
  491. },
  492. _draw = function(pos) {
  493. var dim = {
  494. width : parseInt(start_pos.width + (final_pos.width - start_pos.width) * pos, 10),
  495. height : parseInt(start_pos.height + (final_pos.height - start_pos.height) * pos, 10),
  496. top : parseInt(start_pos.top + (final_pos.top - start_pos.top) * pos, 10),
  497. left : parseInt(start_pos.left + (final_pos.left - start_pos.left) * pos, 10)
  498. };
  499. if (typeof final_pos.opacity !== 'undefined') {
  500. dim.opacity = pos < 0.5 ? 0.5 : pos;
  501. }
  502. wrap.css(dim);
  503. content.css({
  504. 'width' : dim.width - currentOpts.padding * 2,
  505. 'height' : dim.height - (titleHeight * pos) - currentOpts.padding * 2
  506. });
  507. },
  508. _get_viewport = function() {
  509. return [
  510. $(window).width() - (currentOpts.margin * 2),
  511. $(window).height() - (currentOpts.margin * 2),
  512. $(document).scrollLeft() + currentOpts.margin,
  513. $(document).scrollTop() + currentOpts.margin
  514. ];
  515. },
  516. _get_zoom_to = function () {
  517. var view = _get_viewport(),
  518. to = {},
  519. resize = currentOpts.autoScale,
  520. double_padding = currentOpts.padding * 2,
  521. ratio;
  522. if (currentOpts.width.toString().indexOf('%') > -1) {
  523. to.width = parseInt((view[0] * parseFloat(currentOpts.width)) / 100, 10);
  524. } else {
  525. to.width = currentOpts.width + double_padding;
  526. }
  527. if (currentOpts.height.toString().indexOf('%') > -1) {
  528. to.height = parseInt((view[1] * parseFloat(currentOpts.height)) / 100, 10);
  529. } else {
  530. to.height = currentOpts.height + double_padding;
  531. }
  532. if (resize && (to.width > view[0] || to.height > view[1])) {
  533. if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') {
  534. ratio = (currentOpts.width ) / (currentOpts.height );
  535. if ((to.width ) > view[0]) {
  536. to.width = view[0];
  537. to.height = parseInt(((to.width - double_padding) / ratio) + double_padding, 10);
  538. }
  539. if ((to.height) > view[1]) {
  540. to.height = view[1];
  541. to.width = parseInt(((to.height - double_padding) * ratio) + double_padding, 10);
  542. }
  543. } else {
  544. to.width = Math.min(to.width, view[0]);
  545. to.height = Math.min(to.height, view[1]);
  546. }
  547. }
  548. to.top = parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - to.height - 40) * 0.5)), 10);
  549. to.left = parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - to.width - 40) * 0.5)), 10);
  550. return to;
  551. },
  552. _get_obj_pos = function(obj) {
  553. var pos = obj.offset();
  554. pos.top += parseInt( obj.css('paddingTop'), 10 ) || 0;
  555. pos.left += parseInt( obj.css('paddingLeft'), 10 ) || 0;
  556. pos.top += parseInt( obj.css('border-top-width'), 10 ) || 0;
  557. pos.left += parseInt( obj.css('border-left-width'), 10 ) || 0;
  558. pos.width = obj.width();
  559. pos.height = obj.height();
  560. return pos;
  561. },
  562. _get_zoom_from = function() {
  563. var orig = selectedOpts.orig ? $(selectedOpts.orig) : false,
  564. from = {},
  565. pos,
  566. view;
  567. if (orig && orig.length) {
  568. pos = _get_obj_pos(orig);
  569. from = {
  570. width : pos.width + (currentOpts.padding * 2),
  571. height : pos.height + (currentOpts.padding * 2),
  572. top : pos.top - currentOpts.padding - 20,
  573. left : pos.left - currentOpts.padding - 20
  574. };
  575. } else {
  576. view = _get_viewport();
  577. from = {
  578. width : currentOpts.padding * 2,
  579. height : currentOpts.padding * 2,
  580. top : parseInt(view[3] + view[1] * 0.5, 10),
  581. left : parseInt(view[2] + view[0] * 0.5, 10)
  582. };
  583. }
  584. return from;
  585. },
  586. _animate_loading = function() {
  587. if (!loading.is(':visible')){
  588. clearInterval(loadingTimer);
  589. return;
  590. }
  591. $('div', loading).css('top', (loadingFrame * -40) + 'px');
  592. loadingFrame = (loadingFrame + 1) % 12;
  593. };
  594. /*
  595. * Public methods
  596. */
  597. $.fn.fancybox = function(options) {
  598. if (!$(this).length) {
  599. return this;
  600. }
  601. $(this)
  602. .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {})))
  603. .unbind('click.fb')
  604. .bind('click.fb', function(e) {
  605. e.preventDefault();
  606. if (busy) {
  607. return;
  608. }
  609. busy = true;
  610. $(this).blur();
  611. selectedArray = [];
  612. selectedIndex = 0;
  613. var rel = $(this).attr('rel') || '';
  614. if (!rel || rel == '' || rel === 'nofollow') {
  615. selectedArray.push(this);
  616. } else {
  617. selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]");
  618. selectedIndex = selectedArray.index( this );
  619. }
  620. _start();
  621. return;
  622. });
  623. return this;
  624. };
  625. $.fancybox = function(obj) {
  626. var opts;
  627. if (busy) {
  628. return;
  629. }
  630. busy = true;
  631. opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {};
  632. selectedArray = [];
  633. selectedIndex = parseInt(opts.index, 10) || 0;
  634. if ($.isArray(obj)) {
  635. for (var i = 0, j = obj.length; i < j; i++) {
  636. if (typeof obj[i] == 'object') {
  637. $(obj[i]).data('fancybox', $.extend({}, opts, obj[i]));
  638. } else {
  639. obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts));
  640. }
  641. }
  642. selectedArray = jQuery.merge(selectedArray, obj);
  643. } else {
  644. if (typeof obj == 'object') {
  645. $(obj).data('fancybox', $.extend({}, opts, obj));
  646. } else {
  647. obj = $({}).data('fancybox', $.extend({content : obj}, opts));
  648. }
  649. selectedArray.push(obj);
  650. }
  651. if (selectedIndex > selectedArray.length || selectedIndex < 0) {
  652. selectedIndex = 0;
  653. }
  654. _start();
  655. };
  656. $.fancybox.showActivity = function() {
  657. clearInterval(loadingTimer);
  658. loading.show();
  659. loadingTimer = setInterval(_animate_loading, 66);
  660. };
  661. $.fancybox.hideActivity = function() {
  662. loading.hide();
  663. };
  664. $.fancybox.next = function() {
  665. return $.fancybox.pos( currentIndex + 1);
  666. };
  667. $.fancybox.prev = function() {
  668. return $.fancybox.pos( currentIndex - 1);
  669. };
  670. $.fancybox.pos = function(pos) {
  671. if (busy) {
  672. return;
  673. }
  674. pos = parseInt(pos);
  675. selectedArray = currentArray;
  676. if (pos > -1 && pos < currentArray.length) {
  677. selectedIndex = pos;
  678. _start();
  679. } else if (currentOpts.cyclic && currentArray.length > 1) {
  680. selectedIndex = pos >= currentArray.length ? 0 : currentArray.length - 1;
  681. _start();
  682. }
  683. return;
  684. };
  685. $.fancybox.cancel = function() {
  686. if (busy) {
  687. return;
  688. }
  689. busy = true;
  690. $.event.trigger('fancybox-cancel');
  691. _abort();
  692. selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts);
  693. busy = false;
  694. };
  695. // Note: within an iframe use - parent.$.fancybox.close();
  696. $.fancybox.close = function() {
  697. if (busy || wrap.is(':hidden')) {
  698. return;
  699. }
  700. busy = true;
  701. if (currentOpts && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) {
  702. busy = false;
  703. return;
  704. }
  705. _abort();
  706. $(close.add( nav_left ).add( nav_right )).hide();
  707. $(content.add( overlay )).unbind();
  708. $(window).unbind("resize.fb scroll.fb");
  709. $(document).unbind('keydown.fb');
  710. content.find('iframe').attr('src', isIE6 && /^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank');
  711. if (currentOpts.titlePosition !== 'inside') {
  712. title.empty();
  713. }
  714. wrap.stop();
  715. function _cleanup() {
  716. overlay.fadeOut('fast');
  717. title.empty().hide();
  718. wrap.hide();
  719. $.event.trigger('fancybox-cleanup');
  720. content.empty();
  721. currentOpts.onClosed(currentArray, currentIndex, currentOpts);
  722. currentArray = selectedOpts = [];
  723. currentIndex = selectedIndex = 0;
  724. currentOpts = selectedOpts = {};
  725. busy = false;
  726. }
  727. if (currentOpts.transitionOut == 'elastic') {
  728. start_pos = _get_zoom_from();
  729. var pos = wrap.position();
  730. final_pos = {
  731. top : pos.top ,
  732. left : pos.left,
  733. width : wrap.width(),
  734. height : wrap.height()
  735. };
  736. if (currentOpts.opacity) {
  737. final_pos.opacity = 1;
  738. }
  739. title.empty().hide();
  740. fx.prop = 1;
  741. $(fx).animate({ prop: 0 }, {
  742. duration : currentOpts.speedOut,
  743. easing : currentOpts.easingOut,
  744. step : _draw,
  745. complete : _cleanup
  746. });
  747. } else {
  748. wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup);
  749. }
  750. };
  751. $.fancybox.resize = function() {
  752. if (overlay.is(':visible')) {
  753. overlay.css('height', $(document).height());
  754. }
  755. $.fancybox.center(true);
  756. };
  757. $.fancybox.center = function() {
  758. var view, align;
  759. if (busy) {
  760. return;
  761. }
  762. align = arguments[0] === true ? 1 : 0;
  763. view = _get_viewport();
  764. if (!align && (wrap.width() > view[0] || wrap.height() > view[1])) {
  765. return;
  766. }
  767. wrap
  768. .stop()
  769. .animate({
  770. 'top' : parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - content.height() - 40) * 0.5) - currentOpts.padding)),
  771. 'left' : parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - content.width() - 40) * 0.5) - currentOpts.padding))
  772. }, typeof arguments[0] == 'number' ? arguments[0] : 200);
  773. };
  774. $.fancybox.init = function() {
  775. if ($("#fancybox-wrap").length) {
  776. return;
  777. }
  778. $('body').append(
  779. tmp = $('<div id="fancybox-tmp"></div>'),
  780. loading = $('<div id="fancybox-loading"><div></div></div>'),
  781. overlay = $('<div id="fancybox-overlay"></div>'),
  782. wrap = $('<div id="fancybox-wrap"></div>')
  783. );
  784. outer = $('<div id="fancybox-outer"></div>')
  785. .append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>')
  786. .appendTo( wrap );
  787. outer.append(
  788. content = $('<div id="fancybox-content"></div>'),
  789. close = $('<a id="fancybox-close"></a>'),
  790. title = $('<div id="fancybox-title"></div>'),
  791. nav_left = $('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),
  792. nav_right = $('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>')
  793. );
  794. close.click($.fancybox.close);
  795. loading.click($.fancybox.cancel);
  796. nav_left.click(function(e) {
  797. e.preventDefault();
  798. $.fancybox.prev();
  799. });
  800. nav_right.click(function(e) {
  801. e.preventDefault();
  802. $.fancybox.next();
  803. });
  804. if ($.fn.mousewheel) {
  805. wrap.bind('mousewheel.fb', function(e, delta) {
  806. if (busy) {
  807. e.preventDefault();
  808. } else if ($(e.target).get(0).clientHeight == 0 || $(e.target).get(0).scrollHeight === $(e.target).get(0).clientHeight) {
  809. e.preventDefault();
  810. $.fancybox[ delta > 0 ? 'prev' : 'next']();
  811. }
  812. });
  813. }
  814. if (!$.support.opacity) {
  815. wrap.addClass('fancybox-ie');
  816. }
  817. if (isIE6) {
  818. loading.addClass('fancybox-ie6');
  819. wrap.addClass('fancybox-ie6');
  820. $('<iframe id="fancybox-hide-sel-frame" src="' + (/^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank' ) + '" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(outer);
  821. }
  822. };
  823. $.fn.fancybox.defaults = {
  824. padding : 10,
  825. margin : 40,
  826. opacity : false,
  827. modal : false,
  828. cyclic : false,
  829. scrolling : 'auto', // 'auto', 'yes' or 'no'
  830. width : 560,
  831. height : 340,
  832. autoScale : true,
  833. autoDimensions : true,
  834. centerOnScroll : false,
  835. ajax : {},
  836. swf : { wmode: 'transparent' },
  837. hideOnOverlayClick : true,
  838. hideOnContentClick : false,
  839. overlayShow : true,
  840. overlayOpacity : 0.7,
  841. overlayColor : '#777',
  842. titleShow : true,
  843. titlePosition : 'float', // 'float', 'outside', 'inside' or 'over'
  844. titleFormat : null,
  845. titleFromAlt : false,
  846. transitionIn : 'fade', // 'elastic', 'fade' or 'none'
  847. transitionOut : 'fade', // 'elastic', 'fade' or 'none'
  848. speedIn : 300,
  849. speedOut : 300,
  850. changeSpeed : 300,
  851. changeFade : 'fast',
  852. easingIn : 'swing',
  853. easingOut : 'swing',
  854. showCloseButton : true,
  855. showNavArrows : true,
  856. enableEscapeButton : true,
  857. enableKeyboardNav : true,
  858. onStart : function(){},
  859. onCancel : function(){},
  860. onComplete : function(){},
  861. onCleanup : function(){},
  862. onClosed : function(){},
  863. onError : function(){}
  864. };
  865. $(document).ready(function() {
  866. $.fancybox.init();
  867. });
  868. })(jQuery);
  869. /* http://keith-wood.name/countdown.html
  870. Countdown for jQuery v1.6.3.
  871. Written by Keith Wood (kbwood{at}iinet.com.au) January 2008.
  872. Available under the MIT (https://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt) license.
  873. Please attribute the author if you use it. */
  874. /* Display a countdown timer.
  875. Attach it with options like:
  876. $('div selector').countdown(
  877. {until: new Date(2009, 1 - 1, 1, 0, 0, 0), onExpiry: happyNewYear}); */
  878. (function($) { // Hide scope, no $ conflict
  879. /* Countdown manager. */
  880. function Countdown() {
  881. this.regional = []; // Available regional settings, indexed by language code
  882. this.regional[''] = { // Default regional settings
  883. // The display texts for the counters
  884. labels: ['Years', 'Months', 'Weeks', 'Days', 'Hours', 'Minutes', 'Seconds'],
  885. // The display texts for the counters if only one
  886. labels1: ['Year', 'Month', 'Week', 'Day', 'Hour', 'Minute', 'Second'],
  887. compactLabels: ['y', 'm', 'w', 'd'], // The compact texts for the counters
  888. whichLabels: null, // Function to determine which labels to use
  889. digits: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], // The digits to display
  890. timeSeparator: ':', // Separator for time periods
  891. isRTL: false // True for right-to-left languages, false for left-to-right
  892. };
  893. this._defaults = {
  894. until: null, // new Date(year, mth - 1, day, hr, min, sec) - date/time to count down to
  895. // or numeric for seconds offset, or string for unit offset(s):
  896. // 'Y' years, 'O' months, 'W' weeks, 'D' days, 'H' hours, 'M' minutes, 'S' seconds
  897. since: null, // new Date(year, mth - 1, day, hr, min, sec) - date/time to count up from
  898. // or numeric for seconds offset, or string for unit offset(s):
  899. // 'Y' years, 'O' months, 'W' weeks, 'D' days, 'H' hours, 'M' minutes, 'S' seconds
  900. timezone: null, // The timezone (hours or minutes from GMT) for the target times,
  901. // or null for client local
  902. serverSync: null, // A function to retrieve the current server time for synchronisation
  903. format: 'dHMS', // Format for display - upper case for always, lower case only if non-zero,
  904. // 'Y' years, 'O' months, 'W' weeks, 'D' days, 'H' hours, 'M' minutes, 'S' seconds
  905. layout: '', // Build your own layout for the countdown
  906. compact: false, // True to display in a compact format, false for an expanded one
  907. significant: 0, // The number of periods with values to show, zero for all
  908. description: '', // The description displayed for the countdown
  909. expiryUrl: '', // A URL to load upon expiry, replacing the current page
  910. expiryText: '', // Text to display upon expiry, replacing the countdown
  911. alwaysExpire: false, // True to trigger onExpiry even if never counted down
  912. onExpiry: null, // Callback when the countdown expires -
  913. // receives no parameters and 'this' is the containing division
  914. onTick: null, // Callback when the countdown is updated -
  915. // receives int[7] being the breakdown by period (based on format)
  916. // and 'this' is the containing division
  917. tickInterval: 1 // Interval (seconds) between onTick callbacks
  918. };
  919. $.extend(this._defaults, this.regional['']);
  920. this._serverSyncs = [];
  921. var now = (typeof Date.now == 'function' ? Date.now :
  922. function() { return new Date().getTime(); });
  923. var perfAvail = (window.performance && typeof window.performance.now == 'function');
  924. // Shared timer for all countdowns
  925. function timerCallBack(timestamp) {
  926. var drawStart = (timestamp < 1e12 ? // New HTML5 high resolution timer
  927. (perfAvail ? (performance.now() + performance.timing.navigationStart) : now()) :
  928. // Integer milliseconds since unix epoch
  929. timestamp || now());
  930. if (drawStart - animationStartTime >= 1000) {
  931. plugin._updateTargets();
  932. animationStartTime = drawStart;
  933. }
  934. requestAnimationFrame(timerCallBack);
  935. }
  936. var requestAnimationFrame = window.requestAnimationFrame ||
  937. window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame ||
  938. window.oRequestAnimationFrame || window.msRequestAnimationFrame || null;
  939. // This is when we expect a fall-back to setInterval as it's much more fluid
  940. var animationStartTime = 0;
  941. if (!requestAnimationFrame || $.noRequestAnimationFrame) {
  942. $.noRequestAnimationFrame = null;
  943. setInterval(function() { plugin._updateTargets(); }, 980); // Fall back to good old setInterval
  944. }
  945. else {
  946. animationStartTime = window.animationStartTime ||
  947. window.webkitAnimationStartTime || window.mozAnimationStartTime ||
  948. window.oAnimationStartTime || window.msAnimationStartTime || now();
  949. requestAnimationFrame(timerCallBack);
  950. }
  951. }
  952. var Y = 0; // Years
  953. var O = 1; // Months
  954. var W = 2; // Weeks
  955. var D = 3; // Days
  956. var H = 4; // Hours
  957. var M = 5; // Minutes
  958. var S = 6; // Seconds
  959. $.extend(Countdown.prototype, {
  960. /* Class name added to elements to indicate already configured with countdown. */
  961. markerClassName: 'hasCountdown',
  962. /* Name of the data property for instance settings. */
  963. propertyName: 'countdown',
  964. /* Class name for the right-to-left marker. */
  965. _rtlClass: 'countdown_rtl',
  966. /* Class name for the countdown section marker. */
  967. _sectionClass: 'countdown_section',
  968. /* Class name for the period amount marker. */
  969. _amountClass: 'countdown_amount',
  970. /* Class name for the countdown row marker. */
  971. _rowClass: 'countdown_row',
  972. /* Class name for the holding countdown marker. */
  973. _holdingClass: 'countdown_holding',
  974. /* Class name for the showing countdown marker. */
  975. _showClass: 'countdown_show',
  976. /* Class name for the description marker. */
  977. _descrClass: 'countdown_descr',
  978. /* List of currently active countdown targets. */
  979. _timerTargets: [],
  980. /* Override the default settings for all instances of the countdown widget.
  981. @param options (object) the new settings to use as defaults */
  982. setDefaults: function(options) {
  983. this._resetExtraLabels(this._defaults, options);
  984. $.extend(this._defaults, options || {});
  985. },
  986. /* Convert a date/time to UTC.
  987. @param tz (number) the hour or minute offset from GMT, e.g. +9, -360
  988. @param year (Date) the date/time in that timezone or
  989. (number) the year in that timezone
  990. @param month (number, optional) the month (0 - 11) (omit if year is a Date)
  991. @param day (number, optional) the day (omit if year is a Date)
  992. @param hours (number, optional) the hour (omit if year is a Date)
  993. @param mins (number, optional) the minute (omit if year is a Date)
  994. @param secs (number, optional) the second (omit if year is a Date)
  995. @param ms (number, optional) the millisecond (omit if year is a Date)
  996. @return (Date) the equivalent UTC date/time */
  997. UTCDate: function(tz, year, month, day, hours, mins, secs, ms) {
  998. if (typeof year == 'object' && year.constructor == Date) {
  999. ms = year.getMilliseconds();
  1000. secs = year.getSeconds();
  1001. mins = year.getMinutes();
  1002. hours = year.getHours();
  1003. day = year.getDate();
  1004. month = year.getMonth();
  1005. year = year.getFullYear();
  1006. }
  1007. var d = new Date();
  1008. d.setUTCFullYear(year);
  1009. d.setUTCDate(1);
  1010. d.setUTCMonth(month || 0);
  1011. d.setUTCDate(day || 1);
  1012. d.setUTCHours(hours || 0);
  1013. d.setUTCMinutes((mins || 0) - (Math.abs(tz) < 30 ? tz * 60 : tz));
  1014. d.setUTCSeconds(secs || 0);
  1015. d.setUTCMilliseconds(ms || 0);
  1016. return d;
  1017. },
  1018. /* Convert a set of periods into seconds.
  1019. Averaged for months and years.
  1020. @param periods (number[7]) the periods per year/month/week/day/hour/minute/second
  1021. @return (number) the corresponding number of seconds */
  1022. periodsToSeconds: function(periods) {
  1023. return periods[0] * 31557600 + periods[1] * 2629800 + periods[2] * 604800 +
  1024. periods[3] * 86400 + periods[4] * 3600 + periods[5] * 60 + periods[6];
  1025. },
  1026. /* Attach the countdown widget to a div.
  1027. @param target (element) the containing division
  1028. @param options (object) the initial settings for the countdown */
  1029. _attachPlugin: function(target, options) {
  1030. target = $(target);
  1031. if (target.hasClass(this.markerClassName)) {
  1032. return;
  1033. }
  1034. var inst = {options: $.extend({}, this._defaults), _periods: [0, 0, 0, 0, 0, 0, 0]};
  1035. target.addClass(this.markerClassName).data(this.propertyName, inst);
  1036. this._optionPlugin(target, options);
  1037. },
  1038. /* Add a target to the list of active ones.
  1039. @param target (element) the countdown target */
  1040. _addTarget: function(target) {
  1041. if (!this._hasTarget(target)) {
  1042. this._timerTargets.push(target);
  1043. }
  1044. },
  1045. /* See if a target is in the list of active ones.
  1046. @param target (element) the countdown target
  1047. @return (boolean) true if present, false if not */
  1048. _hasTarget: function(target) {
  1049. return ($.inArray(target, this._timerTargets) > -1);
  1050. },
  1051. /* Remove a target from the list of active ones.
  1052. @param target (element) the countdown target */
  1053. _removeTarget: function(target) {
  1054. this._timerTargets = $.map(this._timerTargets,
  1055. function(value) { return (value == target ? null : value); }); // delete entry
  1056. },
  1057. /* Update each active timer target. */
  1058. _updateTargets: function() {
  1059. for (var i = this._timerTargets.length - 1; i >= 0; i--) {
  1060. this._updateCountdown(this._timerTargets[i]);
  1061. }
  1062. },
  1063. /* Reconfigure the settings for a countdown div.
  1064. @param target (element) the control to affect
  1065. @param options (object) the new options for this instance or
  1066. (string) an individual property name
  1067. @param value (any) the individual property value (omit if options
  1068. is an object or to retrieve the value of a setting)
  1069. @return (any) if retrieving a value */
  1070. _optionPlugin: function(target, options, value) {
  1071. target = $(target);
  1072. var inst = target.data(this.propertyName);
  1073. if (!options || (typeof options == 'string' && value == null)) { // Get option
  1074. var name = options;
  1075. options = (inst || {}).options;
  1076. return (options && name ? options[name] : options);
  1077. }
  1078. if (!target.hasClass(this.markerClassName)) {
  1079. return;
  1080. }
  1081. options = options || {};
  1082. if (typeof options == 'string') {
  1083. var name = options;
  1084. options = {};
  1085. options[name] = value;
  1086. }
  1087. if (options.layout) {
  1088. options.layout = options.layout.replace(/&lt;/g, '<').replace(/&gt;/g, '>');
  1089. }
  1090. this._resetExtraLabels(inst.options, options);
  1091. var timezoneChanged = (inst.options.timezone != options.timezone);
  1092. $.extend(inst.options, options);
  1093. this._adjustSettings(target, inst,
  1094. options.until != null || options.since != null || timezoneChanged);
  1095. var now = new Date();
  1096. if ((inst._since && inst._since < now) || (inst._until && inst._until > now)) {
  1097. this._addTarget(target[0]);
  1098. }
  1099. this._updateCountdown(target, inst);
  1100. },
  1101. /* Redisplay the countdown with an updated display.
  1102. @param target (jQuery) the containing division
  1103. @param inst (object) the current settings for this instance */
  1104. _updateCountdown: function(target, inst) {
  1105. var $target = $(target);
  1106. inst = inst || $target.data(this.propertyName);
  1107. if (!inst) {
  1108. return;
  1109. }
  1110. $target.html(this._generateHTML(inst)).toggleClass(this._rtlClass, inst.options.isRTL);
  1111. if ($.isFunction(inst.options.onTick)) {
  1112. var periods = inst._hold != 'lap' ? inst._periods :
  1113. this._calculatePeriods(inst, inst._show, inst.options.significant, new Date());
  1114. if (inst.options.tickInterval == 1 ||
  1115. this.periodsToSeconds(periods) % inst.options.tickInterval == 0) {
  1116. inst.options.onTick.apply(target, [periods]);
  1117. }
  1118. }
  1119. var expired = inst._hold != 'pause' &&
  1120. (inst._since ? inst._now.getTime() < inst._since.getTime() :
  1121. inst._now.getTime() >= inst._until.getTime());
  1122. if (expired && !inst._expiring) {
  1123. inst._expiring = true;
  1124. if (this._hasTarget(target) || inst.options.alwaysExpire) {
  1125. this._removeTarget(target);
  1126. if ($.isFunction(inst.options.onExpiry)) {
  1127. inst.options.onExpiry.apply(target, []);
  1128. }
  1129. if (inst.options.expiryText) {
  1130. var layout = inst.options.layout;
  1131. inst.options.layout = inst.options.expiryText;
  1132. this._updateCountdown(target, inst);
  1133. inst.options.layout = layout;
  1134. }
  1135. if (inst.options.expiryUrl) {
  1136. window.location = inst.options.expiryUrl;
  1137. }
  1138. }
  1139. inst._expiring = false;
  1140. }
  1141. else if (inst._hold == 'pause') {
  1142. this._removeTarget(target);
  1143. }
  1144. $target.data(this.propertyName, inst);
  1145. },
  1146. /* Reset any extra labelsn and compactLabelsn entries if changing labels.
  1147. @param base (object) the options to be updated
  1148. @param options (object) the new option values */
  1149. _resetExtraLabels: function(base, options) {
  1150. var changingLabels = false;
  1151. for (var n in options) {
  1152. if (n != 'whichLabels' && n.match(/[Ll]abels/)) {
  1153. changingLabels = true;
  1154. break;
  1155. }
  1156. }
  1157. if (changingLabels) {
  1158. for (var n in base) { // Remove custom numbered labels
  1159. if (n.match(/[Ll]abels[02-9]|compactLabels1/)) {
  1160. base[n] = null;
  1161. }
  1162. }
  1163. }
  1164. },
  1165. /* Calculate interal settings for an instance.
  1166. @param target (element) the containing division
  1167. @param inst (object) the current settings for this instance
  1168. @param recalc (boolean) true if until or since are set */
  1169. _adjustSettings: function(target, inst, recalc) {
  1170. var now;
  1171. var serverOffset = 0;
  1172. var serverEntry = null;
  1173. for (var i = 0; i < this._serverSyncs.length; i++) {
  1174. if (this._serverSyncs[i][0] == inst.options.serverSync) {
  1175. serverEntry = this._serverSyncs[i][1];
  1176. break;
  1177. }
  1178. }
  1179. if (serverEntry != null) {
  1180. serverOffset = (inst.options.serverSync ? serverEntry : 0);
  1181. now = new Date();
  1182. }
  1183. else {
  1184. var serverResult = ($.isFunction(inst.options.serverSync) ?
  1185. inst.options.serverSync.apply(target, []) : null);
  1186. now = new Date();
  1187. serverOffset = (serverResult ? now.getTime() - serverResult.getTime() : 0);
  1188. this._serverSyncs.push([inst.options.serverSync, serverOffset]);
  1189. }
  1190. var timezone = inst.options.timezone;
  1191. timezone = (timezone == null ? -now.getTimezoneOffset() : timezone);
  1192. if (recalc || (!recalc && inst._until == null && inst._since == null)) {
  1193. inst._since = inst.options.since;
  1194. if (inst._since != null) {
  1195. inst._since = this.UTCDate(timezone, this._determineTime(inst._since, null));
  1196. if (inst._since && serverOffset) {
  1197. inst._since.setMilliseconds(inst._since.getMilliseconds() + serverOffset);
  1198. }
  1199. }
  1200. inst._until = this.UTCDate(timezone, this._determineTime(inst.options.until, now));
  1201. if (serverOffset) {
  1202. inst._until.setMilliseconds(inst._until.getMilliseconds() + serverOffset);
  1203. }
  1204. }
  1205. inst._show = this._determineShow(inst);
  1206. },
  1207. /* Remove the countdown widget from a div.
  1208. @param target (element) the containing division */
  1209. _destroyPlugin: function(target) {
  1210. target = $(target);
  1211. if (!target.hasClass(this.markerClassName)) {
  1212. return;
  1213. }
  1214. this._removeTarget(target[0]);
  1215. target.removeClass(this.markerClassName).empty().removeData(this.propertyName);
  1216. },
  1217. /* Pause a countdown widget at the current time.
  1218. Stop it running but remember and display the current time.
  1219. @param target (element) the containing division */
  1220. _pausePlugin: function(target) {
  1221. this._hold(target, 'pause');
  1222. },
  1223. /* Pause a countdown widget at the current time.
  1224. Stop the display but keep the countdown running.
  1225. @param target (element) the containing division */
  1226. _lapPlugin: function(target) {
  1227. this._hold(target, 'lap');
  1228. },
  1229. /* Resume a paused countdown widget.
  1230. @param target (element) the containing division */
  1231. _resumePlugin: function(target) {
  1232. this._hold(target, null);
  1233. },
  1234. /* Pause or resume a countdown widget.
  1235. @param target (element) the containing division
  1236. @param hold (string) the new hold setting */
  1237. _hold: function(target, hold) {
  1238. var inst = $.data(target, this.propertyName);
  1239. if (inst) {
  1240. if (inst._hold == 'pause' && !hold) {
  1241. inst._periods = inst._savePeriods;
  1242. var sign = (inst._since ? '-' : '+');
  1243. inst[inst._since ? '_since' : '_until'] =
  1244. this._determineTime(sign + inst._periods[0] + 'y' +
  1245. sign + inst._periods[1] + 'o' + sign + inst._periods[2] + 'w' +
  1246. sign + inst._periods[3] + 'd' + sign + inst._periods[4] + 'h' +
  1247. sign + inst._periods[5] + 'm' + sign + inst._periods[6] + 's');
  1248. this._addTarget(target);
  1249. }
  1250. inst._hold = hold;
  1251. inst._savePeriods = (hold == 'pause' ? inst._periods : null);
  1252. $.data(target, this.propertyName, inst);
  1253. this._updateCountdown(target, inst);
  1254. }
  1255. },
  1256. /* Return the current time periods.
  1257. @param target (element) the containing division
  1258. @return (number[7]) the current periods for the countdown */
  1259. _getTimesPlugin: function(target) {
  1260. var inst = $.data(target, this.propertyName);
  1261. return (!inst ? null : (inst._hold == 'pause' ? inst._savePeriods : (!inst._hold ? inst._periods :
  1262. this._calculatePeriods(inst, inst._show, inst.options.significant, new Date()))));
  1263. },
  1264. /* A time may be specified as an exact value or a relative one.
  1265. @param setting (string or number or Date) - the date/time value
  1266. as a relative or absolute value
  1267. @param defaultTime (Date) the date/time to use if no other is supplied
  1268. @return (Date) the corresponding date/time */
  1269. _determineTime: function(setting, defaultTime) {
  1270. var offsetNumeric = function(offset) { // e.g. +300, -2
  1271. var time = new Date();
  1272. time.setTime(time.getTime() + offset * 1000);
  1273. return time;
  1274. };
  1275. var offsetString = function(offset) { // e.g. '+2d', '-4w', '+3h +30m'
  1276. offset = offset.toLowerCase();
  1277. var time = new Date();
  1278. var year = time.getFullYear();
  1279. var month = time.getMonth();
  1280. var day = time.getDate();
  1281. var hour = time.getHours();
  1282. var minute = time.getMinutes();
  1283. var second = time.getSeconds();
  1284. var pattern = /([+-]?[0-9]+)\s*(s|m|h|d|w|o|y)?/g;
  1285. var matches = pattern.exec(offset);
  1286. while (matches) {
  1287. switch (matches[2] || 's') {
  1288. case 's': second += parseInt(matches[1], 10); break;
  1289. case 'm': minute += parseInt(matches[1], 10); break;
  1290. case 'h': hour += parseInt(matches[1], 10); break;
  1291. case 'd': day += parseInt(matches[1], 10); break;
  1292. case 'w': day += parseInt(matches[1], 10) * 7; break;
  1293. case 'o':
  1294. month += parseInt(matches[1], 10);
  1295. day = Math.min(day, plugin._getDaysInMonth(year, month));
  1296. break;
  1297. case 'y':
  1298. year += parseInt(matches[1], 10);
  1299. day = Math.min(day, plugin._getDaysInMonth(year, month));
  1300. break;
  1301. }
  1302. matches = pattern.exec(offset);
  1303. }
  1304. return new Date(year, month, day, hour, minute, second, 0);
  1305. };
  1306. var time = (setting == null ? defaultTime :
  1307. (typeof setting == 'string' ? offsetString(setting) :
  1308. (typeof setting == 'number' ? offsetNumeric(setting) : setting)));
  1309. if (time) time.setMilliseconds(0);
  1310. return time;
  1311. },
  1312. /* Determine the number of days in a month.
  1313. @param year (number) the year
  1314. @param month (number) the month
  1315. @return (number) the days in that month */
  1316. _getDaysInMonth: function(year, month) {
  1317. return 32 - new Date(year, month, 32).getDate();
  1318. },
  1319. /* Determine which set of labels should be used for an amount.
  1320. @param num (number) the amount to be displayed
  1321. @return (number) the set of labels to be used for this amount */
  1322. _normalLabels: function(num) {
  1323. return num;
  1324. },
  1325. /* Generate the HTML to display the countdown widget.
  1326. @param inst (object) the current settings for this instance
  1327. @return (string) the new HTML for the countdown display */
  1328. _generateHTML: function(inst) {
  1329. var self = this;
  1330. // Determine what to show
  1331. inst._periods = (inst._hold ? inst._periods :
  1332. this._calculatePeriods(inst, inst._show, inst.options.significant, new Date()));
  1333. // Show all 'asNeeded' after first non-zero value
  1334. var shownNonZero = false;
  1335. var showCount = 0;
  1336. var sigCount = inst.options.significant;
  1337. var show = $.extend({}, inst._show);
  1338. for (var period = Y; period <= S; period++) {
  1339. shownNonZero |= (inst._show[period] == '?' && inst._periods[period] > 0);
  1340. show[period] = (inst._show[period] == '?' && !shownNonZero ? null : inst._show[period]);
  1341. showCount += (show[period] ? 1 : 0);
  1342. sigCount -= (inst._periods[period] > 0 ? 1 : 0);
  1343. }
  1344. var showSignificant = [false, false, false, false, false, false, false];
  1345. for (var period = S; period >= Y; period--) { // Determine significant periods
  1346. if (inst._show[period]) {
  1347. if (inst._periods[period]) {
  1348. showSignificant[period] = true;
  1349. }
  1350. else {
  1351. showSignificant[period] = sigCount > 0;
  1352. sigCount--;
  1353. }
  1354. }
  1355. }
  1356. var labels = (inst.options.compact ? inst.options.compactLabels : inst.options.labels);
  1357. var whichLabels = inst.options.whichLabels || this._normalLabels;
  1358. var showCompact = function(period) {
  1359. var labelsNum = inst.options['compactLabels' + whichLabels(inst._periods[period])];
  1360. return (show[period] ? self._translateDigits(inst, inst._periods[period]) +
  1361. (labelsNum ? labelsNum[period] : labels[period]) + ' ' : '');
  1362. };
  1363. var showFull = function(period) {
  1364. var labelsNum = inst.options['labels' + whichLabels(inst._periods[period])];
  1365. return ((!inst.options.significant && show[period]) ||
  1366. (inst.options.significant && showSignificant[period]) ?
  1367. '<span class="' + plugin._sectionClass + '">' +
  1368. '<span class="' + plugin._amountClass + '">' +
  1369. self._translateDigits(inst, inst._periods[period]) + '</span><br/>' +
  1370. (labelsNum ? labelsNum[period] : labels[period]) + '</span>' : '');
  1371. };
  1372. return (inst.options.layout ? this._buildLayout(inst, show, inst.options.layout,
  1373. inst.options.compact, inst.options.significant, showSignificant) :
  1374. ((inst.options.compact ? // Compact version
  1375. '<span class="' + this._rowClass + ' ' + this._amountClass +
  1376. (inst._hold ? ' ' + this._holdingClass : '') + '">' +
  1377. showCompact(Y) + showCompact(O) + showCompact(W) + showCompact(D) +
  1378. (show[H] ? this._minDigits(inst, inst._periods[H], 2) : '') +
  1379. (show[M] ? (show[H] ? inst.options.timeSeparator : '') +
  1380. this._minDigits(inst, inst._periods[M], 2) : '') +
  1381. (show[S] ? (show[H] || show[M] ? inst.options.timeSeparator : '') +
  1382. this._minDigits(inst, inst._periods[S], 2) : '') :
  1383. // Full version
  1384. '<span class="' + this._rowClass + ' ' + this._showClass + (inst.options.significant || showCount) +
  1385. (inst._hold ? ' ' + this._holdingClass : '') + '">' +
  1386. showFull(Y) + showFull(O) + showFull(W) + showFull(D) +
  1387. showFull(H) + showFull(M) + showFull(S)) + '</span>' +
  1388. (inst.options.description ? '<span class="' + this._rowClass + ' ' + this._descrClass + '">' +
  1389. inst.options.description + '</span>' : '')));
  1390. },
  1391. /* Construct a custom layout.
  1392. @param inst (object) the current settings for this instance
  1393. @param show (string[7]) flags indicating which periods are requested
  1394. @param layout (string) the customised layout
  1395. @param compact (boolean) true if using compact labels
  1396. @param significant (number) the number of periods with values to show, zero for all
  1397. @param showSignificant (boolean[7]) other periods to show for significance
  1398. @return (string) the custom HTML */
  1399. _buildLayout: function(inst, show, layout, compact, significant, showSignificant) {
  1400. var labels = inst.options[compact ? 'compactLabels' : 'labels'];
  1401. var whichLabels = inst.options.whichLabels || this._normalLabels;
  1402. var labelFor = function(index) {
  1403. return (inst.options[(compact ? 'compactLabels' : 'labels') +
  1404. whichLabels(inst._periods[index])] || labels)[index];
  1405. };
  1406. var digit = function(value, position) {
  1407. return inst.options.digits[Math.floor(value / position) % 10];
  1408. };
  1409. var subs = {desc: inst.options.description, sep: inst.options.timeSeparator,
  1410. yl: labelFor(Y), yn: this._minDigits(inst, inst._periods[Y], 1),
  1411. ynn: this._minDigits(inst, inst._periods[Y], 2),
  1412. ynnn: this._minDigits(inst, inst._periods[Y], 3), y1: digit(inst._periods[Y], 1),
  1413. y10: digit(inst._periods[Y], 10), y100: digit(inst._periods[Y], 100),
  1414. y1000: digit(inst._periods[Y], 1000),
  1415. ol: labelFor(O), on: this._minDigits(inst, inst._periods[O], 1),
  1416. onn: this._minDigits(inst, inst._periods[O], 2),
  1417. onnn: this._minDigits(inst, inst._periods[O], 3), o1: digit(inst._periods[O], 1),
  1418. o10: digit(inst._periods[O], 10), o100: digit(inst._periods[O], 100),
  1419. o1000: digit(inst._periods[O], 1000),
  1420. wl: labelFor(W), wn: this._minDigits(inst, inst._periods[W], 1),
  1421. wnn: this._minDigits(inst, inst._periods[W], 2),
  1422. wnnn: this._minDigits(inst, inst._periods[W], 3), w1: digit(inst._periods[W], 1),
  1423. w10: digit(inst._periods[W], 10), w100: digit(inst._periods[W], 100),
  1424. w1000: digit(inst._periods[W], 1000),
  1425. dl: labelFor(D), dn: this._minDigits(inst, inst._periods[D], 1),
  1426. dnn: this._minDigits(inst, inst._periods[D], 2),
  1427. dnnn: this._minDigits(inst, inst._periods[D], 3), d1: digit(inst._periods[D], 1),
  1428. d10: digit(inst._periods[D], 10), d100: digit(inst._periods[D], 100),
  1429. d1000: digit(inst._periods[D], 1000),
  1430. hl: labelFor(H), hn: this._minDigits(inst, inst._periods[H], 1),
  1431. hnn: this._minDigits(inst, inst._periods[H], 2),
  1432. hnnn: this._minDigits(inst, inst._periods[H], 3), h1: digit(inst._periods[H], 1),
  1433. h10: digit(inst._periods[H], 10), h100: digit(inst._periods[H], 100),
  1434. h1000: digit(inst._periods[H], 1000),
  1435. ml: labelFor(M), mn: this._minDigits(inst, inst._periods[M], 1),
  1436. mnn: this._minDigits(inst, inst._periods[M], 2),
  1437. mnnn: this._minDigits(inst, inst._periods[M], 3), m1: digit(inst._periods[M], 1),
  1438. m10: digit(inst._periods[M], 10), m100: digit(inst._periods[M], 100),
  1439. m1000: digit(inst._periods[M], 1000),
  1440. sl: labelFor(S), sn: this._minDigits(inst, inst._periods[S], 1),
  1441. snn: this._minDigits(inst, inst._periods[S], 2),
  1442. snnn: this._minDigits(inst, inst._periods[S], 3), s1: digit(inst._periods[S], 1),
  1443. s10: digit(inst._periods[S], 10), s100: digit(inst._periods[S], 100),
  1444. s1000: digit(inst._periods[S], 1000)};
  1445. var html = layout;
  1446. // Replace period containers: {p<}...{p>}
  1447. for (var i = Y; i <= S; i++) {
  1448. var period = 'yowdhms'.charAt(i);
  1449. var re = new RegExp('\\{' + period + '<\\}([\\s\\S]*)\\{' + period + '>\\}', 'g');
  1450. html = html.replace(re, ((!significant && show[i]) ||
  1451. (significant && showSignificant[i]) ? '$1' : ''));
  1452. }
  1453. // Replace period values: {pn}
  1454. $.each(subs, function(n, v) {
  1455. var re = new RegExp('\\{' + n + '\\}', 'g');
  1456. html = html.replace(re, v);
  1457. });
  1458. return html;
  1459. },
  1460. /* Ensure a numeric value has at least n digits for display.
  1461. @param inst (object) the current settings for this instance
  1462. @param value (number) the value to display
  1463. @param len (number) the minimum length
  1464. @return (string) the display text */
  1465. _minDigits: function(inst, value, len) {
  1466. value = '' + value;
  1467. if (value.length >= len) {
  1468. return this._translateDigits(inst, value);
  1469. }
  1470. value = '0000000000' + value;
  1471. return this._translateDigits(inst, value.substr(value.length - len));
  1472. },
  1473. /* Translate digits into other representations.
  1474. @param inst (object) the current settings for this instance
  1475. @param value (string) the text to translate
  1476. @return (string) the translated text */
  1477. _translateDigits: function(inst, value) {
  1478. return ('' + value).replace(/[0-9]/g, function(digit) {
  1479. return inst.options.digits[digit];
  1480. });
  1481. },
  1482. /* Translate the format into flags for each period.
  1483. @param inst (object) the current settings for this instance
  1484. @return (string[7]) flags indicating which periods are requested (?) or
  1485. required (!) by year, month, week, day, hour, minute, second */
  1486. _determineShow: function(inst) {
  1487. var format = inst.options.format;
  1488. var show = [];
  1489. show[Y] = (format.match('y') ? '?' : (format.match('Y') ? '!' : null));
  1490. show[O] = (format.match('o') ? '?' : (format.match('O') ? '!' : null));
  1491. show[W] = (format.match('w') ? '?' : (format.match('W') ? '!' : null));
  1492. show[D] = (format.match('d') ? '?' : (format.match('D') ? '!' : null));
  1493. show[H] = (format.match('h') ? '?' : (format.match('H') ? '!' : null));
  1494. show[M] = (format.match('m') ? '?' : (format.match('M') ? '!' : null));
  1495. show[S] = (format.match('s') ? '?' : (format.match('S') ? '!' : null));
  1496. return show;
  1497. },
  1498. /* Calculate the requested periods between now and the target time.
  1499. @param inst (object) the current settings for this instance
  1500. @param show (string[7]) flags indicating which periods are requested/required
  1501. @param significant (number) the number of periods with values to show, zero for all
  1502. @param now (Date) the current date and time
  1503. @return (number[7]) the current time periods (always positive)
  1504. by year, month, week, day, hour, minute, second */
  1505. _calculatePeriods: function(inst, show, significant, now) {
  1506. // Find endpoints
  1507. inst._now = now;
  1508. inst._now.setMilliseconds(0);
  1509. var until = new Date(inst._now.getTime());
  1510. if (inst._since) {
  1511. if (now.getTime() < inst._since.getTime()) {
  1512. inst._now = now = until;
  1513. }
  1514. else {
  1515. now = inst._since;
  1516. }
  1517. }
  1518. else {
  1519. until.setTime(inst._until.getTime());
  1520. if (now.getTime() > inst._until.getTime()) {
  1521. inst._now = now = until;
  1522. }
  1523. }
  1524. // Calculate differences by period
  1525. var periods = [0, 0, 0, 0, 0, 0, 0];
  1526. if (show[Y] || show[O]) {
  1527. // Treat end of months as the same
  1528. var lastNow = plugin._getDaysInMonth(now.getFullYear(), now.getMonth());
  1529. var lastUntil = plugin._getDaysInMonth(until.getFullYear(), until.getMonth());
  1530. var sameDay = (until.getDate() == now.getDate() ||
  1531. (until.getDate() >= Math.min(lastNow, lastUntil) &&
  1532. now.getDate() >= Math.min(lastNow, lastUntil)));
  1533. var getSecs = function(date) {
  1534. return (date.getHours() * 60 + date.getMinutes()) * 60 + date.getSeconds();
  1535. };
  1536. var months = Math.max(0,
  1537. (until.getFullYear() - now.getFullYear()) * 12 + until.getMonth() - now.getMonth() +
  1538. ((until.getDate() < now.getDate() && !sameDay) ||
  1539. (sameDay && getSecs(until) < getSecs(now)) ? -1 : 0));
  1540. periods[Y] = (show[Y] ? Math.floor(months / 12) : 0);
  1541. periods[O] = (show[O] ? months - periods[Y] * 12 : 0);
  1542. // Adjust for months difference and end of month if necessary
  1543. now = new Date(now.getTime());
  1544. var wasLastDay = (now.getDate() == lastNow);
  1545. var lastDay = plugin._getDaysInMonth(now.getFullYear() + periods[Y],
  1546. now.getMonth() + periods[O]);
  1547. if (now.getDate() > lastDay) {
  1548. now.setDate(lastDay);
  1549. }
  1550. now.setFullYear(now.getFullYear() + periods[Y]);
  1551. now.setMonth(now.getMonth() + periods[O]);
  1552. if (wasLastDay) {
  1553. now.setDate(lastDay);
  1554. }
  1555. }
  1556. var diff = Math.floor((until.getTime() - now.getTime()) / 1000);
  1557. var extractPeriod = function(period, numSecs) {
  1558. periods[period] = (show[period] ? Math.floor(diff / numSecs) : 0);
  1559. diff -= periods[period] * numSecs;
  1560. };
  1561. extractPeriod(W, 604800);
  1562. extractPeriod(D, 86400);
  1563. extractPeriod(H, 3600);
  1564. extractPeriod(M, 60);
  1565. extractPeriod(S, 1);
  1566. if (diff > 0 && !inst._since) { // Round up if left overs
  1567. var multiplier = [1, 12, 4.3482, 7, 24, 60, 60];
  1568. var lastShown = S;
  1569. var max = 1;
  1570. for (var period = S; period >= Y; period--) {
  1571. if (show[period]) {
  1572. if (periods[lastShown] >= max) {
  1573. periods[lastShown] = 0;
  1574. diff = 1;
  1575. }
  1576. if (diff > 0) {
  1577. periods[period]++;
  1578. diff = 0;
  1579. lastShown = period;
  1580. max = 1;
  1581. }
  1582. }
  1583. max *= multiplier[period];
  1584. }
  1585. }
  1586. if (significant) { // Zero out insignificant periods
  1587. for (var period = Y; period <= S; period++) {
  1588. if (significant && periods[period]) {
  1589. significant--;
  1590. }
  1591. else if (!significant) {
  1592. periods[period] = 0;
  1593. }
  1594. }
  1595. }
  1596. return periods;
  1597. }
  1598. });
  1599. // The list of commands that return values and don't permit chaining
  1600. var getters = ['getTimes'];
  1601. /* Determine whether a command is a getter and doesn't permit chaining.
  1602. @param command (string, optional) the command to run
  1603. @param otherArgs ([], optional) any other arguments for the command
  1604. @return true if the command is a getter, false if not */
  1605. function isNotChained(command, otherArgs) {
  1606. if (command == 'option' && (otherArgs.length == 0 ||
  1607. (otherArgs.length == 1 && typeof otherArgs[0] == 'string'))) {
  1608. return true;
  1609. }
  1610. return $.inArray(command, getters) > -1;
  1611. }
  1612. /* Process the countdown functionality for a jQuery selection.
  1613. @param options (object) the new settings to use for these instances (optional) or
  1614. (string) the command to run (optional)
  1615. @return (jQuery) for chaining further calls or
  1616. (any) getter value */
  1617. $.fn.countdown = function(options) {
  1618. var otherArgs = Array.prototype.slice.call(arguments, 1);
  1619. if (isNotChained(options, otherArgs)) {
  1620. return plugin['_' + options + 'Plugin'].
  1621. apply(plugin, [this[0]].concat(otherArgs));
  1622. }
  1623. return this.each(function() {
  1624. if (typeof options == 'string') {
  1625. if (!plugin['_' + options + 'Plugin']) {
  1626. throw 'Unknown command: ' + options;
  1627. }
  1628. plugin['_' + options + 'Plugin'].
  1629. apply(plugin, [this].concat(otherArgs));
  1630. }
  1631. else {
  1632. plugin._attachPlugin(this, options || {});
  1633. }
  1634. });
  1635. };
  1636. /* Initialise the countdown functionality. */
  1637. var plugin = $.countdown = new Countdown(); // Singleton instance
  1638. })(jQuery);
  1639. /*
  1640. * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
  1641. *
  1642. * Uses the built in easing capabilities added In jQuery 1.1
  1643. * to offer multiple easing options
  1644. *
  1645. * TERMS OF USE - jQuery Easing
  1646. *
  1647. * Open source under the BSD License.
  1648. *
  1649. * Copyright © 2008 George McGinley Smith
  1650. * All rights reserved.
  1651. *
  1652. * Redistribution and use in source and binary forms, with or without modification,
  1653. * are permitted provided that the following conditions are met:
  1654. *
  1655. * Redistributions of source code must retain the above copyright notice, this list of
  1656. * conditions and the following disclaimer.
  1657. * Redistributions in binary form must reproduce the above copyright notice, this list
  1658. * of conditions and the following disclaimer in the documentation and/or other materials
  1659. * provided with the distribution.
  1660. *
  1661. * Neither the name of the author nor the names of contributors may be used to endorse
  1662. * or promote products derived from this software without specific prior written permission.
  1663. *
  1664. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  1665. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  1666. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  1667. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  1668. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  1669. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  1670. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1671. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  1672. * OF THE POSSIBILITY OF SUCH DAMAGE.
  1673. *
  1674. */
  1675. // t: current time, b: begInnIng value, c: change In value, d: duration
  1676. eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('h.i[\'1a\']=h.i[\'z\'];h.O(h.i,{y:\'D\',z:9(x,t,b,c,d){6 h.i[h.i.y](x,t,b,c,d)},17:9(x,t,b,c,d){6 c*(t/=d)*t+b},D:9(x,t,b,c,d){6-c*(t/=d)*(t-2)+b},13:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t+b;6-c/2*((--t)*(t-2)-1)+b},X:9(x,t,b,c,d){6 c*(t/=d)*t*t+b},U:9(x,t,b,c,d){6 c*((t=t/d-1)*t*t+1)+b},R:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t+b;6 c/2*((t-=2)*t*t+2)+b},N:9(x,t,b,c,d){6 c*(t/=d)*t*t*t+b},M:9(x,t,b,c,d){6-c*((t=t/d-1)*t*t*t-1)+b},L:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t*t+b;6-c/2*((t-=2)*t*t*t-2)+b},K:9(x,t,b,c,d){6 c*(t/=d)*t*t*t*t+b},J:9(x,t,b,c,d){6 c*((t=t/d-1)*t*t*t*t+1)+b},I:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t*t*t+b;6 c/2*((t-=2)*t*t*t*t+2)+b},G:9(x,t,b,c,d){6-c*8.C(t/d*(8.g/2))+c+b},15:9(x,t,b,c,d){6 c*8.n(t/d*(8.g/2))+b},12:9(x,t,b,c,d){6-c/2*(8.C(8.g*t/d)-1)+b},Z:9(x,t,b,c,d){6(t==0)?b:c*8.j(2,10*(t/d-1))+b},Y:9(x,t,b,c,d){6(t==d)?b+c:c*(-8.j(2,-10*t/d)+1)+b},W:9(x,t,b,c,d){e(t==0)6 b;e(t==d)6 b+c;e((t/=d/2)<1)6 c/2*8.j(2,10*(t-1))+b;6 c/2*(-8.j(2,-10*--t)+2)+b},V:9(x,t,b,c,d){6-c*(8.o(1-(t/=d)*t)-1)+b},S:9(x,t,b,c,d){6 c*8.o(1-(t=t/d-1)*t)+b},Q:9(x,t,b,c,d){e((t/=d/2)<1)6-c/2*(8.o(1-t*t)-1)+b;6 c/2*(8.o(1-(t-=2)*t)+1)+b},P:9(x,t,b,c,d){f s=1.l;f p=0;f a=c;e(t==0)6 b;e((t/=d)==1)6 b+c;e(!p)p=d*.3;e(a<8.w(c)){a=c;f s=p/4}m f s=p/(2*8.g)*8.r(c/a);6-(a*8.j(2,10*(t-=1))*8.n((t*d-s)*(2*8.g)/p))+b},H:9(x,t,b,c,d){f s=1.l;f p=0;f a=c;e(t==0)6 b;e((t/=d)==1)6 b+c;e(!p)p=d*.3;e(a<8.w(c)){a=c;f s=p/4}m f s=p/(2*8.g)*8.r(c/a);6 a*8.j(2,-10*t)*8.n((t*d-s)*(2*8.g)/p)+c+b},T:9(x,t,b,c,d){f s=1.l;f p=0;f a=c;e(t==0)6 b;e((t/=d/2)==2)6 b+c;e(!p)p=d*(.3*1.5);e(a<8.w(c)){a=c;f s=p/4}m f s=p/(2*8.g)*8.r(c/a);e(t<1)6-.5*(a*8.j(2,10*(t-=1))*8.n((t*d-s)*(2*8.g)/p))+b;6 a*8.j(2,-10*(t-=1))*8.n((t*d-s)*(2*8.g)/p)*.5+c+b},F:9(x,t,b,c,d,s){e(s==u)s=1.l;6 c*(t/=d)*t*((s+1)*t-s)+b},E:9(x,t,b,c,d,s){e(s==u)s=1.l;6 c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},16:9(x,t,b,c,d,s){e(s==u)s=1.l;e((t/=d/2)<1)6 c/2*(t*t*(((s*=(1.B))+1)*t-s))+b;6 c/2*((t-=2)*t*(((s*=(1.B))+1)*t+s)+2)+b},A:9(x,t,b,c,d){6 c-h.i.v(x,d-t,0,c,d)+b},v:9(x,t,b,c,d){e((t/=d)<(1/2.k)){6 c*(7.q*t*t)+b}m e(t<(2/2.k)){6 c*(7.q*(t-=(1.5/2.k))*t+.k)+b}m e(t<(2.5/2.k)){6 c*(7.q*(t-=(2.14/2.k))*t+.11)+b}m{6 c*(7.q*(t-=(2.18/2.k))*t+.19)+b}},1b:9(x,t,b,c,d){e(t<d/2)6 h.i.A(x,t*2,0,c,d)*.5+b;6 h.i.v(x,t*2-d,0,c,d)*.5+c*.5+b}});',62,74,'||||||return||Math|function|||||if|var|PI|jQuery|easing|pow|75|70158|else|sin|sqrt||5625|asin|||undefined|easeOutBounce|abs||def|swing|easeInBounce|525|cos|easeOutQuad|easeOutBack|easeInBack|easeInSine|easeOutElastic|easeInOutQuint|easeOutQuint|easeInQuint|easeInOutQuart|easeOutQuart|easeInQuart|extend|easeInElastic|easeInOutCirc|easeInOutCubic|easeOutCirc|easeInOutElastic|easeOutCubic|easeInCirc|easeInOutExpo|easeInCubic|easeOutExpo|easeInExpo||9375|easeInOutSine|easeInOutQuad|25|easeOutSine|easeInOutBack|easeInQuad|625|984375|jswing|easeInOutBounce'.split('|'),0,{}))
  1677. /*
  1678. *
  1679. * TERMS OF USE - EASING EQUATIONS
  1680. *
  1681. * Open source under the BSD License.
  1682. *
  1683. * Copyright © 2001 Robert Penner
  1684. * All rights reserved.
  1685. *
  1686. * Redistribution and use in source and binary forms, with or without modification,
  1687. * are permitted provided that the following conditions are met:
  1688. *
  1689. * Redistributions of source code must retain the above copyright notice, this list of
  1690. * conditions and the following disclaimer.
  1691. * Redistributions in binary form must reproduce the above copyright notice, this list
  1692. * of conditions and the following disclaimer in the documentation and/or other materials
  1693. * provided with the distribution.
  1694. *
  1695. * Neither the name of the author nor the names of contributors may be used to endorse
  1696. * or promote products derived from this software without specific prior written permission.
  1697. *
  1698. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  1699. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  1700. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  1701. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  1702. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  1703. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  1704. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1705. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  1706. * OF THE POSSIBILITY OF SUCH DAMAGE.
  1707. *
  1708. */