equal
deleted
inserted
replaced
|
1 /* global wpPointerL10n */ |
1 /** |
2 /** |
2 * Pointer jQuery widget. |
3 * Pointer jQuery widget. |
3 */ |
4 */ |
4 (function($){ |
5 (function($){ |
5 var identifier = 0, |
6 var identifier = 0, |
6 zindex = 9999; |
7 zindex = 9999; |
7 |
8 |
8 $.widget("wp.pointer", { |
9 $.widget('wp.pointer', { |
9 options: { |
10 options: { |
10 pointerClass: 'wp-pointer', |
11 pointerClass: 'wp-pointer', |
11 pointerWidth: 320, |
12 pointerWidth: 320, |
12 content: function( respond, event, t ) { |
13 content: function() { |
13 return $(this).text(); |
14 return $(this).text(); |
14 }, |
15 }, |
15 buttons: function( event, t ) { |
16 buttons: function( event, t ) { |
16 var close = ( wpPointerL10n ) ? wpPointerL10n.dismiss : 'Dismiss', |
17 var close = ( wpPointerL10n ) ? wpPointerL10n.dismiss : 'Dismiss', |
17 button = $('<a class="close" href="#">' + close + '</a>'); |
18 button = $('<a class="close" href="#">' + close + '</a>'); |
58 _setOption: function( key, value ) { |
59 _setOption: function( key, value ) { |
59 var o = this.options, |
60 var o = this.options, |
60 tip = this.pointer; |
61 tip = this.pointer; |
61 |
62 |
62 // Handle document transfer |
63 // Handle document transfer |
63 if ( key === "document" && value !== o.document ) { |
64 if ( key === 'document' && value !== o.document ) { |
64 tip.detach().appendTo( value.body ); |
65 tip.detach().appendTo( value.body ); |
65 |
66 |
66 // Handle class change |
67 // Handle class change |
67 } else if ( key === "pointerClass" ) { |
68 } else if ( key === 'pointerClass' ) { |
68 tip.removeClass( o.pointerClass ).addClass( value ); |
69 tip.removeClass( o.pointerClass ).addClass( value ); |
69 } |
70 } |
70 |
71 |
71 // Call super method. |
72 // Call super method. |
72 $.Widget.prototype._setOption.apply( this, arguments ); |
73 $.Widget.prototype._setOption.apply( this, arguments ); |
73 |
74 |
74 // Reposition automatically |
75 // Reposition automatically |
75 if ( key === "position" ) { |
76 if ( key === 'position' ) { |
76 this.reposition(); |
77 this.reposition(); |
77 |
78 |
78 // Update content automatically if pointer is open |
79 // Update content automatically if pointer is open |
79 } else if ( key === "content" && this.active ) { |
80 } else if ( key === 'content' && this.active ) { |
80 this.update(); |
81 this.update(); |
81 } |
82 } |
82 }, |
83 }, |
83 |
84 |
84 destroy: function() { |
85 destroy: function() { |
99 if ( o.disabled ) |
100 if ( o.disabled ) |
100 return; |
101 return; |
101 |
102 |
102 dfd.done( function( content ) { |
103 dfd.done( function( content ) { |
103 self._update( event, content ); |
104 self._update( event, content ); |
104 }) |
105 }); |
105 |
106 |
106 // Either o.content is a string... |
107 // Either o.content is a string... |
107 if ( typeof o.content === 'string' ) { |
108 if ( typeof o.content === 'string' ) { |
108 content = o.content; |
109 content = o.content; |
109 |
110 |
233 if ( this.active || o.disabled || this.element.is(':hidden') ) |
234 if ( this.active || o.disabled || this.element.is(':hidden') ) |
234 return; |
235 return; |
235 |
236 |
236 this.active = true; |
237 this.active = true; |
237 |
238 |
238 this._trigger( "open", event, this._handoff() ); |
239 this._trigger( 'open', event, this._handoff() ); |
239 |
240 |
240 this._trigger( "show", event, this._handoff({ |
241 this._trigger( 'show', event, this._handoff({ |
241 opened: function() { |
242 opened: function() { |
242 self._trigger( "opened", event, self._handoff() ); |
243 self._trigger( 'opened', event, self._handoff() ); |
243 } |
244 } |
244 })); |
245 })); |
245 }, |
246 }, |
246 |
247 |
247 close: function( event ) { |
248 close: function( event ) { |
249 return; |
250 return; |
250 |
251 |
251 var self = this; |
252 var self = this; |
252 this.active = false; |
253 this.active = false; |
253 |
254 |
254 this._trigger( "close", event, this._handoff() ); |
255 this._trigger( 'close', event, this._handoff() ); |
255 this._trigger( "hide", event, this._handoff({ |
256 this._trigger( 'hide', event, this._handoff({ |
256 closed: function() { |
257 closed: function() { |
257 self._trigger( "closed", event, self._handoff() ); |
258 self._trigger( 'closed', event, self._handoff() ); |
258 } |
259 } |
259 })); |
260 })); |
260 }, |
261 }, |
261 |
262 |
262 sendToTop: function( event ) { |
263 sendToTop: function() { |
263 if ( this.active ) |
264 if ( this.active ) |
264 this.pointer.css( 'z-index', zindex++ ); |
265 this.pointer.css( 'z-index', zindex++ ); |
265 }, |
266 }, |
266 |
267 |
267 toggle: function( event ) { |
268 toggle: function( event ) { |