|
33 | 33 | '<div class="webui-popover-inner">'+ |
34 | 34 | '<a href="#" class="close">x</a>'+ |
35 | 35 | '<h3 class="webui-popover-title"></h3>'+ |
36 | | - '<div class="webui-popover-content"><i class="glyphicon glyphicon-refresh"></i> <p></p></div>'+ |
| 36 | + '<div class="webui-popover-content"><i class="icon-refresh"></i> <p> </p></div>'+ |
37 | 37 | '</div>'+ |
38 | 38 | '</div>' |
39 | 39 | }; |
|
60 | 60 | .on('mouseenter',$.proxy(this.mouseenterHandler,this)) |
61 | 61 | .on('mouseleave',$.proxy(this.mouseleaveHandler,this)); |
62 | 62 | } |
| 63 | + $('body').off('keyup.webui-popover').on('keyup.webui-popover',$.proxy(this.escapeHandler,this)); |
63 | 64 | this._poped = false; |
64 | 65 | this._inited = true; |
65 | 66 | }, |
|
89 | 90 | }, |
90 | 91 | /*core method ,show popover */ |
91 | 92 | show:function(){ |
| 93 | + var |
| 94 | + $target = this.getTarget().removeClass().addClass(pluginClass); |
| 95 | + if (!this.options.multi){ |
| 96 | + this.hideAll(); |
| 97 | + } |
| 98 | + // use cache by default, if not cache setted , reInit the contents |
| 99 | + if (!this.options.cache||!this._poped){ |
| 100 | + this.setTitle(this.getTitle()); |
| 101 | + if (!this.options.closeable){ |
| 102 | + $target.find('.close').off('click').remove(); |
| 103 | + } |
| 104 | + if (!this.isAsync()){ |
| 105 | + this.setContent(this.getContent()); |
| 106 | + }else{ |
| 107 | + this.setContentASync(this.options.content); |
| 108 | + this.displayContent(); |
| 109 | + return; |
| 110 | + } |
| 111 | + $target.show(); |
| 112 | + } |
| 113 | + this.displayContent(); |
| 114 | + }, |
| 115 | + displayContent:function(){ |
92 | 116 | var |
93 | 117 | //element postion |
94 | 118 | elementPos = this.getElementPosition(), |
|
103 | 127 | //placement |
104 | 128 | placement = 'bottom', |
105 | 129 | e = $.Event('show.' + pluginType); |
106 | | - |
107 | | - if (!this.options.multi){ |
108 | | - this.hideAll(); |
109 | | - } |
110 | 130 | //if (this.hasContent()){ |
111 | | - this.$element.trigger(e); |
| 131 | + this.$element.trigger(e); |
112 | 132 | //} |
113 | | - // use cache by default, if not cache setted , reInit the contents |
114 | | - if (!this.options.cache||!this._poped){ |
115 | | - if (!this.isAsync()){ |
116 | | - this.setContent(this.getContent()); |
117 | | - }else{ |
118 | | - this.setContentASync(this.options.content); |
119 | | - } |
120 | | - this.setTitle(this.getTitle()); |
121 | | - if (!this.options.closeable){ |
122 | | - $target.find('.close').off('click').remove(); |
123 | | - } |
124 | | - $target.show(); |
125 | | - } |
126 | 133 | if (this.options.width!=='auto') {$target.width(this.options.width);} |
127 | 134 | if (this.options.height!=='auto'){$targetContent.height(this.options.height);} |
128 | 135 |
|
|
146 | 153 | if (this.options.style){ |
147 | 154 | this.$target.addClass(pluginClass+'-'+this.options.style); |
148 | 155 | } |
| 156 | + |
149 | 157 | if (!this.options.padding){ |
150 | | - //fixed position offset bug |
151 | 158 | $targetContent.css('height',$targetContent.outerHeight()); |
152 | 159 | this.$target.addClass('webui-no-padding'); |
153 | 160 | } |
|
163 | 170 | } |
164 | 171 | this._poped = true; |
165 | 172 | this.$element.trigger('shown.'+pluginType); |
| 173 | + |
166 | 174 | }, |
| 175 | + |
| 176 | + isTargetLoaded:function(){ |
| 177 | + return this.getTarget().find('i.glyphicon-refresh').length===0; |
| 178 | + }, |
| 179 | + |
167 | 180 | /*getter setters */ |
168 | 181 | getTarget:function(){ |
169 | 182 | if (!this.$target){ |
|
228 | 241 | that.content = data; |
229 | 242 | } |
230 | 243 | that.setContent(that.content); |
| 244 | + var $targetContent = that.getContentElement(); |
| 245 | + $targetContent.removeAttr('style'); |
| 246 | + that.displayContent(); |
231 | 247 | } |
232 | 248 | }); |
233 | 249 | }, |
|
244 | 260 | self.hide(); |
245 | 261 | },self.options.delay); |
246 | 262 | }, |
| 263 | + escapeHandler:function(e){ |
| 264 | + if (e.keyCode===27){ |
| 265 | + this.hide(); |
| 266 | + this.hideAll(); |
| 267 | + } |
| 268 | + }, |
| 269 | + |
247 | 270 | //reset and init the target events; |
248 | 271 | initTargetEvents:function(){ |
249 | 272 | if (this.options.trigger!=='click'){ |
|
274 | 297 | }else{ |
275 | 298 | placement = this.$element.data('placement')||this.options.placement; |
276 | 299 | } |
277 | | - console.log(pageY,scrollTop,clientHeight); |
278 | 300 |
|
279 | 301 | if (placement==='auto'){ |
280 | 302 | if (pageX<clientWidth/3){ |
|
320 | 342 | elementH = this.$element.outerHeight(), |
321 | 343 | position={}, |
322 | 344 | arrowOffset=null, |
323 | | - arrowSize = this.options.arrow?0:0; |
| 345 | + arrowSize = this.options.arrow?20:0, |
| 346 | + fixedW = elementW<arrowSize?arrowSize:0; |
| 347 | + fixedH = elementH<arrowSize?arrowSize:0; |
324 | 348 | switch (placement) { |
325 | 349 | case 'bottom': |
326 | 350 | position = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - targetWidth / 2}; |
327 | 351 | break; |
328 | 352 | case 'top': |
329 | | - position = {top: pos.top - targetHeight-arrowSize, left: pos.left + pos.width / 2 - targetWidth / 2}; |
| 353 | + position = {top: pos.top - targetHeight, left: pos.left + pos.width / 2 - targetWidth / 2}; |
330 | 354 | break; |
331 | 355 | case 'left': |
332 | | - position = {top: pos.top + pos.height / 2 - targetHeight / 2, left: pos.left - targetWidth -arrowSize}; |
| 356 | + position = {top: pos.top + pos.height / 2 - targetHeight / 2, left: pos.left - targetWidth}; |
333 | 357 | break; |
334 | 358 | case 'right': |
335 | 359 | position = {top: pos.top + pos.height / 2 - targetHeight / 2, left: pos.left + pos.width}; |
336 | 360 | break; |
337 | 361 | case 'top-right': |
338 | | - position = {top: pos.top - targetHeight -arrowSize, left: pos.left}; |
339 | | - arrowOffset = {left: elementW /2 }; |
| 362 | + position = {top: pos.top - targetHeight, left: pos.left-fixedW}; |
| 363 | + arrowOffset = {left: elementW/2 + fixedW}; |
340 | 364 | break; |
341 | 365 | case 'top-left': |
342 | | - position = {top: pos.top - targetHeight -arrowSize, left: pos.left -targetWidth +pos.width}; |
343 | | - arrowOffset = {left: targetWidth - elementW /2 }; |
| 366 | + position = {top: pos.top - targetHeight, left: pos.left -targetWidth +pos.width + fixedW}; |
| 367 | + arrowOffset = {left: targetWidth - elementW /2 -fixedW}; |
344 | 368 | break; |
345 | 369 | case 'bottom-right': |
346 | | - position = {top: pos.top + pos.height, left: pos.left}; |
347 | | - arrowOffset = {left: elementW /2}; |
| 370 | + position = {top: pos.top + pos.height, left: pos.left-fixedW}; |
| 371 | + arrowOffset = {left: elementW /2+fixedW}; |
348 | 372 | break; |
349 | 373 | case 'bottom-left': |
350 | 374 | position = {top: pos.top + pos.height, left: pos.left -targetWidth +pos.width}; |
351 | 375 | arrowOffset = {left: targetWidth- elementW /2}; |
352 | 376 | break; |
353 | 377 | case 'right-top': |
354 | | - position = {top: pos.top -targetHeight + pos.height, left: pos.left + pos.width}; |
355 | | - arrowOffset = {top: targetHeight - elementH/2}; |
| 378 | + position = {top: pos.top -targetHeight + pos.height + fixedH, left: pos.left + pos.width}; |
| 379 | + arrowOffset = {top: targetHeight - elementH/2 -fixedH}; |
356 | 380 | break; |
357 | 381 | case 'right-bottom': |
358 | | - position = {top: pos.top , left: pos.left + pos.width}; |
359 | | - arrowOffset = {top: elementH /2 }; |
| 382 | + position = {top: pos.top - fixedH, left: pos.left + pos.width}; |
| 383 | + arrowOffset = {top: elementH /2 +fixedH }; |
360 | 384 | break; |
361 | 385 | case 'left-top': |
362 | | - position = {top: pos.top -targetHeight + pos.height, left: pos.left - targetWidth}; |
363 | | - arrowOffset = {top: targetHeight - elementH/2}; |
| 386 | + position = {top: pos.top -targetHeight + pos.height+fixedH, left: pos.left - targetWidth}; |
| 387 | + arrowOffset = {top: targetHeight - elementH/2 - fixedH}; |
364 | 388 | break; |
365 | 389 | case 'left-bottom': |
366 | 390 | position = {top: pos.top , left: pos.left -targetWidth}; |
|
0 commit comments