MTooltips.js 37 KB

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