fw.tip.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /**
  2. * @author herong
  3. * 提示组件
  4. */
  5. var CFWTip = _FW.fCreateClass();
  6. /**
  7. * 提示组件API
  8. */
  9. CFWTip.prototype = {
  10. /**
  11. * 初始化
  12. * */
  13. fInitialize : function (options){
  14. },
  15. /**
  16. * 验证提示框,显示3秒后自动隐蔽
  17. * @param findObj(必需)控件对象
  18. * @param msg 提示信息
  19. * <pre>
  20. * 使用举例:
  21. * CFW.oTip.fnValidateTip(cbxxForm.XM,"姓名输入不合法");
  22. * </pre>
  23. */
  24. fnValidateTip : function (findObj, msg){
  25. var defaults = {content: {text: msg},
  26. hide: {delay: 0,
  27. event: false,
  28. inactive: 3000},
  29. position:{my: 'center left', // 默认显示在右侧
  30. at: 'center right'}};
  31. var $findObj = $(findObj);
  32. //距离浏览器窗口右边的距离
  33. var distance = document.body.clientWidth - $findObj.get(0).getBoundingClientRect().right;
  34. if(distance <= 200){//如果距离浏览器右边的距离少于200px,则提示信息在下方显示
  35. defaults.position = {my: 'top center',
  36. at: 'bottom center'};
  37. if($findObj.hasClass("fwcombox-arrow")){
  38. $findObj.prev().qtip(defaults).qtip("show");
  39. }
  40. else{
  41. $findObj.qtip(defaults).qtip("show");
  42. }
  43. }
  44. else{
  45. $findObj.qtip(defaults).qtip("show");
  46. }
  47. },
  48. /**
  49. * 有标题和关闭按钮的提示框
  50. * @param oFindObj(必需)控件对象
  51. * @param sTitleStr 标题
  52. * @param sMsg 提示信息
  53. * <pre>
  54. * 使用举例:
  55. * CFW.oTip.fnTipDialog(cbxxForm.XM,"错误提示","姓名输入不合法");
  56. * </pre>
  57. */
  58. fnTipDialog : function (findObj, titleStr, msg){
  59. var isTitle = true;
  60. if (jQuery.trim(msg) != ''){
  61. isTitle = false;
  62. }
  63. this.fnShowTip(findObj, msg, {hide: {event: false},
  64. content:{title: {text: titleStr, // Give the tooltip a title using each elements text
  65. button: true},
  66. text: function(){
  67. return !isTitle ? msg : $(this).attr('title');}},
  68. position:{my: 'left center', // Use the corner...
  69. at: 'right center' // ...and opposite corner
  70. }}).qtip('show');
  71. },
  72. /**
  73. * 普通提示框(可以显示title属性内容,或提定要示的内容)
  74. * @param oFindObj(必需)控件对象
  75. * @param sMsg 提示信息
  76. * @returns oQtip对象
  77. * <pre>
  78. * 使用举例:
  79. * CFW.oTip.fnTip('a[title]',"提示信息");
  80. * </pre>
  81. */
  82. fnTip : function (findObj, msg){
  83. var isTitle = true;
  84. var options = {};
  85. if (jQuery.trim(msg) != ''){
  86. isTitle = false;
  87. }
  88. var defaults =
  89. {content: {text: function() {return !isTitle ? msg : $(this).attr('title');}},
  90. hide:{delay: 3000,
  91. event: false,
  92. inactive: 3000},
  93. position: {my: 'left center', // Use the corner...
  94. at: 'right center' // ...and opposite corner
  95. }};
  96. jQuery.extend(true,defaults,options);
  97. $(findObj).qtip(defaults).qtip('show');
  98. },
  99. /**
  100. * 普通提示框(可以显示title属性内容,或提定要示的内容) alert title 未能显示
  101. * @param oFindObj(必需)控件对象
  102. * @param sMsg 提示信息
  103. * @param sOptions 参数
  104. * @returns oQtip对象
  105. * <pre>
  106. * 使用举例:
  107. * CFW.oTip.fnShowTip('a[title]',"提示信息");
  108. * </pre>
  109. */
  110. fnShowTip : function (findObj, msg, options){
  111. var isTitle = true;
  112. var options2 = options == undefined || options == null ? {} : options;
  113. if (jQuery.trim(msg) != ''){
  114. isTitle = false;
  115. }
  116. var defaults = {content: {
  117. text: function() {
  118. return !isTitle ? msg : $(this).attr('title');
  119. }
  120. },
  121. position: {
  122. my: 'left center', // Use the corner...
  123. at: 'right center' // ...and opposite corner
  124. }};
  125. jQuery.extend(true,defaults,options2);
  126. return $(findObj).qtip(defaults);
  127. },
  128. /**
  129. * ajax动态内容提示框
  130. * @param oFindObj(必需) 控件对象
  131. * @param sOptions(必需) 参数
  132. * <pre>
  133. * 使用举例:
  134. * CFW.oTip.fnTipDynamic("a[name='hrefTip']", options);
  135. * 定义的 options
  136. * {
  137. title:{
  138. text: '提示',
  139. button: true
  140. },
  141. position:{
  142. at: 'bottom right',
  143. my: 'top left',
  144. viewport: $(window)
  145. }
  146. * </pre>
  147. */
  148. fnTipDynamic : function (findObj, options){
  149. var defaultOptions = {
  150. title:{
  151. text: '提示',
  152. button: true
  153. },
  154. position:{
  155. at: 'bottom right',
  156. my: 'top left',
  157. viewport: $(window)
  158. },
  159. style:'ui-tooltip-wiki'
  160. };
  161. jQuery.extend(defaultOptions,options || {});
  162. $(findObj).each(function()
  163. {
  164. // We make use of the .each() loop to gain access to each element via the "this" keyword...
  165. $(this).qtip(
  166. {
  167. content: {
  168. text: '<img class="throbber" src="'+contextPath+'/js/ui/qtip/images/throbber.gif" alt="Loading..." />',
  169. ajax: defaultOptions.ajax || $(this).attr('rel'),
  170. title: defaultOptions.title
  171. },
  172. position: defaultOptions.position,
  173. show: {
  174. event: 'click',
  175. solo: true // Only show one tooltip at a time
  176. },
  177. hide: 'unfocus',
  178. style:defaultOptions.style
  179. })
  180. // Make sure it doesn't follow the link when we click it
  181. .click(function() { return false; });
  182. }).qtip('show');
  183. defaultOptions = null;
  184. },
  185. /**
  186. * 提示框
  187. * @param msg(必需) 提示信息
  188. * <pre>
  189. * 使用举例:
  190. * CFW.oTip.fnAlert('操作成功');
  191. * </pre>
  192. */
  193. fnAlert : function (msg){
  194. return alert(msg);
  195. },
  196. fnOpenProcess : function(){
  197. var MainID="_FWOPACITYDIV";
  198. var DlgID="_FWPROCESS";
  199. if(document.getElementById(MainID)==null){
  200. var MainNode=document.createElement("div");
  201. MainNode.setAttribute("id",MainID);
  202. MainNode.style.backgroundColor="#0096FF";
  203. MainNode.style.left="0px";
  204. MainNode.style.top="0px";
  205. MainNode.style.width="0px";
  206. MainNode.style.height="0px";
  207. MainNode.innerHTML="";
  208. MainNode.style.position="absolute";
  209. MainNode.style.zIndex="400";
  210. MainNode.style.display="none";
  211. $(MainNode).css({'opacity':'0.1'});
  212. document.body.appendChild(MainNode);
  213. }
  214. if(document.getElementById(DlgID)==null){
  215. //--------------------------------------------------------- 对话框----------------
  216. var dlgNode=document.createElement("div");
  217. dlgNode.setAttribute("id",DlgID);
  218. dlgNode.style.backgroundColor="#FFFFFF";
  219. dlgNode.style.zIndex="420";
  220. dlgNode.style.display="none";
  221. dlgNode.style.border="10"+"px";
  222. dlgNode.style.border_color="#FF0000";
  223. dlgNode.style.border_style="solid";
  224. dlgNode.innerHTML= "<img style=\"\" src=\""+contextPath+"/themes/default/images/process.gif\" />";
  225. dlgNode.style.left="0px";
  226. dlgNode.style.top="0px";
  227. dlgNode.style.width="190"+"px";
  228. dlgNode.style.height="14"+"px";
  229. dlgNode.style.position="absolute";
  230. document.body.appendChild(dlgNode);
  231. }
  232. var Dwidth;
  233. var Dheight;
  234. if (document.compatMode == 'BackCompat') {
  235. Dwidth=Math.max(document.body.scrollWidth, document.body.clientWidth);
  236. Dheight=Math.max(document.body.scrollHeight, document.body.clientHeight);
  237. } else {
  238. Dwidth=Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth);
  239. Dheight=Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight);
  240. }
  241. var CHeight=$(window).height();
  242. var CWidth=$(window).width();
  243. var scrolltop=$(document).scrollTop();
  244. var Dlgwidth=document.getElementById(DlgID).style.width;
  245. var DlgHeight=document.getElementById(DlgID).style.height;
  246. document.getElementById(MainID).style.width=Dwidth+"px";
  247. document.getElementById(MainID).style.height=Dheight+"px";
  248. document.getElementById(DlgID).style.left=(CWidth/2)-(parseInt(Dlgwidth)/2)+"px";
  249. document.getElementById(DlgID).style.top=(scrolltop+CHeight/2-parseInt(DlgHeight)/2)+"px";
  250. document.getElementById(MainID).style.display="block";
  251. document.getElementById(DlgID).style.display="block";
  252. },
  253. fnCloseProcess : function(){
  254. var MainID="_FWOPACITYDIV";
  255. var DlgID="_FWPROCESS";
  256. var MainIDNode=document.getElementById(MainID);
  257. var DlgIDNode=document.getElementById(DlgID);
  258. if(MainIDNode!=null){
  259. document.body.removeChild(MainIDNode);
  260. }
  261. if(DlgIDNode!=null){
  262. document.body.removeChild(DlgIDNode);
  263. }
  264. }
  265. };