main.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /**
  2. * Created by 23rd and Walnut
  3. * www.23andwalnut.com
  4. * User: Saleem El-Amin
  5. * Date: Jun 11, 2010
  6. * Time: 7:55:26 PM
  7. */
  8. $(document).ready(function()
  9. {
  10. var loading_indicator = '<div class="loading-indicator">' +
  11. '<div class="loading-overlay">&nbsp;</div>' +
  12. '<img class="loading" src="application/views/images/loading.gif" />' +
  13. '</div>';
  14. function ie8up()
  15. {
  16. if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
  17. { //test for MSIE x.x;
  18. var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
  19. if (ieversion >= 8)
  20. return true;
  21. else if (ieversion >= 7)
  22. return false;
  23. else if (ieversion >= 6)
  24. return false;
  25. else if (ieversion >= 5)
  26. return false;
  27. } else return true;
  28. }
  29. if (ie8up())
  30. {
  31. $('.pagination a, .hide-messages a').live('click', function(e)
  32. {
  33. e.preventDefault();
  34. $('#page-content').append(loading_indicator);
  35. $('#page-content-outer').load($(this).attr('href') + ' #page-content', function()
  36. {
  37. $('.loading-indicator').remove();
  38. });
  39. return false;
  40. });
  41. }
  42. /** Load content into modal box **/
  43. if (ie8up())
  44. {
  45. $('.small-button.modal, .modal a, a.modal, .no-files a.small-button, .client-actions a, .add-item a, a.edit-icon, a.delete-icon, .project-actions a').live('click', function()
  46. {
  47. $('body').append(loading_indicator);
  48. $('#modal-body').load($(this).attr('href') + ' .form', function()
  49. {
  50. $('.loading-indicator').remove();
  51. $('#modal').jqmShow();
  52. var modal_y = ($(window).height() - $('#modal').height())/2;
  53. modal_y = (modal_y < 0)? 0 : modal_y;
  54. var modal_x = ($(window).width() - $('#modal').width())/2;
  55. $('#modal').css({'top':modal_y, 'left':modal_x});
  56. });
  57. return false;
  58. });
  59. }
  60. function preloadImages(imageList, callback)
  61. {
  62. var i, total, loaded = 0;
  63. if (typeof imageList != 'undefined')
  64. {
  65. if ($.isArray(imageList))
  66. {
  67. total = imageList.length; // used later
  68. for (var i = 0; i < total; i++)
  69. {
  70. images[imageList[i]] = new Image();
  71. images[imageList[i]].onload = function()
  72. {
  73. loaded++;
  74. if (loaded == total)
  75. {
  76. if ($.isFunction(callback))
  77. {
  78. callback();
  79. }
  80. }
  81. };
  82. images[imageList[i]].src = imageList[i];
  83. }
  84. }
  85. }
  86. }
  87. var imageList = [];
  88. var images = [];
  89. var preload = [
  90. 'application/views/images/loading.gif',
  91. 'application/views/images/small-button.png'];
  92. $('#modal').jqm();
  93. preloadImages(preload);
  94. });
  95. /*
  96. * jqModal - Minimalist Modaling with jQuery
  97. * (http://dev.iceburg.net/jquery/jqModal/)
  98. *
  99. * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
  100. * Dual licensed under the MIT and GPL licenses:
  101. * http://www.opensource.org/licenses/mit-license.php
  102. * http://www.gnu.org/licenses/gpl.html
  103. *
  104. * $Version: 03/01/2009 +r14
  105. */
  106. (function($)
  107. {
  108. $.fn.jqm = function(o)
  109. {
  110. var p = {
  111. overlay: 50,
  112. overlayClass: 'jqmOverlay',
  113. closeClass: 'jqmClose',
  114. trigger: '.jqModal',
  115. ajax: F,
  116. ajaxText: '',
  117. target: F,
  118. modal: F,
  119. toTop: F,
  120. onShow: F,
  121. onHide: F,
  122. onLoad: F
  123. };
  124. return this.each(function()
  125. {
  126. if (this._jqm)return H[this._jqm].c = $.extend({}, H[this._jqm].c, o);
  127. s++;
  128. this._jqm = s;
  129. H[s] = {c:$.extend(p, $.jqm.params, o),a:F,w:$(this).addClass('jqmID' + s),s:s};
  130. if (p.trigger)$(this).jqmAddTrigger(p.trigger);
  131. });
  132. };
  133. $.fn.jqmAddClose = function(e)
  134. {
  135. return hs(this, e, 'jqmHide');
  136. };
  137. $.fn.jqmAddTrigger = function(e)
  138. {
  139. return hs(this, e, 'jqmShow');
  140. };
  141. $.fn.jqmShow = function(t)
  142. {
  143. return this.each(function()
  144. {
  145. t = t || window.event;
  146. $.jqm.open(this._jqm, t);
  147. });
  148. };
  149. $.fn.jqmHide = function(t)
  150. {
  151. return this.each(function()
  152. {
  153. t = t || window.event;
  154. $.jqm.close(this._jqm, t)
  155. });
  156. };
  157. $.jqm = {
  158. hash:{},
  159. open:function(s, t)
  160. {
  161. var h = H[s],c = h.c,cc = '.' + c.closeClass,z = (parseInt(h.w.css('z-index'))),z = (z > 0) ? z : 3000,o = $('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z - 1,opacity:c.overlay / 100});
  162. if (h.a)return F;
  163. h.t = t;
  164. h.a = true;
  165. h.w.css('z-index', z);
  166. if (c.modal)
  167. {
  168. if (!A[0])L('bind');
  169. A.push(s);
  170. }
  171. else if (c.overlay > 0)h.w.jqmAddClose(o);
  172. else o = F;
  173. h.o = (o) ? o.addClass(c.overlayClass).prependTo('body') : F;
  174. if (ie6)
  175. {
  176. $('html,body').css({height:'100%',width:'100%'});
  177. if (o)
  178. {
  179. o = o.css({position:'absolute'})[0];
  180. for (var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(), "(_=(document.documentElement.scroll" + y + " || document.body.scroll" + y + "))+'px'");
  181. }
  182. }
  183. if (c.ajax)
  184. {
  185. var r = c.target || h.w,u = c.ajax,r = (typeof r == 'string') ? $(r, h.w) : $(r),u = (u.substr(0, 1) == '@') ? $(t).attr(u.substring(1)) : u;
  186. r.html(c.ajaxText).load(u, function()
  187. {
  188. if (c.onLoad)c.onLoad.call(this, h);
  189. if (cc)h.w.jqmAddClose($(cc, h.w));
  190. e(h);
  191. });
  192. }
  193. else if (cc)h.w.jqmAddClose($(cc, h.w));
  194. if (c.toTop && h.o)h.w.before('<span id="jqmP' + h.w[0]._jqm + '"></span>').insertAfter(h.o);
  195. (c.onShow) ? c.onShow(h) : h.w.show();
  196. e(h);
  197. return F;
  198. },
  199. close:function(s)
  200. {
  201. var h = H[s];
  202. if (!h.a)return F;
  203. h.a = F;
  204. if (A[0])
  205. {
  206. A.pop();
  207. if (!A[0])L('unbind');
  208. }
  209. if (h.c.toTop && h.o)$('#jqmP' + h.w[0]._jqm).after(h.w).remove();
  210. if (h.c.onHide)h.c.onHide(h); else
  211. {
  212. h.w.hide();
  213. if (h.o)h.o.remove();
  214. }
  215. return F;
  216. },
  217. params:{}};
  218. var s = 0,H = $.jqm.hash,A = [],ie6 = $.browser.msie && ($.browser.version == "6.0"),F = false,
  219. i = $('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),
  220. e = function(h)
  221. {
  222. if (ie6)if (h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i); else if (!$('iframe.jqm', h.w)[0])h.w.prepend(i);
  223. f(h);
  224. },
  225. f = function(h)
  226. {
  227. try
  228. {
  229. $(':input:visible', h.w)[0].focus();
  230. } catch(_)
  231. {
  232. }
  233. },
  234. L = function(t)
  235. {
  236. $()[t]("keypress", m)[t]("keydown", m)[t]("mousedown", m);
  237. },
  238. m = function(e)
  239. {
  240. var h = H[A[A.length - 1]],r = (!$(e.target).parents('.jqmID' + h.s)[0]);
  241. if (r)f(h);
  242. return !r;
  243. },
  244. hs = function(w, t, c)
  245. {
  246. return w.each(function()
  247. {
  248. var s = this._jqm;
  249. $(t).each(function()
  250. {
  251. if (!this[c])
  252. {
  253. this[c] = [];
  254. $(this).click(function()
  255. {
  256. for (var i in {jqmShow:1,jqmHide:1})for (var s in this[i])if (H[this[i][s]])H[this[i][s]].w[i](this);
  257. return F;
  258. });
  259. }
  260. this[c].push(s);
  261. });
  262. });
  263. };
  264. })(jQuery);