国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

291 lines
12KB

  1. /***********************************************************
  2. * 使用iframe模拟ajax的窗体,本JS需要引用jquery框架
  3. * 为了支持拖动,需要同时引入jquery.ui.core以及ui.draggable.js
  4. * 修改自 thickbox 源码
  5. ************************************************************/
  6. var $ = jQuery;
  7. var tb_pathToImage = "images/loadinglit.gif";
  8. var ref_parent = false;
  9. var tb_frameid = 0;
  10. /**
  11. * 对于指定了class为'thickbox'的超链接自动监听其超链接,其中可以指定 rel=(0|1) 属性决定点击关闭后是否刷新上级窗口
  12. * 如果不需要侦听超链接事件,可以禁用些初始化方法
  13. */
  14. $(document).ready(function()
  15. {
  16. tb_init('a.thickbox, area.thickbox, input.thickbox');
  17. imgLoader = new Image();
  18. imgLoader.src = tb_pathToImage;
  19. });
  20. function tb_init(domChunk)
  21. {
  22. $(domChunk).click(function(){
  23. var t = this.title || this.name || null;
  24. var a = this.href || this.alt;
  25. var g = this.rel || false;
  26. tb_show(t, a, g);
  27. this.blur();
  28. return false;
  29. });
  30. }
  31. /**
  32. * 弹窗警告窗口让用户确认操作
  33. * refParent 参数(0|1)决定点击关闭后是否刷新上级窗口
  34. */
  35. function tb_action(msg, gourl)
  36. {
  37. msg += "<br/><a href='javascript:tb_remove();'>&lt;&lt;点错了</a> &nbsp;|&nbsp; <a href='"+gourl+"'>确定要操作&gt;&gt;</a>";
  38. tb_showmsg(msg);
  39. }
  40. /**
  41. * 弹窗主函数
  42. * refParent 参数(0|1)决定点击关闭后是否刷新上级窗口
  43. */
  44. function tb_show(caption, url, refParent)
  45. {
  46. ref_parent = refParent;
  47. if (typeof document.body.style.maxHeight === "undefined")
  48. {
  49. $("body","html").css({height: "100%", width: "100%"});
  50. $("html").css("overflow","hidden");
  51. if (document.getElementById("TB_HideSelect") === null) {
  52. $("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
  53. $("#TB_overlay").click(tb_remove);
  54. }
  55. }
  56. else
  57. {
  58. if(document.getElementById("TB_overlay") === null){
  59. $("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
  60. $("#TB_overlay").click(tb_remove);
  61. }
  62. }
  63. if(tb_detectMacXFF()){
  64. $("#TB_overlay").addClass("TB_overlayMacFFBGHack");
  65. }else{
  66. $("#TB_overlay").addClass("TB_overlayBG");
  67. }
  68. if(caption===null) caption="消息窗口";
  69. $("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");
  70. $('#TB_load').show();
  71. var baseURL;
  72. if(url.indexOf("?")!==-1){
  73. baseURL = url.substr(0, url.indexOf("?"));
  74. }else{
  75. baseURL = url;
  76. }
  77. var queryString = url.replace(/^[^\?]+\??/,'');
  78. var params = tb_parseQuery( queryString );
  79. TB_WIDTH = (params['width']*1) + 30 || 630;
  80. TB_HEIGHT = (params['height']*1) + 40 || 420;
  81. ajaxContentW = TB_WIDTH - 30;
  82. ajaxContentH = TB_HEIGHT - 45;
  83. // either iframe or ajax window
  84. if(url.indexOf('TB_iframe') != -1)
  85. {
  86. urlNoQuery = url.split('TB_');
  87. $("#TB_iframeContent").remove();
  88. tb_frameid++;
  89. if(params['modal'] != "true"){
  90. $("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='javascript:void(0);' id='TB_closeWindowButton' title='关闭'>关闭</a></div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
  91. }else{
  92. $("#TB_overlay").unbind();
  93. $("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+tb_frameid+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
  94. }
  95. }
  96. // not an iframe, ajax
  97. else
  98. {
  99. if($("#TB_window").css("display") != "block"){
  100. if(params['modal'] != "true"){
  101. $("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='javascript:void(0);' id='TB_closeWindowButton' title='关闭'>关闭</a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
  102. }else{
  103. $("#TB_overlay").unbind();
  104. $("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");
  105. }
  106. }else{
  107. $("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
  108. $("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
  109. $("#TB_ajaxContent")[0].scrollTop = 0;
  110. $("#TB_ajaxWindowTitle").html(caption);
  111. }
  112. }
  113. $("#TB_closeWindowButton").click(tb_remove);
  114. if(url.indexOf('TB_inline') != -1)
  115. {
  116. $("#TB_ajaxContent").append($('#' + params['inlineId']).children());
  117. $("#TB_window").unload(function () {
  118. $('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
  119. });
  120. tb_position();
  121. $("#TB_load").remove();
  122. $("#TB_window").css({display:"block"});
  123. }
  124. else if(url.indexOf('TB_iframe') != -1)
  125. {
  126. tb_position();
  127. if($.browser.safari){//safari needs help because it will not fire iframe onload
  128. $("#TB_load").remove();
  129. $("#TB_window").css({display:"block"});
  130. }
  131. }
  132. else
  133. {
  134. $("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
  135. tb_position();
  136. $("#TB_load").remove();
  137. tb_init("#TB_ajaxContent a.thickbox");
  138. $("#TB_window").css({display:"block"});
  139. });
  140. }
  141. $("#TB_window").draggable(); //支持窗口拖动
  142. //alert( $("#TB_window").get(0).innerHTML );
  143. if(!params['modal'])
  144. {
  145. document.onkeyup = function(e){ kc = (e == null ? event.keyCode : e.which); if(kc == 27){ tb_remove(); } };
  146. }
  147. }
  148. /**
  149. * 弹窗信息框
  150. */
  151. function tb_showmsg(msg, caption, talign, ww, wh)
  152. {
  153. //默认参数
  154. if(!caption || caption=="") caption="消息窗口";
  155. if(!talign) talign = "center";
  156. if(!ww) ww = "350px";
  157. if(!wh) wh = "180px";
  158. if (typeof document.body.style.maxHeight === "undefined") {
  159. $("body","html").css({height: "100%", width: "100%"});
  160. $("html").css("overflow","hidden");
  161. }
  162. if(document.getElementById("TB_overlay") === null){
  163. $("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
  164. $("#TB_overlay").click(tb_remove);
  165. }
  166. if(tb_detectMacXFF()){
  167. $("#TB_overlay").addClass("TB_overlayMacFFBGHack");
  168. }else{
  169. $("#TB_overlay").addClass("TB_overlayBG");
  170. }
  171. $("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='关闭'>关闭</a></div></div><div id='TB_ajaxContent'><table width='100%'><tr><td valign='middle' style='height:100%;font-size:14px;line-height:28px;' align='"+talign+"'>"+ msg +"</td></tr></table></div>");
  172. $("#TB_closeWindowButton").click(tb_remove);
  173. $("#TB_window").css({display:"block"});
  174. topx = ($.browser.msie)? 150 : 50;
  175. $("#TB_window").css({top: topx + "px"});
  176. $("#TB_window")[0].style.width = ww;
  177. $("#TB_window")[0].style.height = wh;
  178. $("#TB_window").draggable(); //支持窗口拖动
  179. document.onkeyup = function(e){ kc = (e == null ? event.keyCode : e.which); if(kc == 27){ tb_remove(); } };
  180. }
  181. //helper functions below
  182. function tb_showIframe()
  183. {
  184. $("#TB_load").remove();
  185. $("#TB_window").css({display:"block"});
  186. }
  187. // 增加父级框架关闭内容的方法
  188. function tb_remove()
  189. {
  190. var isparent = $("#TB_imageOff",parent.document).length;
  191. if(isparent )
  192. {
  193. $("#TB_imageOff",parent.document).unbind("click");
  194. $("#TB_closeWindowButton",parent.document).unbind("click");
  195. $("#TB_window",parent.document).fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect',parent.document).trigger("unload").unbind().remove();});
  196. $("#TB_load",parent.document).remove();
  197. //if IE 6
  198. if (typeof parent.document.body.style.maxHeight == "undefined")
  199. {
  200. $("body","html",parent.document).css({height: "auto", width: "auto"});
  201. $("html",parent.document).css("overflow","");
  202. }
  203. document.onkeydown = "";
  204. document.onkeyup = "";
  205. if( ref_parent ) location.reload();
  206. return;
  207. } else {
  208. $("#TB_imageOff").unbind("click");
  209. $("#TB_closeWindowButton").unbind("click");
  210. $("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
  211. $("#TB_load").remove();
  212. //if IE 6
  213. if (typeof document.body.style.maxHeight == "undefined")
  214. {
  215. $("body","html").css({height: "auto", width: "auto"});
  216. $("html").css("overflow","");
  217. }
  218. document.onkeydown = "";
  219. document.onkeyup = "";
  220. if( ref_parent ) location.reload();
  221. return;
  222. }
  223. }
  224. function tb_position()
  225. {
  226. $("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
  227. // take away IE6
  228. if ( !(jQuery.browser.msie && jQuery.browser.version < 7))
  229. {
  230. $("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
  231. }
  232. }
  233. function tb_parseQuery ( query )
  234. {
  235. var Params = {};
  236. if ( ! query ) {return Params;}// return empty object
  237. var Pairs = query.split(/[;&]/);
  238. for ( var i = 0; i < Pairs.length; i++ ) {
  239. var KeyVal = Pairs[i].split('=');
  240. if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
  241. var key = unescape( KeyVal[0] );
  242. var val = unescape( KeyVal[1] );
  243. val = val.replace(/\+/g, ' ');
  244. Params[key] = val;
  245. }
  246. return Params;
  247. }
  248. function tb_getPageSize()
  249. {
  250. var de = document.documentElement;
  251. var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  252. var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
  253. arrayPageSize = [w,h];
  254. return arrayPageSize;
  255. }
  256. function tb_detectMacXFF()
  257. {
  258. var userAgent = navigator.userAgent.toLowerCase();
  259. if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
  260. return true;
  261. }
  262. }