MTooltips.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. var MTooltips = new Class({
  2. Extends: MWF.widget.Common,
  3. Implements: [Options, Events],
  4. options : {
  5. style : "", //如果有style,就加载 style/css.wcss
  6. axis: "y", //箭头在x轴还是y轴上展现
  7. position : { //node 固定的位置
  8. x : "auto", //x轴上left center right, auto 系统自动计算
  9. y : "auto" //y 轴上top middle bottom, auto 系统自动计算
  10. },
  11. priorityOfAuto :{
  12. x : [ "center", "right", "left" ], //当position x 为 auto 时候的优先级
  13. y : [ "middle", "bottom", "top" ] //当position y 为 auto 时候的优先级
  14. },
  15. isFitToContainer : true, //当position x 不为 auto, y 不为 auto 的时候,自动设置偏移量,使tooltip不超过容器的可见范围
  16. event : "mouseenter", //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  17. hiddenDelay : 200, //ms , 有target 且 事件类型为 mouseenter 时有效
  18. displayDelay : 0, //ms , 有target 且事件类型为 mouseenter 时有效
  19. hasArrow : true,
  20. isAutoShow : true,
  21. isAutoHide : true,
  22. hasMask : true,
  23. hasCloseAction : false,
  24. overflow : "hidden" //弹出框高宽超过container的时候怎么处理,hidden 表示超过的隐藏,scroll 表示超过的时候显示滚动条
  25. },
  26. initialize : function( container, target, app, data, options, targetCoordinates ){
  27. //可以传入target 或者 targetCoordinates,两种选一
  28. //传入target,表示触发tooltip的节点,本类根据 this.options.event 自动绑定target的事件
  29. //传入targetCoordinates,表示 出发tooltip的位置,本类不绑定触发事件
  30. if( options ){
  31. this.setOptions(options);
  32. }
  33. this.container = container;
  34. this.target = target;
  35. this.targetCoordinates = targetCoordinates;
  36. this.app = app;
  37. if(app)this.lp = app.lp;
  38. this.data = data;
  39. this.path = "/x_component_Template/$MTooltips/";
  40. if( this.target ){
  41. this.setTargetEvents();
  42. }
  43. this.fireEvent("postInitialize",[this]);
  44. },
  45. setTargetEvents : function(){
  46. if( this.options.event == "click" ){
  47. if( this.options.isAutoShow ){
  48. this.targetClickFun = function( ev ){
  49. this.load();
  50. ev.stopPropagation();
  51. }.bind(this);
  52. this.target.addEvents({
  53. "click": this.targetClickFun
  54. });
  55. }
  56. }else{
  57. if( this.options.isAutoHide || this.options.isAutoShow ){
  58. this.targetMouseenterFun = function(){
  59. if( this.timer_hide ){
  60. clearTimeout(this.timer_hide);
  61. }
  62. }.bind(this);
  63. this.target.addEvents({
  64. "mouseenter": this.targetMouseenterFun
  65. });
  66. }
  67. if( this.options.isAutoShow ){
  68. this.targetMouseenterFun2 = function(){
  69. if( this.status != "display" ){
  70. this.timer_show = setTimeout( this.load.bind(this),this.options.displayDelay );
  71. }
  72. }.bind(this);
  73. this.target.addEvents({
  74. "mouseenter": this.targetMouseenterFun2
  75. });
  76. }
  77. if( this.options.isAutoHide || this.options.isAutoShow ){
  78. this.targetMouseleaveFun = function(){
  79. if( this.timer_show ){
  80. clearTimeout(this.timer_show);
  81. }
  82. }.bind(this);
  83. this.target.addEvents({
  84. "mouseleave" : this.targetMouseleaveFun
  85. });
  86. }
  87. if( this.options.isAutoHide ){
  88. this.targetMouseleaveFun2 = function(){
  89. if( this.status == "display" ){
  90. this.timer_hide = setTimeout( this.hide.bind(this),this.options.hiddenDelay );
  91. }
  92. }.bind(this);
  93. this.target.addEvents({
  94. "mouseleave" : this.targetMouseleaveFun2
  95. });
  96. }
  97. }
  98. },
  99. load: function(){
  100. this.fireEvent("queryLoad",[this]);
  101. if( this.isEnable() ){
  102. if( this.node ){
  103. this.show();
  104. }else{
  105. this.create();
  106. }
  107. if( this.options.event == "click" ) {
  108. if( this.options.isAutoHide ){
  109. if( !this.options.hasMask ){
  110. this.containerClickFun = function(e){
  111. if( this.status === "display" ){
  112. this.hide();
  113. }
  114. e.stopPropagation();
  115. }.bind(this);
  116. this.container.addEvent("click", this.containerClickFun )
  117. }
  118. }
  119. }
  120. }
  121. this.fireEvent("postLoad",[this]);
  122. },
  123. hide: function(){
  124. if( this.node ){
  125. this.node.setStyle("display","none");
  126. this.status = "hidden";
  127. if( this.maskNode ){
  128. this.maskNode.setStyle("display","none");
  129. }
  130. if( this.containerClickFun ){
  131. this.container.removeEvent("click", this.containerClickFun );
  132. this.containerClickFun = null;
  133. }
  134. this.fireEvent("hide",[this]);
  135. }
  136. },
  137. show: function(){
  138. this.status = "display";
  139. if( this.maskNode ){
  140. this.maskNode.setStyle("display","");
  141. }
  142. this.node.setStyle("display","");
  143. this.setCoondinates();
  144. this.fireEvent("show",[this]);
  145. },
  146. create: function(){
  147. this.status = "display";
  148. this.fireEvent("queryCreate",[this]);
  149. this.loadStyle();
  150. this.node = new Element("div.tooltipNode", {
  151. styles : this.nodeStyles
  152. }).inject( this.container );
  153. if( this.contentNode ){
  154. this.contentNode.inject( this.node );
  155. }else{
  156. this.contentNode = new Element("div",{
  157. styles : this.contentStyles
  158. }).inject( this.node );
  159. this.contentNode.set("html", this._getHtml() );
  160. }
  161. this._customNode( this.node, this.contentNode );
  162. if( this.options.hasArrow ){
  163. this.arrowNode = new Element("div.arrowNode", {
  164. "styles": this.arrowStyles
  165. }
  166. ).inject(this.node);
  167. }
  168. if( this.options.hasCloseAction ){
  169. this.closeActionNode = new Element("div", {
  170. styles : this.closeActionStyles,
  171. events : {
  172. click : function(){ this.hide() }.bind(this)
  173. }
  174. }).inject( this.node );
  175. }
  176. this._loadCustom( function(){
  177. this.setCoondinates();
  178. }.bind(this));
  179. if( this.options.event == "click" ) {
  180. if( this.options.isAutoHide ){
  181. if( this.options.hasMask ){
  182. this.maskNode = new Element("div.maskNode", {
  183. "styles": this.maskStyles,
  184. "events": {
  185. "mouseover": function (e) {
  186. e.stopPropagation();
  187. },
  188. "mouseout": function (e) {
  189. e.stopPropagation();
  190. },
  191. "click": function (e) {
  192. this.hide();
  193. e.stopPropagation();
  194. }.bind(this)
  195. }
  196. }).inject( this.container );
  197. }
  198. if( this.app ){
  199. this.hideFun_resize = this.hide.bind(this);
  200. this.app.addEvent( "resize" , this.hideFun_resize );
  201. }
  202. }
  203. }else{
  204. if( this.options.isAutoHide || this.options.isAutoShow ){
  205. this.node.addEvents({
  206. "mouseenter": function(){
  207. if( this.timer_hide )clearTimeout(this.timer_hide);
  208. }.bind(this)
  209. });
  210. }
  211. if( this.options.isAutoHide ){
  212. this.node.addEvents({
  213. "mouseleave" : function(){
  214. this.timer_hide = setTimeout( this.hide.bind(this),this.options.hiddenDelay );
  215. }.bind(this)
  216. });
  217. }
  218. }
  219. //this.target.addEvent( "mouseleave", function(){
  220. // this.timer_hide = setTimeout( this.hide.bind(this), this.options.HiddenDelay );
  221. //}.bind(this));
  222. this.fireEvent("postCreate",[this]);
  223. },
  224. loadStyle : function(){
  225. if( this.options.style ){
  226. this.cssPath = this.path+this.options.style+"/css.wcss";
  227. this._loadCss();
  228. }
  229. this.nodeStyles = {
  230. "font-size" : "12px",
  231. "position" : "absolute",
  232. "max-width" : "500px",
  233. "min-width" : "260px",
  234. "z-index" : "11",
  235. "background-color" : "#fff",
  236. "padding" : "10px",
  237. "border-radius" : "8px",
  238. "box-shadow": "0 0 18px 0 #999999",
  239. "-webkit-user-select": "text",
  240. "-moz-user-select": "text"
  241. };
  242. if( this.options.nodeStyles ){ //兼容之前在options里设置nodeStyles
  243. this.nodeStyles = Object.merge( this.nodeStyles, this.options.nodeStyles );
  244. }else if( this.css && this.css.nodeStyles ){
  245. this.nodeStyles = this.css.nodeStyles
  246. }
  247. if( this.css && this.css.contentStyles ){
  248. this.contentStyles = this.css.contentStyles;
  249. }else{
  250. this.contentStyles = {
  251. "width" : "100%",
  252. "height" : "100%"
  253. }
  254. }
  255. if( this.options.hasArrow ){
  256. if( this.css && this.css.arrowStyles ){
  257. this.arrowStyles = this.css.arrowStyles
  258. }else{
  259. this.arrowStyles = {
  260. "width": this.options.axis == "x" ? "9px" : "17px",
  261. "height" : this.options.axis == "x" ? "17px" : "9px",
  262. "position":"absolute",
  263. "background" : "no-repeat url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAAlCAYAAACgc9J8AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAP9JREFUeNq01oENhCAMBdCWuIgTuP8WOoGj9GhSDaeUfjiuCSEm+iKFVllESGNdVzrPk55xHIfewHnItm1MrVDMG/u+i0aeyWZp3R9CJRaBIWRB5YUHItAL80AEqmI1EIFcrAQ1rwjUxEoQgULsAue+2ayc/W83p5+z6RXggOO1WQGhrsFXP/Oip58tAaQTZ4QMbEbyEB2GCKEBdtpmru4NsC4aHg8PLJ/3lim2xDv02jYDz1kNQsGEQgiYeqAQBPuZQF1jFKqBYTn1RLK1D4+v3E3NGfgNkJlfdKi0XrUZgc1OWyt0Dwz/z37tGhA20s+WR4t+1iBbzTJyaD8CDAB7WgNSzh/AnwAAAABJRU5ErkJggg==)"
  264. }
  265. }
  266. }
  267. if( this.options.event == "click" && this.options.isAutoHide ) {
  268. if( this.css && this.css.maskStyles ){
  269. this.maskStyles = this.css.maskStyles;
  270. }else{
  271. this.maskStyles = {
  272. "width": "100%",
  273. "height": "100%",
  274. "opacity": 0,
  275. "position": "absolute",
  276. "background-color": "#fff",
  277. "top": "0px",
  278. "left": "0px"
  279. }
  280. }
  281. }
  282. if( this.options.hasCloseAction ){
  283. if( this.css && this.css.closeActionStyles ){
  284. this.closeActionStyles = this.css.closeActionStyles
  285. }else{
  286. this.closeActionStyles = {
  287. "width": "24px",
  288. "height" : "24px",
  289. "position" : "absolute",
  290. "top": "0px",
  291. "right" : "0px",
  292. "background": "url(/x_component_Template/$MTooltips/default/icon/off_gray.png) no-repeat center center",
  293. "cursor": "pointer"
  294. }
  295. }
  296. }
  297. },
  298. isEnable : function(){
  299. return !this.disable;
  300. },
  301. setCoondinates : function(){
  302. if( this.options.axis == "x" ){
  303. this.setCoondinates_x();
  304. }else{
  305. this.setCoondinates_y();
  306. }
  307. },
  308. setCoondinates_x : function(){
  309. var targetCoondinates = this.target ? this.target.getCoordinates( this.container ) : this.targetCoordinates ;
  310. var node = this.node;
  311. if( this.resetWidth ){
  312. node.setStyles({
  313. overflow : "visible",
  314. width : "auto"
  315. });
  316. if(this.arrowNode)this.arrowNode.setStyle("display","");
  317. this.resetWidth = false;
  318. }
  319. var containerScroll = this.container.getScroll();
  320. var containerSize = this.container.getSize();
  321. var nodeSize = node.getSize();
  322. var left;
  323. var arrowX, arrowY;
  324. var offsetX = this.options.hasArrow ? 10 : 0;
  325. if( this.options.position.x == "left" ) {
  326. left = targetCoondinates.left - nodeSize.x - offsetX;
  327. arrowX = "right";
  328. }else if( this.options.position.x == "right" ){
  329. left = targetCoondinates.right + offsetX;
  330. arrowX = "left";
  331. }else{
  332. var priorityOfAuto = this.options.priorityOfAuto;
  333. if( priorityOfAuto && priorityOfAuto.x ){
  334. for( var i=0; i<priorityOfAuto.x.length; i++ ){
  335. if( priorityOfAuto.x[i] == "left" ){
  336. if( targetCoondinates.left - containerScroll.x > containerSize.x - targetCoondinates.right){
  337. left = targetCoondinates.left - nodeSize.x - offsetX;
  338. arrowX = "right";
  339. break;
  340. }
  341. }
  342. if( priorityOfAuto.x[i] == "right" ){
  343. if( containerSize.x + containerScroll.x - targetCoondinates.right > nodeSize.x ){
  344. left = targetCoondinates.right + offsetX;
  345. arrowX = "left";
  346. break;
  347. }
  348. }
  349. }
  350. }
  351. if( !left ){
  352. if( targetCoondinates.left - containerScroll.x > containerSize.x - targetCoondinates.right){
  353. left = targetCoondinates.left - nodeSize.x - offsetX;
  354. arrowX = "right";
  355. }else{
  356. left = targetCoondinates.right + offsetX;
  357. arrowX = "left";
  358. }
  359. }
  360. }
  361. var top;
  362. if( this.options.position.y == "middle" ){
  363. top = targetCoondinates.top + (targetCoondinates.height/2) - ( nodeSize.y / 2 ) ;
  364. arrowY = "middle";
  365. }else if( this.options.position.y == "top" ){
  366. top = targetCoondinates.bottom - nodeSize.y;
  367. arrowY = "bottom";
  368. }else if( this.options.position.y == "bottom" ){
  369. top = targetCoondinates.top;
  370. arrowY = "top";
  371. }else{
  372. var priorityOfAuto = this.options.priorityOfAuto;
  373. if( priorityOfAuto && priorityOfAuto.y ){
  374. for( var i=0; i<priorityOfAuto.y.length; i++ ){
  375. if( priorityOfAuto.y[i] == "middle" ){
  376. if( targetCoondinates.top + (targetCoondinates.height/2) - ( nodeSize.y / 2 ) > containerScroll.y &&
  377. targetCoondinates.bottom - (targetCoondinates.height/2) + ( nodeSize.y / 2 ) - containerScroll.y < containerSize.y ){
  378. top = targetCoondinates.top + (targetCoondinates.height/2) - ( nodeSize.y / 2 ) ;
  379. arrowY = "middle";
  380. break;
  381. }
  382. }
  383. if( priorityOfAuto.y[i] == "top" ){
  384. if( targetCoondinates.top - containerScroll.y > containerSize.y - targetCoondinates.bottom ){
  385. top = targetCoondinates.bottom - nodeSize.y;
  386. arrowY = "bottom";
  387. break;
  388. }
  389. }
  390. if( priorityOfAuto.y[i] == "bottom" ){
  391. if( containerSize.y + containerScroll.y - targetCoondinates.bottom > nodeSize.y ){
  392. top = targetCoondinates.top;
  393. arrowY = "top";
  394. break;
  395. }
  396. }
  397. }
  398. }
  399. if( !top ){
  400. if( targetCoondinates.top + (targetCoondinates.height/2) - ( nodeSize.y / 2 ) > containerScroll.y &&
  401. targetCoondinates.bottom - (targetCoondinates.height/2) + ( nodeSize.y / 2 ) - containerScroll.y < containerSize.y ){
  402. top = targetCoondinates.top + (targetCoondinates.height/2) - ( nodeSize.y / 2 ) ;
  403. arrowY = "middle";
  404. } else if( targetCoondinates.top - containerScroll.y > containerSize.y - targetCoondinates.bottom ){
  405. top = targetCoondinates.bottom - nodeSize.y;
  406. arrowY = "bottom";
  407. }else{
  408. top = targetCoondinates.top;
  409. arrowY = "top";
  410. }
  411. }
  412. }
  413. var arrowOffsetY = 0;
  414. if( this.options.isFitToContainer ){
  415. if( top < containerScroll.y ){
  416. arrowOffsetY = containerScroll.y - top;
  417. top = containerScroll.y;
  418. }else if( top + nodeSize.y > containerSize.y + containerScroll.y ){
  419. arrowOffsetY = containerSize.y + containerScroll.y - top - nodeSize.y;
  420. top = containerSize.y + containerScroll.y - nodeSize.y;
  421. }
  422. }
  423. if( this.options.overflow == "scroll" ){
  424. if( left < 0 ){
  425. node.setStyles({
  426. "overflow" : "auto",
  427. "width" : nodeSize.x + left - offsetX
  428. });
  429. this.resetWidth = true;
  430. left = 0
  431. }else if( left + nodeSize.x > containerSize.x + containerScroll.x ){
  432. node.setStyles({
  433. "overflow" : "auto",
  434. "width" : Math.abs( containerSize.x + containerScroll.x - left + offsetX )
  435. });
  436. left = left - offsetX;
  437. this.resetWidth = true;
  438. }
  439. }
  440. if( this.resetWidth ){
  441. if( this.arrowNode )this.arrowNode.setStyle("display","none");
  442. }else if( this.options.hasArrow && this.arrowNode ) {
  443. if (arrowX == "left") {
  444. this.arrowNode.setStyles({
  445. "left": "-8px",
  446. "right": "auto",
  447. "background-position": "0px 0px"
  448. });
  449. } else {
  450. this.arrowNode.setStyles({
  451. "left": "auto",
  452. "right": "-8px",
  453. "background-position": "-11px 0px"
  454. });
  455. }
  456. var ah = this.arrowNode.getSize().y / 2;
  457. //var th = targetCoondinates.height / 2 - ah;
  458. var h = Math.min(targetCoondinates.height, nodeSize.y) / 2 - ah;
  459. var radiusDv = 0; //圆角和箭头偏移量的差值
  460. var radius = 0;
  461. if (arrowY == "middle") {
  462. this.arrowNode.setStyles({
  463. "top": (nodeSize.y / 2 - ah) - arrowOffsetY + "px",
  464. "bottom": "auto"
  465. })
  466. } else if (arrowY == "top") {
  467. radius = this.node.getStyle("border-top-" + arrowX + "-radius");
  468. radius = radius ? parseInt(radius) : 0;
  469. if (radius > h) {
  470. radiusDv = radius - h;
  471. }
  472. this.arrowNode.setStyles({
  473. "top": h + radiusDv - arrowOffsetY + "px",
  474. "bottom": "auto"
  475. })
  476. } else {
  477. radius = this.node.getStyle("border-bottom-" + arrowX + "-radius");
  478. radius = radius ? parseInt(radius) : 0;
  479. if (radius > h) {
  480. radiusDv = radius - h;
  481. }
  482. this.arrowNode.setStyles({
  483. "top": "auto",
  484. "bottom": h + radiusDv + arrowOffsetY + "px"
  485. })
  486. }
  487. var t = top;
  488. if (radiusDv) {
  489. if (arrowY == "top") {
  490. t = t - radiusDv;
  491. } else if (arrowY == "bottom") {
  492. t = t + radiusDv;
  493. }
  494. }
  495. }
  496. node.setStyles({
  497. "left" : left,
  498. "top" : t || top
  499. });
  500. },
  501. setCoondinates_y : function(){
  502. var targetCoondinates = this.target ? this.target.getCoordinates( this.container ) : this.targetCoordinates ;
  503. var node = this.node;
  504. if( this.resetHeight ){
  505. node.setStyles({
  506. overflow : "visible",
  507. height : "auto"
  508. });
  509. if(this.arrowNode)this.arrowNode.setStyle("display","");
  510. this.resetHeight = false;
  511. }
  512. var containerScroll = this.container.getScroll();
  513. var containerSize = this.container.getSize();
  514. var nodeSize = node.getSize();
  515. var top;
  516. var arrowX, arrowY;
  517. var offsetY = this.options.hasArrow ? 10 : 0;
  518. if( this.options.position.y == "top" ){
  519. top = targetCoondinates.top - nodeSize.y - offsetY;
  520. arrowY = "bottom";
  521. }else if( this.options.position.y == "bottom" ){
  522. top = targetCoondinates.bottom + offsetY;
  523. arrowY = "top";
  524. }else{
  525. var priorityOfAuto = this.options.priorityOfAuto;
  526. if( priorityOfAuto && priorityOfAuto.y ){
  527. for( var i=0; i<priorityOfAuto.y.length; i++ ){
  528. if( priorityOfAuto.y[i] == "top" ){
  529. if( targetCoondinates.top - containerScroll.y > containerSize.y - targetCoondinates.bottom ){
  530. top = targetCoondinates.top - nodeSize.y - offsetY;
  531. arrowY = "bottom";
  532. break;
  533. }
  534. }
  535. if( priorityOfAuto.y[i] == "bottom" ){
  536. if( containerSize.y + containerScroll.y - targetCoondinates.bottom > nodeSize.y ){
  537. top = targetCoondinates.bottom + offsetY;
  538. arrowY = "top";
  539. break;
  540. }
  541. }
  542. }
  543. }
  544. if( !top ){
  545. if( targetCoondinates.top - containerScroll.y > containerSize.y - targetCoondinates.bottom){
  546. top = targetCoondinates.top - nodeSize.y - offsetY;
  547. arrowY = "bottom";
  548. }else{
  549. top = targetCoondinates.bottom + offsetY;
  550. arrowY = "top";
  551. }
  552. }
  553. }
  554. var left;
  555. if( this.options.position.x == "center" ){
  556. left = targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) ;
  557. arrowX = "center";
  558. }else if( this.options.position.x == "left" ){
  559. left = targetCoondinates.right - nodeSize.x;
  560. arrowX = "right";
  561. }else if( this.options.position.x == "right" ){
  562. left = targetCoondinates.left;
  563. arrowX = "left";
  564. }else{
  565. var priorityOfAuto = this.options.priorityOfAuto;
  566. if( priorityOfAuto && priorityOfAuto.x ){
  567. for( var i=0; i<priorityOfAuto.x.length; i++ ){
  568. if( priorityOfAuto.x[i] == "center" ){
  569. if( targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) > containerScroll.x &&
  570. targetCoondinates.right - (targetCoondinates.width/2) + ( nodeSize.x / 2 ) - containerScroll.x < containerSize.x ){
  571. left = targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) ;
  572. arrowX = "center";
  573. break;
  574. }
  575. }
  576. if( priorityOfAuto.x[i] == "left" ){
  577. if( targetCoondinates.left - containerScroll.x > containerSize.x - targetCoondinates.right){
  578. left = targetCoondinates.right - nodeSize.x;
  579. arrowX = "right";
  580. break;
  581. }
  582. }
  583. if( priorityOfAuto.x[i] == "right" ){
  584. if( containerSize.x + containerScroll.x - targetCoondinates.right > nodeSize.x ){
  585. left = targetCoondinates.left;
  586. arrowX = "left";
  587. break;
  588. }
  589. }
  590. }
  591. }
  592. if( !left ){
  593. if( targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) > containerScroll.x &&
  594. targetCoondinates.right - (targetCoondinates.width/2) + ( nodeSize.x / 2 ) - containerScroll.x < containerSize.x ){
  595. left = targetCoondinates.left + (targetCoondinates.width/2) - ( nodeSize.x / 2 ) ;
  596. arrowX = "center";
  597. } else if( targetCoondinates.left - containerScroll.x > containerSize.x - targetCoondinates.right ){
  598. left = targetCoondinates.right - nodeSize.x;
  599. arrowX = "right";
  600. }else{
  601. left = targetCoondinates.left;
  602. arrowX = "left";
  603. }
  604. }
  605. }
  606. var arrowOffsetX = 0;
  607. if( this.options.isFitToContainer ){
  608. if( left < containerScroll.x ){
  609. arrowOffsetX = containerScroll.x - left;
  610. left = containerScroll.x;
  611. }else if( left + nodeSize.x > containerSize.x + containerScroll.x ){
  612. arrowOffsetX = containerSize.x + containerScroll.x - left - nodeSize.x;
  613. left = containerSize.x + containerScroll.x - nodeSize.x;
  614. }
  615. }
  616. if( this.options.overflow == "scroll" ){
  617. if( top < 0 ){
  618. node.setStyles({
  619. "overflow" : "auto",
  620. "height" : nodeSize.y + top - offsetY
  621. });
  622. this.resetHeight = true;
  623. top = 0
  624. }else if( top + nodeSize.y > containerSize.y + containerScroll.y ){
  625. node.setStyles({
  626. "overflow" : "auto",
  627. "height" : Math.abs( containerSize.y + containerScroll.y - top + offsetY )
  628. });
  629. top = top - offsetY;
  630. this.resetHeight = true;
  631. }
  632. }
  633. if( this.resetHeight ){
  634. if( this.arrowNode )this.arrowNode.setStyle("display","none");
  635. }else if( this.options.hasArrow && this.arrowNode ){
  636. if( arrowY == "top" ){
  637. this.arrowNode.setStyles( {
  638. "top" : "-8px",
  639. "bottom" : "auto",
  640. "background-position": "0px -18px"
  641. });
  642. }else{
  643. this.arrowNode.setStyles( {
  644. "top" : "auto",
  645. "bottom" : "-8px",
  646. "background-position": "0px -28px"
  647. });
  648. }
  649. var aw = this.arrowNode.getSize().x / 2 ;
  650. //var tw = targetCoondinates.width / 2 - aw;
  651. var w = Math.min( targetCoondinates.width , nodeSize.x )/ 2 - aw;
  652. var radiusDv = 0; //圆角和箭头偏移量的差值
  653. var radius = 0; //圆角值
  654. if( arrowX == "center" ) {
  655. this.arrowNode.setStyles({
  656. "left": (nodeSize.x/2 - aw - arrowOffsetX )+"px",
  657. "right": "auto"
  658. })
  659. }else if( arrowX == "left" ){
  660. radius = this.node.getStyle("border-"+arrowY+"-left-radius");
  661. radius = radius ? parseInt( radius ) : 0;
  662. if( radius > w ){
  663. radiusDv = radius - w;
  664. }
  665. this.arrowNode.setStyles({
  666. "left" : w + radiusDv - arrowOffsetX + "px",
  667. "right" : "auto"
  668. })
  669. }else{
  670. radius = this.node.getStyle("border-" + arrowY + "-right-radius");
  671. radius = radius ? parseInt(radius) : 0;
  672. if( radius > w ){
  673. radiusDv = radius - w;
  674. }
  675. this.arrowNode.setStyles({
  676. "left" : "auto",
  677. "right" : w + radiusDv + arrowOffsetX +"px"
  678. })
  679. }
  680. var l = left;
  681. if( radiusDv ){
  682. if( arrowX == "left" ){
  683. l = l - radiusDv;
  684. }else if( arrowX == "right" ){
  685. l = l + radiusDv;
  686. }
  687. }
  688. }
  689. node.setStyles({
  690. "left" : l || left,
  691. "top" : top
  692. });
  693. },
  694. destroy: function(){
  695. //if( this.options.event == "click" && this.node ){
  696. // this.container.removeEvent("mousedown",this.hideFun );
  697. //}
  698. if( this.options.event == "click" && this.app && this.hideFun_resize ){
  699. this.app.removeEvent("resize",this.hideFun_resize );
  700. }
  701. if( this.targetClickFun )this.target.removeEvent( "click", this.targetClickFun );
  702. if( this.targetMouseenterFun )this.target.removeEvent( "mouseenter", this.targetMouseenterFun );
  703. if( this.targetMouseenterFun2 )this.target.removeEvent( "mouseenter", this.targetMouseenterFun2 );
  704. if( this.targetMouseleaveFun )this.target.removeEvent( "mouseleave", this.targetMouseleaveFun );
  705. if( this.targetMouseleaveFun2 )this.target.removeEvent( "mouseleave", this.targetMouseleaveFun2 );
  706. if( this.node ){
  707. this.node.destroy();
  708. this.node = null;
  709. }
  710. this.fireEvent("destroy",[this]);
  711. MWF.release(this);
  712. },
  713. _getHtml : function(){
  714. //var data = this.data;
  715. //var titleStyle = "font-size:14px;color:#333";
  716. //var valueStyle = "font-size:14px;color:#666;padding-right:20px";
  717. //var persons = [];
  718. //data.invitePersonList.each( function( p ){
  719. // persons.push(p.split("@")[0] )
  720. //}.bind(this));
  721. //
  722. //var html =
  723. // "<div style='overflow: hidden;padding:15px 20px 20px 10px;height:16px;line-height:16px;'>" +
  724. // " <div style='font-size: 12px;color:#666; float: right'>"+ this.lp.applyPerson +":" + data.applicant.split("@")[0] +"</div>" +
  725. // " <div style='font-size: 16px;color:#333;float: left'>"+ this.lp.meetingDetail +"</div>"+
  726. // "</div>"+
  727. // "<div style='font-size: 18px;color:#333;padding:0px 10px 15px 20px;'>"+ data.subject +"</div>"+
  728. // "<div style='height:1px;margin:0px 20px;border-bottom:1px solid #ccc;'></div>"+
  729. // "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' style='margin:13px 13px 13px 13px;'>" +
  730. // "<tr><td style='"+titleStyle+"' width='70'>"+this.lp.beginTime+":</td>" +
  731. // " <td style='"+valueStyle+"'>" + data.startTime + "</td></tr>" +
  732. // "<tr><td style='"+titleStyle+"'>"+this.lp.endTime+":</td>" +
  733. // " <td style='"+valueStyle+"'>" + data.completedTime + "</td></tr>" +
  734. // "<tr><td style='"+titleStyle+"'>"+this.lp.selectRoom +":</td>" +
  735. // " <td style='"+valueStyle+"' item='meetingRoom'></td></tr>" +
  736. // "<tr><td style='"+titleStyle+"'>"+this.lp.invitePerson2+":</td>" +
  737. // " <td style='"+valueStyle+"' item='invitePerson'>"+persons.join(",")+"</td></tr>" +
  738. // "<tr><td style='"+titleStyle+"'>"+this.lp.meetingDescription+":</td>" +
  739. // " <td style='"+valueStyle+"'>"+ data.description +"</td></tr>" +
  740. // "<tr><td style='"+titleStyle+"'>"+this.lp.meetingAttachment+":</td>" +
  741. // " <td style='"+valueStyle+"' item='attachment'></td></tr>"+
  742. // "</table>";
  743. return "";
  744. },
  745. _customNode : function( node, contentNode ){
  746. },
  747. _setContent : function( contentNode ){
  748. this.contentNode = contentNode;
  749. if( this.node ){
  750. this.node.empty();
  751. this.contentNode.inject( this.node );
  752. }
  753. },
  754. _loadCustom : function( callback ){
  755. if(callback)callback();
  756. }
  757. });