Edit File by line
/home/barbar84/public_h.../wp-inclu.../js
File: wp-pointer.js
/**
[0] Fix | Delete
* @output wp-includes/js/wp-pointer.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* Initializes the wp-pointer widget using jQuery UI Widget Factory.
[5] Fix | Delete
*/
[6] Fix | Delete
(function($){
[7] Fix | Delete
var identifier = 0,
[8] Fix | Delete
zindex = 9999;
[9] Fix | Delete
[10] Fix | Delete
$.widget('wp.pointer',/** @lends $.widget.wp.pointer.prototype */{
[11] Fix | Delete
options: {
[12] Fix | Delete
pointerClass: 'wp-pointer',
[13] Fix | Delete
pointerWidth: 320,
[14] Fix | Delete
content: function() {
[15] Fix | Delete
return $(this).text();
[16] Fix | Delete
},
[17] Fix | Delete
buttons: function( event, t ) {
[18] Fix | Delete
var button = $('<a class="close" href="#"></a>').text( wp.i18n.__( 'Dismiss' ) );
[19] Fix | Delete
[20] Fix | Delete
return button.on( 'click.pointer', function(e) {
[21] Fix | Delete
e.preventDefault();
[22] Fix | Delete
t.element.pointer('close');
[23] Fix | Delete
});
[24] Fix | Delete
},
[25] Fix | Delete
position: 'top',
[26] Fix | Delete
show: function( event, t ) {
[27] Fix | Delete
t.pointer.show();
[28] Fix | Delete
t.opened();
[29] Fix | Delete
},
[30] Fix | Delete
hide: function( event, t ) {
[31] Fix | Delete
t.pointer.hide();
[32] Fix | Delete
t.closed();
[33] Fix | Delete
},
[34] Fix | Delete
document: document
[35] Fix | Delete
},
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* A class that represents a WordPress pointer.
[39] Fix | Delete
*
[40] Fix | Delete
* @since 3.3.0
[41] Fix | Delete
* @private
[42] Fix | Delete
*
[43] Fix | Delete
* @constructs $.widget.wp.pointer
[44] Fix | Delete
*/
[45] Fix | Delete
_create: function() {
[46] Fix | Delete
var positioning,
[47] Fix | Delete
family;
[48] Fix | Delete
[49] Fix | Delete
this.content = $('<div class="wp-pointer-content"></div>');
[50] Fix | Delete
this.arrow = $('<div class="wp-pointer-arrow"><div class="wp-pointer-arrow-inner"></div></div>');
[51] Fix | Delete
[52] Fix | Delete
family = this.element.parents().add( this.element );
[53] Fix | Delete
positioning = 'absolute';
[54] Fix | Delete
[55] Fix | Delete
if ( family.filter(function(){ return 'fixed' === $(this).css('position'); }).length )
[56] Fix | Delete
positioning = 'fixed';
[57] Fix | Delete
[58] Fix | Delete
this.pointer = $('<div />')
[59] Fix | Delete
.append( this.content )
[60] Fix | Delete
.append( this.arrow )
[61] Fix | Delete
.attr('id', 'wp-pointer-' + identifier++)
[62] Fix | Delete
.addClass( this.options.pointerClass )
[63] Fix | Delete
.css({'position': positioning, 'width': this.options.pointerWidth+'px', 'display': 'none'})
[64] Fix | Delete
.appendTo( this.options.document.body );
[65] Fix | Delete
},
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Sets an option on the pointer instance.
[69] Fix | Delete
*
[70] Fix | Delete
* There are 4 special values that do something extra:
[71] Fix | Delete
*
[72] Fix | Delete
* - `document` will transfer the pointer to the body of the new document
[73] Fix | Delete
* specified by the value.
[74] Fix | Delete
* - `pointerClass` will change the class of the pointer element.
[75] Fix | Delete
* - `position` will reposition the pointer.
[76] Fix | Delete
* - `content` will update the content of the pointer.
[77] Fix | Delete
*
[78] Fix | Delete
* @since 3.3.0
[79] Fix | Delete
* @private
[80] Fix | Delete
*
[81] Fix | Delete
* @param {string} key The key of the option to set.
[82] Fix | Delete
* @param {*} value The value to set the option to.
[83] Fix | Delete
*/
[84] Fix | Delete
_setOption: function( key, value ) {
[85] Fix | Delete
var o = this.options,
[86] Fix | Delete
tip = this.pointer;
[87] Fix | Delete
[88] Fix | Delete
// Handle document transfer.
[89] Fix | Delete
if ( key === 'document' && value !== o.document ) {
[90] Fix | Delete
tip.detach().appendTo( value.body );
[91] Fix | Delete
[92] Fix | Delete
// Handle class change.
[93] Fix | Delete
} else if ( key === 'pointerClass' ) {
[94] Fix | Delete
tip.removeClass( o.pointerClass ).addClass( value );
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
// Call super method.
[98] Fix | Delete
$.Widget.prototype._setOption.apply( this, arguments );
[99] Fix | Delete
[100] Fix | Delete
// Reposition automatically.
[101] Fix | Delete
if ( key === 'position' ) {
[102] Fix | Delete
this.reposition();
[103] Fix | Delete
[104] Fix | Delete
// Update content automatically if pointer is open.
[105] Fix | Delete
} else if ( key === 'content' && this.active ) {
[106] Fix | Delete
this.update();
[107] Fix | Delete
}
[108] Fix | Delete
},
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* Removes the pointer element from of the DOM.
[112] Fix | Delete
*
[113] Fix | Delete
* Makes sure that the widget and all associated bindings are destroyed.
[114] Fix | Delete
*
[115] Fix | Delete
* @since 3.3.0
[116] Fix | Delete
*/
[117] Fix | Delete
destroy: function() {
[118] Fix | Delete
this.pointer.remove();
[119] Fix | Delete
$.Widget.prototype.destroy.call( this );
[120] Fix | Delete
},
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Returns the pointer element.
[124] Fix | Delete
*
[125] Fix | Delete
* @since 3.3.0
[126] Fix | Delete
*
[127] Fix | Delete
* @return {Object} Pointer The pointer object.
[128] Fix | Delete
*/
[129] Fix | Delete
widget: function() {
[130] Fix | Delete
return this.pointer;
[131] Fix | Delete
},
[132] Fix | Delete
[133] Fix | Delete
/**
[134] Fix | Delete
* Updates the content of the pointer.
[135] Fix | Delete
*
[136] Fix | Delete
* This function doesn't update the content of the pointer itself. That is done
[137] Fix | Delete
* by the `_update` method. This method will make sure that the `_update` method
[138] Fix | Delete
* is called with the right content.
[139] Fix | Delete
*
[140] Fix | Delete
* The content in the options can either be a string or a callback. If it is a
[141] Fix | Delete
* callback the result of this callback is used as the content.
[142] Fix | Delete
*
[143] Fix | Delete
* @since 3.3.0
[144] Fix | Delete
*
[145] Fix | Delete
* @param {Object} event The event that caused the update.
[146] Fix | Delete
*
[147] Fix | Delete
* @return {Promise} Resolves when the update has been executed.
[148] Fix | Delete
*/
[149] Fix | Delete
update: function( event ) {
[150] Fix | Delete
var self = this,
[151] Fix | Delete
o = this.options,
[152] Fix | Delete
dfd = $.Deferred(),
[153] Fix | Delete
content;
[154] Fix | Delete
[155] Fix | Delete
if ( o.disabled )
[156] Fix | Delete
return;
[157] Fix | Delete
[158] Fix | Delete
dfd.done( function( content ) {
[159] Fix | Delete
self._update( event, content );
[160] Fix | Delete
});
[161] Fix | Delete
[162] Fix | Delete
// Either o.content is a string...
[163] Fix | Delete
if ( typeof o.content === 'string' ) {
[164] Fix | Delete
content = o.content;
[165] Fix | Delete
[166] Fix | Delete
// ...or o.content is a callback.
[167] Fix | Delete
} else {
[168] Fix | Delete
content = o.content.call( this.element[0], dfd.resolve, event, this._handoff() );
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
// If content is set, then complete the update.
[172] Fix | Delete
if ( content )
[173] Fix | Delete
dfd.resolve( content );
[174] Fix | Delete
[175] Fix | Delete
return dfd.promise();
[176] Fix | Delete
},
[177] Fix | Delete
[178] Fix | Delete
/**
[179] Fix | Delete
* Updates the content of the pointer.
[180] Fix | Delete
*
[181] Fix | Delete
* Will make sure that the pointer is correctly positioned.
[182] Fix | Delete
*
[183] Fix | Delete
* @since 3.3.0
[184] Fix | Delete
* @private
[185] Fix | Delete
*
[186] Fix | Delete
* @param {Object} event The event that caused the update.
[187] Fix | Delete
* @param {*} content The content object. Either a string or a jQuery tree.
[188] Fix | Delete
*/
[189] Fix | Delete
_update: function( event, content ) {
[190] Fix | Delete
var buttons,
[191] Fix | Delete
o = this.options;
[192] Fix | Delete
[193] Fix | Delete
if ( ! content )
[194] Fix | Delete
return;
[195] Fix | Delete
[196] Fix | Delete
// Kill any animations on the pointer.
[197] Fix | Delete
this.pointer.stop();
[198] Fix | Delete
this.content.html( content );
[199] Fix | Delete
[200] Fix | Delete
buttons = o.buttons.call( this.element[0], event, this._handoff() );
[201] Fix | Delete
if ( buttons ) {
[202] Fix | Delete
buttons.wrap('<div class="wp-pointer-buttons" />').parent().appendTo( this.content );
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
this.reposition();
[206] Fix | Delete
},
[207] Fix | Delete
[208] Fix | Delete
/**
[209] Fix | Delete
* Repositions the pointer.
[210] Fix | Delete
*
[211] Fix | Delete
* Makes sure the pointer is the correct size for its content and makes sure it
[212] Fix | Delete
* is positioned to point to the right element.
[213] Fix | Delete
*
[214] Fix | Delete
* @since 3.3.0
[215] Fix | Delete
*/
[216] Fix | Delete
reposition: function() {
[217] Fix | Delete
var position;
[218] Fix | Delete
[219] Fix | Delete
if ( this.options.disabled )
[220] Fix | Delete
return;
[221] Fix | Delete
[222] Fix | Delete
position = this._processPosition( this.options.position );
[223] Fix | Delete
[224] Fix | Delete
// Reposition pointer.
[225] Fix | Delete
this.pointer.css({
[226] Fix | Delete
top: 0,
[227] Fix | Delete
left: 0,
[228] Fix | Delete
zIndex: zindex++ // Increment the z-index so that it shows above other opened pointers.
[229] Fix | Delete
}).show().position($.extend({
[230] Fix | Delete
of: this.element,
[231] Fix | Delete
collision: 'fit none'
[232] Fix | Delete
}, position )); // The object comes before this.options.position so the user can override position.of.
[233] Fix | Delete
[234] Fix | Delete
this.repoint();
[235] Fix | Delete
},
[236] Fix | Delete
[237] Fix | Delete
/**
[238] Fix | Delete
* Sets the arrow of the pointer to the correct side of the pointer element.
[239] Fix | Delete
*
[240] Fix | Delete
* @since 3.3.0
[241] Fix | Delete
*/
[242] Fix | Delete
repoint: function() {
[243] Fix | Delete
var o = this.options,
[244] Fix | Delete
edge;
[245] Fix | Delete
[246] Fix | Delete
if ( o.disabled )
[247] Fix | Delete
return;
[248] Fix | Delete
[249] Fix | Delete
edge = ( typeof o.position == 'string' ) ? o.position : o.position.edge;
[250] Fix | Delete
[251] Fix | Delete
// Remove arrow classes.
[252] Fix | Delete
this.pointer[0].className = this.pointer[0].className.replace( /wp-pointer-[^\s'"]*/, '' );
[253] Fix | Delete
[254] Fix | Delete
// Add arrow class.
[255] Fix | Delete
this.pointer.addClass( 'wp-pointer-' + edge );
[256] Fix | Delete
},
[257] Fix | Delete
[258] Fix | Delete
/**
[259] Fix | Delete
* Calculates the correct position based on a position in the settings.
[260] Fix | Delete
*
[261] Fix | Delete
* @since 3.3.0
[262] Fix | Delete
* @private
[263] Fix | Delete
*
[264] Fix | Delete
* @param {string|Object} position Either a side of a pointer or an object
[265] Fix | Delete
* containing a pointer.
[266] Fix | Delete
*
[267] Fix | Delete
* @return {Object} result An object containing position related data.
[268] Fix | Delete
*/
[269] Fix | Delete
_processPosition: function( position ) {
[270] Fix | Delete
var opposite = {
[271] Fix | Delete
top: 'bottom',
[272] Fix | Delete
bottom: 'top',
[273] Fix | Delete
left: 'right',
[274] Fix | Delete
right: 'left'
[275] Fix | Delete
},
[276] Fix | Delete
result;
[277] Fix | Delete
[278] Fix | Delete
// If the position object is a string, it is shorthand for position.edge.
[279] Fix | Delete
if ( typeof position == 'string' ) {
[280] Fix | Delete
result = {
[281] Fix | Delete
edge: position + ''
[282] Fix | Delete
};
[283] Fix | Delete
} else {
[284] Fix | Delete
result = $.extend( {}, position );
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
if ( ! result.edge )
[288] Fix | Delete
return result;
[289] Fix | Delete
[290] Fix | Delete
if ( result.edge == 'top' || result.edge == 'bottom' ) {
[291] Fix | Delete
result.align = result.align || 'left';
[292] Fix | Delete
[293] Fix | Delete
result.at = result.at || result.align + ' ' + opposite[ result.edge ];
[294] Fix | Delete
result.my = result.my || result.align + ' ' + result.edge;
[295] Fix | Delete
} else {
[296] Fix | Delete
result.align = result.align || 'top';
[297] Fix | Delete
[298] Fix | Delete
result.at = result.at || opposite[ result.edge ] + ' ' + result.align;
[299] Fix | Delete
result.my = result.my || result.edge + ' ' + result.align;
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
return result;
[303] Fix | Delete
},
[304] Fix | Delete
[305] Fix | Delete
/**
[306] Fix | Delete
* Opens the pointer.
[307] Fix | Delete
*
[308] Fix | Delete
* Only opens the pointer widget in case it is closed and not disabled, and
[309] Fix | Delete
* calls 'update' before doing so. Calling update makes sure that the pointer
[310] Fix | Delete
* is correctly sized and positioned.
[311] Fix | Delete
*
[312] Fix | Delete
* @since 3.3.0
[313] Fix | Delete
*
[314] Fix | Delete
* @param {Object} event The event that triggered the opening of this pointer.
[315] Fix | Delete
*/
[316] Fix | Delete
open: function( event ) {
[317] Fix | Delete
var self = this,
[318] Fix | Delete
o = this.options;
[319] Fix | Delete
[320] Fix | Delete
if ( this.active || o.disabled || this.element.is(':hidden') )
[321] Fix | Delete
return;
[322] Fix | Delete
[323] Fix | Delete
this.update().done( function() {
[324] Fix | Delete
self._open( event );
[325] Fix | Delete
});
[326] Fix | Delete
},
[327] Fix | Delete
[328] Fix | Delete
/**
[329] Fix | Delete
* Opens and shows the pointer element.
[330] Fix | Delete
*
[331] Fix | Delete
* @since 3.3.0
[332] Fix | Delete
* @private
[333] Fix | Delete
*
[334] Fix | Delete
* @param {Object} event An event object.
[335] Fix | Delete
*/
[336] Fix | Delete
_open: function( event ) {
[337] Fix | Delete
var self = this,
[338] Fix | Delete
o = this.options;
[339] Fix | Delete
[340] Fix | Delete
if ( this.active || o.disabled || this.element.is(':hidden') )
[341] Fix | Delete
return;
[342] Fix | Delete
[343] Fix | Delete
this.active = true;
[344] Fix | Delete
[345] Fix | Delete
this._trigger( 'open', event, this._handoff() );
[346] Fix | Delete
[347] Fix | Delete
this._trigger( 'show', event, this._handoff({
[348] Fix | Delete
opened: function() {
[349] Fix | Delete
self._trigger( 'opened', event, self._handoff() );
[350] Fix | Delete
}
[351] Fix | Delete
}));
[352] Fix | Delete
},
[353] Fix | Delete
[354] Fix | Delete
/**
[355] Fix | Delete
* Closes and hides the pointer element.
[356] Fix | Delete
*
[357] Fix | Delete
* @since 3.3.0
[358] Fix | Delete
*
[359] Fix | Delete
* @param {Object} event An event object.
[360] Fix | Delete
*/
[361] Fix | Delete
close: function( event ) {
[362] Fix | Delete
if ( !this.active || this.options.disabled )
[363] Fix | Delete
return;
[364] Fix | Delete
[365] Fix | Delete
var self = this;
[366] Fix | Delete
this.active = false;
[367] Fix | Delete
[368] Fix | Delete
this._trigger( 'close', event, this._handoff() );
[369] Fix | Delete
this._trigger( 'hide', event, this._handoff({
[370] Fix | Delete
closed: function() {
[371] Fix | Delete
self._trigger( 'closed', event, self._handoff() );
[372] Fix | Delete
}
[373] Fix | Delete
}));
[374] Fix | Delete
},
[375] Fix | Delete
[376] Fix | Delete
/**
[377] Fix | Delete
* Puts the pointer on top by increasing the z-index.
[378] Fix | Delete
*
[379] Fix | Delete
* @since 3.3.0
[380] Fix | Delete
*/
[381] Fix | Delete
sendToTop: function() {
[382] Fix | Delete
if ( this.active )
[383] Fix | Delete
this.pointer.css( 'z-index', zindex++ );
[384] Fix | Delete
},
[385] Fix | Delete
[386] Fix | Delete
/**
[387] Fix | Delete
* Toggles the element between shown and hidden.
[388] Fix | Delete
*
[389] Fix | Delete
* @since 3.3.0
[390] Fix | Delete
*
[391] Fix | Delete
* @param {Object} event An event object.
[392] Fix | Delete
*/
[393] Fix | Delete
toggle: function( event ) {
[394] Fix | Delete
if ( this.pointer.is(':hidden') )
[395] Fix | Delete
this.open( event );
[396] Fix | Delete
else
[397] Fix | Delete
this.close( event );
[398] Fix | Delete
},
[399] Fix | Delete
[400] Fix | Delete
/**
[401] Fix | Delete
* Extends the pointer and the widget element with the supplied parameter, which
[402] Fix | Delete
* is either an element or a function.
[403] Fix | Delete
*
[404] Fix | Delete
* @since 3.3.0
[405] Fix | Delete
* @private
[406] Fix | Delete
*
[407] Fix | Delete
* @param {Object} extend The object to be merged into the original object.
[408] Fix | Delete
*
[409] Fix | Delete
* @return {Object} The extended object.
[410] Fix | Delete
*/
[411] Fix | Delete
_handoff: function( extend ) {
[412] Fix | Delete
return $.extend({
[413] Fix | Delete
pointer: this.pointer,
[414] Fix | Delete
element: this.element
[415] Fix | Delete
}, extend);
[416] Fix | Delete
}
[417] Fix | Delete
});
[418] Fix | Delete
})(jQuery);
[419] Fix | Delete
[420] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function