Changeset 43346
- Timestamp:
- 06/14/2018 03:13:19 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/lib/pointer.js
r43309 r43346 1 1 /* global wpPointerL10n */ 2 2 3 /** 3 * Pointer jQuery widget.4 * Initializes the wp-pointer widget using jQuery UI Widget Factory. 4 5 */ 5 6 (function($){ … … 7 8 zindex = 9999; 8 9 9 /**10 * @class $.widget.wp.pointer11 */12 10 $.widget('wp.pointer',/** @lends $.widget.wp.pointer.prototype */{ 13 11 options: { … … 38 36 }, 39 37 38 /** 39 * A class that represents a WordPress pointer. 40 * 41 * @since 3.3.0 42 * @private 43 * 44 * @constructs $.widget.wp.pointer 45 */ 40 46 _create: function() { 41 47 var positioning, … … 60 66 }, 61 67 68 /** 69 * Sets an option on the pointer instance. 70 * 71 * There are 4 special values that do something extra: 72 * 73 * - `document` will transfer the pointer to the body of the new document 74 * specified by the value. 75 * - `pointerClass` will change the class of the pointer element. 76 * - `position` will reposition the pointer. 77 * - `content` will update the content of the pointer. 78 * 79 * @since 3.3.0 80 * @private 81 * 82 * @param {string} key The key of the option to set. 83 * @param {*} value The value to set the option to. 84 */ 62 85 _setOption: function( key, value ) { 63 86 var o = this.options, … … 86 109 }, 87 110 111 /** 112 * Removes the pointer element from of the DOM. 113 * 114 * Makes sure that the widget and all associated bindings are destroyed. 115 * 116 * @since 3.3.0 117 */ 88 118 destroy: function() { 89 119 this.pointer.remove(); … … 91 121 }, 92 122 123 /** 124 * Returns the pointer element. 125 * 126 * @since 3.3.0 127 * 128 * @return {Object} Pointer The pointer object. 129 */ 93 130 widget: function() { 94 131 return this.pointer; 95 132 }, 96 133 134 /** 135 * Updates the content of the pointer. 136 * 137 * This function doesn't update the content of the pointer itself. That is done 138 * by the `_update` method. This method will make sure that the `_update` method 139 * is called with the right content. 140 * 141 * The content in the options can either be a string or a callback. If it is a 142 * callback the result of this callback is used as the content. 143 * 144 * @since 3.3.0 145 * 146 * @param {Object} event The event that caused the update. 147 * 148 * @return {Promise} Resolves when the update has been executed. 149 */ 97 150 update: function( event ) { 98 151 var self = this, … … 125 178 126 179 /** 127 * Update is separated into two functions to allow events to defer 128 * updating the pointer (e.g. fetch content with ajax, etc). 180 * Updates the content of the pointer. 181 * 182 * Will make sure that the pointer is correctly positioned. 183 * 184 * @since 3.3.0 185 * @private 186 * 187 * @param {Object} event The event that caused the update. 188 * @param {*} content The content object. Either a string or a jQuery tree. 129 189 */ 130 190 _update: function( event, content ) { … … 135 195 return; 136 196 137 this.pointer.stop(); // Kill any animations on the pointer. 197 // Kill any animations on the pointer. 198 this.pointer.stop(); 138 199 this.content.html( content ); 139 200 … … 146 207 }, 147 208 209 /** 210 * Repositions the pointer. 211 * 212 * Makes sure the pointer is the correct size for its content and makes sure it 213 * is positioned to point to the right element. 214 * 215 * @since 3.3.0 216 */ 148 217 reposition: function() { 149 218 var position; … … 167 236 }, 168 237 238 /** 239 * Sets the arrow of the pointer to the correct side of the pointer element. 240 * 241 * @since 3.3.0 242 */ 169 243 repoint: function() { 170 244 var o = this.options, … … 183 257 }, 184 258 259 /** 260 * Calculates the correct position based on a position in the settings. 261 * 262 * @since 3.3.0 263 * @private 264 * 265 * @param {string|Object} position Either a side of a pointer or an object 266 * containing a pointer. 267 * 268 * @return {Object} result An object containing position related data. 269 */ 185 270 _processPosition: function( position ) { 186 271 var opposite = { … … 219 304 }, 220 305 306 /** 307 * Opens the pointer. 308 * 309 * Only opens the pointer widget in case it is closed and not disabled, and 310 * calls 'update' before doing so. Calling update makes sure that the pointer 311 * is correctly sized and positioned. 312 * 313 * @since 3.3.0 314 * 315 * @param {Object} event The event that triggered the opening of this pointer. 316 */ 221 317 open: function( event ) { 222 318 var self = this, … … 231 327 }, 232 328 329 /** 330 * Opens and shows the pointer element. 331 * 332 * @since 3.3.0 333 * @private 334 * 335 * @param {Object} event An event object. 336 */ 233 337 _open: function( event ) { 234 338 var self = this, … … 249 353 }, 250 354 355 /** 356 * Closes and hides the pointer element. 357 * 358 * @since 3.3.0 359 * 360 * @param {Object} event An event object. 361 */ 251 362 close: function( event ) { 252 363 if ( !this.active || this.options.disabled ) … … 264 375 }, 265 376 377 /** 378 * Puts the pointer on top by increasing the z-index. 379 * 380 * @since 3.3.0 381 */ 266 382 sendToTop: function() { 267 383 if ( this.active ) … … 269 385 }, 270 386 387 /** 388 * Toggles the element between shown and hidden. 389 * 390 * @since 3.3.0 391 * 392 * @param {Object} event An event object. 393 */ 271 394 toggle: function( event ) { 272 395 if ( this.pointer.is(':hidden') ) … … 276 399 }, 277 400 401 /** 402 * Extends the pointer and the widget element with the supplied parameter, which 403 * is either an element or a function. 404 * 405 * @since 3.3.0 406 * @private 407 * 408 * @param {Object} extend The object to be merged into the original object. 409 * 410 * @return {Object} The extended object. 411 */ 278 412 _handoff: function( extend ) { 279 413 return $.extend({
Note: See TracChangeset
for help on using the changeset viewer.