diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index c373e27ca4..1803253908 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -2217,3 +2217,54 @@ function get_submit_button( $text = NULL, $type = 'primary', $name = 'submit', $ return $button; } + +/** + * Initializes the new feature pointers. + * + * @since 3.3.0 + * + * Pointer user settings: + * p0 - Admin bar pointer, added 3.3. + */ +function wp_pointer_enqueue( $hook_suffix ) { + $enqueue = false; + + $admin_bar = get_user_setting( 'p0', 0 ); + if ( ! $admin_bar && apply_filters( 'show_wp_pointer_admin_bar', true ) ) { + $enqueue = true; + add_action( 'admin_print_footer_scripts', '_wp_pointer_print_admin_bar' ); + } + + if ( $enqueue ) { + wp_enqueue_style( 'wp-pointer' ); + wp_enqueue_script( 'wp-pointer' ); + wp_enqueue_script( 'utils' ); + } +} +add_action( 'admin_enqueue_scripts', 'wp_pointer_enqueue' ); + +function _wp_pointer_print_admin_bar() { + $pointer_content = '

' . __('The admin bar has been updated in WordPress 3.3.') . '

'; + $pointer_content .= '

' . sprintf( __('Have some feedback? Visit this ticket.'), 'http://core.trac.wordpress.org/ticket/18197' ) . '

'; + $pointer_content .= '

' . sprintf( __('P.S. You are looking at a new admin pointer. Chime in here.'), 'http://core.trac.wordpress.org/ticket/18693' ) . '

'; + +?> + +' + close + ''); + + return button.bind( 'click.pointer', function() { + t.element.pointer('close'); + }); + }, + arrow: 'auto', + position: { + my: "left center", + at: "right center" + }, + arrow: { + edge: 'top', + align: 'left', + offset: 20 + }, + show: function( event, t ) { + t.pointer.show(); + t.opened(); + }, + hide: function( event, t ) { + t.pointer.hide(); + t.closed(); + }, + document: document + }, + + _create: function() { + var positioning, + family; + + this.content = $('
'); + this.arrow = $('
'); + + family = this.element.parents().add( this.element ); + positioning = 'absolute'; + + if ( family.filter(function(){ return 'fixed' === $(this).css('position'); }).length ) + positioning = 'fixed'; + + + this.pointer = $('
') + .append( this.content ) + .append( this.arrow ) + .attr('id', 'wp-pointer-' + identifier++) + .addClass( this.options.pointerClass ) + .css('position', positioning) + .hide() + .appendTo( this.options.document.body ); + }, + + _setOption: function( key, value ) { + var o = this.options, + tip = this.pointer; + + // Handle document transfer + if ( key === "document" && value !== o.document ) { + tip.detach().appendTo( value.body ); + + // Handle class change + } else if ( key === "pointerClass" ) { + tip.removeClass( o.pointerClass ).addClass( value ); + } + + // Call super method. + $.Widget.prototype._setOption.apply( this, arguments ); + + // Reposition automatically + if ( key === "position" ) { + this.reposition(); + + // Update content automatically if pointer is open + } else if ( key === "content" && this.active ) { + this.update(); + } + }, + + destroy: function() { + this.pointer.remove(); + $.Widget.prototype.destroy.call( this ); + }, + + widget: function() { + return this.pointer; + }, + + update: function( event ) { + var self = this, + o = this.options, + dfd = $.Deferred(), + content; + + if ( o.disabled ) + return; + + dfd.done( function( content ) { + self._update( event, content ); + }) + + // Either o.content is a string... + if ( typeof o.content === 'string' ) { + content = o.content; + + // ...or o.content is a callback. + } else { + content = o.content.call( this.element[0], dfd.resolve, event, this._handoff() ); + } + + // If content is set, then complete the update. + if ( content ) + dfd.resolve( content ); + + return dfd.promise(); + }, + + /** + * Update is separated into two functions to allow events to defer + * updating the pointer (e.g. fetch content with ajax, etc). + */ + _update: function( event, content ) { + var buttons, + o = this.options; + + if ( ! content ) + return; + + this.pointer.stop(); // Kill any animations on the pointer. + this.content.html( content ); + + buttons = o.buttons.call( this.element[0], event, this._handoff() ); + if ( buttons ) { + buttons.wrap('
').parent().appendTo( this.content ); + } + + this.reposition(); + }, + + reposition: function() { + if ( this.options.disabled ) + return; + + // Reposition pointer. + this.pointer.css({ + top: 0, + left: 0, + zIndex: zindex++ // Increment the z-index so that it shows above other opened pointers. + }).show().position($.extend({ + of: this.element + }, this.options.position )); // the object comes before this.options.position so the user can override position.of. + + this.repoint(); + }, + + repoint: function() { + var o = this.options, + position = { + my: 'center', + of: this.pointer + }, + clear; + + if ( o.disabled ) + return; + + // Remove arrow classes. + this.pointer[0].className = this.pointer[0].className.replace( /wp-pointer-[^\s'"]*/, '' ); + + if ( o.arrow.edge == 'top' || o.arrow.edge == 'bottom' ) { + position.at = o.arrow.align + ' ' + o.arrow.edge; + position.offset = o.arrow.offset + ' 0'; + clear = 'top'; + } else { + position.at = o.arrow.edge + ' ' + o.arrow.align; + position.offset = '0 ' + o.arrow.offset; + clear = 'left'; + } + + // Reposition arrow. + this.arrow.position( position ).css( clear, '' ); + // Add arrow class. + this.pointer.addClass( 'wp-pointer-' + o.arrow.edge ); + }, + + + open: function( event ) { + var self = this, + o = this.options; + + if ( this.active || o.disabled ) + return; + + this.update().done( function() { + self._open( event ); + }); + }, + + _open: function( event ) { + var self = this, + o = this.options; + + if ( this.active || o.disabled ) + return; + + this.active = true; + + this._trigger( "open", event, this._handoff() ); + + this._trigger( "show", event, this._handoff({ + opened: function() { + self._trigger( "opened", event, self._handoff() ); + } + })); + }, + + close: function( event ) { + if ( !this.active || this.options.disabled ) + return; + + var self = this; + this.active = false; + + this._trigger( "close", event, this._handoff() ); + this._trigger( "hide", event, this._handoff({ + closed: function() { + self._trigger( "closed", event, self._handoff() ); + } + })); + }, + + sendToTop: function( event ) { + if ( this.active ) + this.pointer.css( 'z-index', zindex++ ); + }, + + toggle: function( event ) { + if ( this.pointer.is(':hidden') ) + this.open( event ); + else + this.close( event ); + }, + + _handoff: function( extend ) { + return $.extend({ + pointer: this.pointer, + element: this.element + }, extend); + } + }); +})(jQuery); \ No newline at end of file diff --git a/wp-includes/js/wp-pointer.js b/wp-includes/js/wp-pointer.js new file mode 100644 index 0000000000..80c86da617 --- /dev/null +++ b/wp-includes/js/wp-pointer.js @@ -0,0 +1 @@ +(function(c){var a=0,b=9999;c.widget("wp.pointer",{options:{pointerClass:"wp-pointer",content:function(f,e,d){return c(this).text()},buttons:function(f,e){var g=(wpPointerL10n)?wpPointerL10n.close:"Close",d=c(''+g+"
");return d.bind("click.pointer",function(){e.element.pointer("close")})},arrow:"auto",position:{my:"left center",at:"right center"},arrow:{edge:"top",align:"left",offset:20},show:function(e,d){d.pointer.show();d.opened()},hide:function(e,d){d.pointer.hide();d.closed()},document:document},_create:function(){var e,d;this.content=c('
');this.arrow=c('
');d=this.element.parents().add(this.element);e="absolute";if(d.filter(function(){return"fixed"===c(this).css("position")}).length){e="fixed"}this.pointer=c("
").append(this.content).append(this.arrow).attr("id","wp-pointer-"+a++).addClass(this.options.pointerClass).css("position",e).hide().appendTo(this.options.document.body)},_setOption:function(d,f){var g=this.options,e=this.pointer;if(d==="document"&&f!==g.document){e.detach().appendTo(f.body)}else{if(d==="pointerClass"){e.removeClass(g.pointerClass).addClass(f)}}c.Widget.prototype._setOption.apply(this,arguments);if(d==="position"){this.reposition()}else{if(d==="content"&&this.active){this.update()}}},destroy:function(){this.pointer.remove();c.Widget.prototype.destroy.call(this)},widget:function(){return this.pointer},update:function(g){var e=this,h=this.options,d=c.Deferred(),f;if(h.disabled){return}d.done(function(i){e._update(g,i)});if(typeof h.content==="string"){f=h.content}else{f=h.content.call(this.element[0],d.resolve,g,this._handoff())}if(f){d.resolve(f)}return d.promise()},_update:function(f,e){var d,g=this.options;if(!e){return}this.pointer.stop();this.content.html(e);d=g.buttons.call(this.element[0],f,this._handoff());if(d){d.wrap('
').parent().appendTo(this.content)}this.reposition()},reposition:function(){if(this.options.disabled){return}this.pointer.css({top:0,left:0,zIndex:b++}).show().position(c.extend({of:this.element},this.options.position));this.repoint()},repoint:function(){var f=this.options,e={my:"center",of:this.pointer},d;if(f.disabled){return}this.pointer[0].className=this.pointer[0].className.replace(/wp-pointer-[^\s'"]*/,"");if(f.arrow.edge=="top"||f.arrow.edge=="bottom"){e.at=f.arrow.align+" "+f.arrow.edge;e.offset=f.arrow.offset+" 0";d="top"}else{e.at=f.arrow.edge+" "+f.arrow.align;e.offset="0 "+f.arrow.offset;d="left"}this.arrow.position(e).css(d,"");this.pointer.addClass("wp-pointer-"+f.arrow.edge)},open:function(e){var d=this,f=this.options;if(this.active||f.disabled){return}this.update().done(function(){d._open(e)})},_open:function(e){var d=this,f=this.options;if(this.active||f.disabled){return}this.active=true;this._trigger("open",e,this._handoff());this._trigger("show",e,this._handoff({opened:function(){d._trigger("opened",e,d._handoff())}}))},close:function(e){if(!this.active||this.options.disabled){return}var d=this;this.active=false;this._trigger("close",e,this._handoff());this._trigger("hide",e,this._handoff({closed:function(){d._trigger("closed",e,d._handoff())}}))},sendToTop:function(d){if(this.active){this.pointer.css("z-index",b++)}},toggle:function(d){if(this.pointer.is(":hidden")){this.open(d)}else{this.close(d)}},_handoff:function(d){return c.extend({pointer:this.pointer,element:this.element},d)}})})(jQuery); \ No newline at end of file diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 2aafc6b51c..33f0a863b3 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -96,6 +96,11 @@ function wp_default_scripts( &$scripts ) { 'broken' => __('An unidentified error has occurred.') ) ); + $scripts->add( 'wp-pointer', "/wp-includes/js/wp-pointer$suffix.js", array( 'jquery-ui-widget', 'jquery-ui-position' ), '20110918', 1 ); + $scripts->add_script_data( 'wp-pointer', 'wpPointerL10n', array( + 'close' => __('Close'), + ) ); + $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), '20110524', 1 ); $scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array('wp-ajax-response'), '20110521', 1 ); @@ -425,6 +430,7 @@ function wp_default_styles( &$styles ) { $styles->add( 'admin-bar', "/wp-includes/css/admin-bar$suffix.css", array(), '20110916b' ); $styles->add( 'wp-jquery-ui-dialog', "/wp-includes/css/jquery-ui-dialog$suffix.css", array(), '20101224' ); $styles->add( 'editor-buttons', "/wp-includes/css/editor-buttons$suffix.css", array(), '20110802' ); + $styles->add( 'wp-pointer', "/wp-includes/css/wp-pointer$suffix.css", array(), '20110918' ); foreach ( $rtl_styles as $rtl_style ) { $styles->add_data( $rtl_style, 'rtl', true );