Add pointers feature, and pointer to admin bar, props nacin for PHP bits, see #18693.

git-svn-id: https://develop.svn.wordpress.org/trunk@18707 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Daryl Koopersmith 2011-09-18 21:17:09 +00:00
parent be4c3e1d86
commit 342180470d
6 changed files with 429 additions and 0 deletions

View File

@ -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 = '<h3>' . __('The admin bar has been updated in WordPress 3.3.') . '</h3>';
$pointer_content .= '<p>' . sprintf( __('Have some feedback? Visit this <a href="%s">ticket</a>.'), 'http://core.trac.wordpress.org/ticket/18197' ) . '</p>';
$pointer_content .= '<p>' . sprintf( __('P.S. You are looking at a new admin pointer. Chime in <a href="%s">here</a>.'), 'http://core.trac.wordpress.org/ticket/18693' ) . '</p>';
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready( function($) {
$('#wpadminbar').pointer({
content: '<?php echo $pointer_content; ?>',
position: {
my: 'left top',
at: 'center bottom',
offset: '-25 0'
},
close: function() {
setUserSetting( 'p0', '1' );
}
}).pointer('open');
});
//]]>
</script>
<?php
}

View File

@ -0,0 +1 @@
.wp-pointer-content{padding:0 10px;background:white;border:1px solid #aaa;-moz-box-shadow:0 0 16px rgba(0,0,0,0.1);-webkit-box-shadow:0 0 16px rgba(0,0,0,0.1);box-shadow:0 0 16px rgba(0,0,0,0.1);}.wp-pointer-buttons{padding:0 0 10px 0;overflow:auto;}.wp-pointer-buttons a{float:right;display:inline-block;}.wp-pointer-arrow,.wp-pointer-arrow-inner{position:absolute;width:0;height:0;}.wp-pointer-arrow{z-index:10;}.wp-pointer-arrow-inner{z-index:20;}.wp-pointer-left{margin-left:10px;}.wp-pointer-right{margin-left:-10px;}.wp-pointer-top{margin-top:10px;}.wp-pointer-bottom{margin-top:-10px;}.wp-pointer-left .wp-pointer-arrow,.wp-pointer-right .wp-pointer-arrow,.wp-pointer-top .wp-pointer-arrow,.wp-pointer-bottom .wp-pointer-arrow{border:solid 10px transparent;}.wp-pointer-left .wp-pointer-arrow{border-right-color:#aaa;border-left-width:0;right:100%;top:0;}.wp-pointer-right .wp-pointer-arrow{border-left-color:#aaa;border-right-width:0;left:100%;top:0;}.wp-pointer-top .wp-pointer-arrow{border-bottom-color:#aaa;border-top-width:0;left:0;bottom:100%;}.wp-pointer-bottom .wp-pointer-arrow{border-top-color:#aaa;border-bottom-width:0;left:0;top:100%;}.wp-pointer-left .wp-pointer-arrow-inner,.wp-pointer-right .wp-pointer-arrow-inner,.wp-pointer-top .wp-pointer-arrow-inner,.wp-pointer-bottom .wp-pointer-arrow-inner{border:solid 9px transparent;}.wp-pointer-left .wp-pointer-arrow-inner{border-right-color:#fff;border-left-width:0;top:-9px;left:2px;}.wp-pointer-right .wp-pointer-arrow-inner{border-left-color:#fff;border-right-width:0;top:-9px;right:2px;}.wp-pointer-top .wp-pointer-arrow-inner{border-bottom-color:#fff;border-top-width:0;top:2px;left:-9px;}.wp-pointer-bottom .wp-pointer-arrow-inner{border-top-color:#fff;border-bottom-width:0;bottom:2px;left:-9px;}

View File

@ -0,0 +1,106 @@
.wp-pointer-content {
padding: 0 10px;
background: white;
border: 1px solid #aaa;
-moz-box-shadow: 0 0 16px rgba( 0, 0, 0, 0.1 );
-webkit-box-shadow: 0 0 16px rgba( 0, 0, 0, 0.1 );
box-shadow: 0 0 16px rgba( 0, 0, 0, 0.1 );
}
.wp-pointer-buttons {
padding: 0 0 10px 0;
overflow: auto;
}
.wp-pointer-buttons a {
float: right;
display: inline-block;
}
/* The arrow base class must take up no space, even with transparent borders. */
.wp-pointer-arrow,
.wp-pointer-arrow-inner {
position: absolute;
width: 0;
height: 0;
}
.wp-pointer-arrow {
z-index: 10;
}
.wp-pointer-arrow-inner {
z-index: 20;
}
.wp-pointer-left {
margin-left: 10px;
}
.wp-pointer-right {
margin-left: -10px;
}
.wp-pointer-top {
margin-top: 10px;
}
.wp-pointer-bottom {
margin-top: -10px;
}
.wp-pointer-left .wp-pointer-arrow,
.wp-pointer-right .wp-pointer-arrow,
.wp-pointer-top .wp-pointer-arrow,
.wp-pointer-bottom .wp-pointer-arrow {
border: solid 10px transparent;
}
.wp-pointer-left .wp-pointer-arrow {
border-right-color: #aaa;
border-left-width: 0;
right: 100%;
top: 0;
}
.wp-pointer-right .wp-pointer-arrow {
border-left-color: #aaa;
border-right-width: 0;
left: 100%;
top: 0;
}
.wp-pointer-top .wp-pointer-arrow {
border-bottom-color: #aaa;
border-top-width: 0;
left: 0;
bottom: 100%;
}
.wp-pointer-bottom .wp-pointer-arrow {
border-top-color: #aaa;
border-bottom-width: 0;
left: 0;
top: 100%;
}
.wp-pointer-left .wp-pointer-arrow-inner,
.wp-pointer-right .wp-pointer-arrow-inner,
.wp-pointer-top .wp-pointer-arrow-inner,
.wp-pointer-bottom .wp-pointer-arrow-inner {
border: solid 9px transparent;
}
.wp-pointer-left .wp-pointer-arrow-inner {
border-right-color: #fff;
border-left-width: 0;
top: -9px;
left: 2px;
}
.wp-pointer-right .wp-pointer-arrow-inner {
border-left-color: #fff;
border-right-width: 0;
top: -9px;
right: 2px;
}
.wp-pointer-top .wp-pointer-arrow-inner {
border-bottom-color: #fff;
border-top-width: 0;
top: 2px;
left: -9px;
}
.wp-pointer-bottom .wp-pointer-arrow-inner {
border-top-color: #fff;
border-bottom-width: 0;
bottom: 2px;
left: -9px;
}

View File

@ -0,0 +1,264 @@
/**
* Pointer jQuery widget.
*/
(function($){
var identifier = 0,
zindex = 9999;
$.widget("wp.pointer", {
options: {
pointerClass: 'wp-pointer',
content: function( respond, event, t ) {
return $(this).text();
},
buttons: function( event, t ) {
var close = ( wpPointerL10n ) ? wpPointerL10n.close : 'Close',
button = $('<a class="button-secondary">' + close + '</div>');
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 = $('<div class="wp-pointer-content"></div>');
this.arrow = $('<div class="wp-pointer-arrow"><div class="wp-pointer-arrow-inner"></div></div>');
family = this.element.parents().add( this.element );
positioning = 'absolute';
if ( family.filter(function(){ return 'fixed' === $(this).css('position'); }).length )
positioning = 'fixed';
this.pointer = $('<div />')
.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('<div class="wp-pointer-buttons" />').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);

View File

@ -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('<a class="button-secondary">'+g+"</div>");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('<div class="wp-pointer-content"></div>');this.arrow=c('<div class="wp-pointer-arrow"><div class="wp-pointer-arrow-inner"></div></div>');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("<div />").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('<div class="wp-pointer-buttons" />').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);

View File

@ -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 );