<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[41264] trunk/src/wp-admin/js/color-picker.js: Docs: Improve JavaScript documentation in color-picker.js.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/41264">41264</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/41264","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>adamsilverstein</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-08-18 13:09:45 +0000 (Fri, 18 Aug 2017)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Docs: Improve JavaScript documentation in color-picker.js.
Add and improve JSDOC blocks.
Props carolinegeven, jjcomack, jipmoors.
Fixes <a href="https://core.trac.wordpress.org/ticket/41063">#41063</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminjscolorpickerjs">trunk/src/wp-admin/js/color-picker.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminjscolorpickerjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/color-picker.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/color-picker.js 2017-08-18 10:59:38 UTC (rev 41263)
+++ trunk/src/wp-admin/js/color-picker.js 2017-08-18 13:09:45 UTC (rev 41264)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2,13 +2,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ( function( $, undef ){
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> var ColorPicker,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // html stuff
</del><span class="cx" style="display: block; padding: 0 10px"> _before = '<a tabindex="0" class="wp-color-result" />',
</span><span class="cx" style="display: block; padding: 0 10px"> _after = '<div class="wp-picker-holder" />',
</span><span class="cx" style="display: block; padding: 0 10px"> _wrap = '<div class="wp-picker-container" />',
</span><span class="cx" style="display: block; padding: 0 10px"> _button = '<input type="button" class="button button-small hidden" />';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // jQuery UI Widget constructor
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Creates a jQuery UI color picker.
+ *
+ * Creates a jQuery UI color picker that is used in the theme customizer.
+ *
+ * @since 3.5.0
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> ColorPicker = {
</span><span class="cx" style="display: block; padding: 0 10px"> options: {
</span><span class="cx" style="display: block; padding: 0 10px"> defaultColor: false,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -21,21 +26,39 @@
</span><span class="cx" style="display: block; padding: 0 10px"> type: 'full',
</span><span class="cx" style="display: block; padding: 0 10px"> slider: 'horizontal'
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Creates a color picker that only allows you to adjust the hue.
+ *
+ * @since 3.5.0
+ *
+ * @access private
+ *
+ * @returns {void}
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> _createHueOnly: function() {
</span><span class="cx" style="display: block; padding: 0 10px"> var self = this,
</span><span class="cx" style="display: block; padding: 0 10px"> el = self.element,
</span><span class="cx" style="display: block; padding: 0 10px"> color;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // hide input
</del><span class="cx" style="display: block; padding: 0 10px"> el.hide();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // max saturated color for hue to be obvious
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Set the saturation to the maximum level.
</ins><span class="cx" style="display: block; padding: 0 10px"> color = 'hsl(' + el.val() + ', 100, 50)';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Create an instance of the color picker, using the hsl mode.
</ins><span class="cx" style="display: block; padding: 0 10px"> el.iris( {
</span><span class="cx" style="display: block; padding: 0 10px"> mode: 'hsl',
</span><span class="cx" style="display: block; padding: 0 10px"> type: 'hue',
</span><span class="cx" style="display: block; padding: 0 10px"> hide: false,
</span><span class="cx" style="display: block; padding: 0 10px"> color: color,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Handles the onChange event if one has been defined in the options.
+ *
+ * @param {Event} event The event that's being called.
+ * @param {HTMLElement} ui The HTMLElement containing the color picker.
+ *
+ * @returns {void}
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> change: function( event, ui ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $.isFunction( self.options.change ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> self.options.change.call( this, event, ui );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -45,8 +68,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> slider: self.options.slider
</span><span class="cx" style="display: block; padding: 0 10px"> } );
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Creates the color picker.
+ *
+ * Creates the color picker, sets default values, css classes and wraps it all in HTML.
+ *
+ * @since 3.5.0
+ *
+ * @access private
+ *
+ * @returns {void}
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> _create: function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // bail early for unsupported Iris.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Return early if Iris support is missing.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $.support.iris ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -54,19 +88,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> var self = this,
</span><span class="cx" style="display: block; padding: 0 10px"> el = self.element;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Override default options with options bound to the element.
</ins><span class="cx" style="display: block; padding: 0 10px"> $.extend( self.options, el.data() );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // hue-only gets created differently
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Create a color picker which only allows adjustments to the hue.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( self.options.type === 'hue' ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return self._createHueOnly();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // keep close bound so it can be attached to a body listener
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Bind the close event.
</ins><span class="cx" style="display: block; padding: 0 10px"> self.close = $.proxy( self.close, self );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self.initialValue = el.val();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Set up HTML structure, hide things
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Set up HTML structure and hide the color picker.
</ins><span class="cx" style="display: block; padding: 0 10px"> el.addClass( 'wp-color-picker' ).hide().wrap( _wrap );
</span><span class="cx" style="display: block; padding: 0 10px"> self.wrap = el.parent();
</span><span class="cx" style="display: block; padding: 0 10px"> self.toggler = $( _before ).insertBefore( el ).css( { backgroundColor: self.initialValue } ).attr( 'title', wpColorPickerL10n.pick ).attr( 'data-current', wpColorPickerL10n.current );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -79,7 +114,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> self.button.addClass( 'wp-picker-clear' ).val( wpColorPickerL10n.clear );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- el.wrap( '<span class="wp-picker-input-wrap" />' ).after(self.button);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ el.wrap( '<span class="wp-picker-input-wrap" />' ).after( self.button );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> el.iris( {
</span><span class="cx" style="display: block; padding: 0 10px"> target: self.pickerContainer,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -87,9 +122,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> width: self.options.width,
</span><span class="cx" style="display: block; padding: 0 10px"> mode: self.options.mode,
</span><span class="cx" style="display: block; padding: 0 10px"> palettes: self.options.palettes,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Handles the onChange event if one has been defined in the options.
+ *
+ * Handles the onChange event if one has been defined in the options and additionally
+ * sets the background color for the toggler element.
+ *
+ * @since 3.5.0
+ *
+ * @param {Event} event The event that's being called.
+ * @param {HTMLElement} ui The HTMLElement containing the color picker.
+ *
+ * @returns {void}
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> change: function( event, ui ) {
</span><span class="cx" style="display: block; padding: 0 10px"> self.toggler.css( { backgroundColor: ui.color.toString() } );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // check for a custom cb
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $.isFunction( self.options.change ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> self.options.change.call( this, event, ui );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -98,18 +146,42 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> el.val( self.initialValue );
</span><span class="cx" style="display: block; padding: 0 10px"> self._addListeners();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Force the color picker to always be closed on initial load.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! self.options.hide ) {
</span><span class="cx" style="display: block; padding: 0 10px"> self.toggler.click();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Binds event listeners to the color picker.
+ *
+ * @since 3.5.0
+ *
+ * @access private
+ *
+ * @returns {void}
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> _addListeners: function() {
</span><span class="cx" style="display: block; padding: 0 10px"> var self = this;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // prevent any clicks inside this widget from leaking to the top and closing it
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Prevent any clicks inside this widget from leaking to the top and closing it.
+ *
+ * @since 3.5.0
+ *
+ * @param {Event} event The event that's being called.
+ *
+ * @returs {void}
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> self.wrap.on( 'click.wpcolorpicker', function( event ) {
</span><span class="cx" style="display: block; padding: 0 10px"> event.stopPropagation();
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Open or close the color picker depending on the class.
+ *
+ * @since 3.5
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> self.toggler.click( function(){
</span><span class="cx" style="display: block; padding: 0 10px"> if ( self.toggler.hasClass( 'wp-picker-open' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> self.close();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -118,20 +190,43 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Checks if value is empty when changing the color in the color picker.
+ *
+ * Checks if value is empty when changing the color in the color picker.
+ * If so, the background color is cleared.
+ *
+ * @since 3.5.0
+ *
+ * @param {Event} event The event that's being called.
+ *
+ * @returns {void}
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> self.element.change( function( event ) {
</span><span class="cx" style="display: block; padding: 0 10px"> var me = $( this ),
</span><span class="cx" style="display: block; padding: 0 10px"> val = me.val();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Empty = clear
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( val === '' || val === '#' ) {
</span><span class="cx" style="display: block; padding: 0 10px"> self.toggler.css( 'backgroundColor', '' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // fire clear callback if we have one
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Fire clear callback if we have one.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $.isFunction( self.options.clear ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> self.options.clear.call( this, event );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // open a keyboard-focused closed picker with space or enter
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Enables the user to open the color picker with their keyboard.
+ *
+ * Enables the user to open the color picker with their keyboard.
+ * This is possible by using the space or enter key.
+ *
+ * @since 3.5.0
+ *
+ * @param {Event} event The event that's being called.
+ *
+ * @returns {void}
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> self.toggler.on( 'keyup', function( event ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( event.keyCode === 13 || event.keyCode === 32 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> event.preventDefault();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -139,6 +234,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Enables the user to clear or revert the color in the color picker.
+ *
+ * Enables the user to either clear the color in the color picker or revert back to the default color.
+ *
+ * @since 3.5.0
+ *
+ * @param {Event} event The event that's being called.
+ *
+ * @returns {void}
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> self.button.click( function( event ) {
</span><span class="cx" style="display: block; padding: 0 10px"> var me = $( this );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( me.hasClass( 'wp-picker-clear' ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -152,6 +258,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Opens the color picker dialog.
+ *
+ * @since 3.5.0
+ *
+ * @returns {void}
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> open: function() {
</span><span class="cx" style="display: block; padding: 0 10px"> this.element.show().iris( 'toggle' ).focus();
</span><span class="cx" style="display: block; padding: 0 10px"> this.button.removeClass( 'hidden' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -159,6 +272,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> this.toggler.addClass( 'wp-picker-open' );
</span><span class="cx" style="display: block; padding: 0 10px"> $( 'body' ).trigger( 'click.wpcolorpicker' ).on( 'click.wpcolorpicker', this.close );
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Closes the color picker dialog.
+ *
+ * @since 3.5.0
+ *
+ * @returns {void}
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> close: function() {
</span><span class="cx" style="display: block; padding: 0 10px"> this.element.hide().iris( 'toggle' );
</span><span class="cx" style="display: block; padding: 0 10px"> this.button.addClass( 'hidden' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -166,16 +286,35 @@
</span><span class="cx" style="display: block; padding: 0 10px"> this.toggler.removeClass( 'wp-picker-open' );
</span><span class="cx" style="display: block; padding: 0 10px"> $( 'body' ).off( 'click.wpcolorpicker', this.close );
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // $("#input").wpColorPicker('color') returns the current color
- // $("#input").wpColorPicker('color', '#bada55') to set
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Returns iris object or sets new color.
+ *
+ * Returns the iris object if no new color is provided. If a new color is provided, it sets the new color.
+ *
+ * @param newColor {string|*} The new color to use. Can be undefined.
+ *
+ * @since 3.5.0
+ *
+ * @returns {string} The element's color
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> color: function( newColor ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( newColor === undef ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return this.element.iris( 'option', 'color' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> this.element.iris( 'option', 'color', newColor );
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //$("#input").wpColorPicker('defaultColor') returns the current default color
- //$("#input").wpColorPicker('defaultColor', newDefaultColor) to set
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @summary Returns iris object or sets new default color.
+ *
+ * Returns the iris object if no new default color is provided.
+ * If a new default color is provided, it sets the new default color.
+ *
+ * @param newDefaultColor {string|*} The new default color to use. Can be undefined.
+ *
+ * @since 3.5.0
+ *
+ * @returns {boolean|string} The element's color.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> defaultColor: function( newDefaultColor ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( newDefaultColor === undef ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return this.options.defaultColor;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -185,5 +324,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Register the color picker as a widget.
</ins><span class="cx" style="display: block; padding: 0 10px"> $.widget( 'wp.wpColorPicker', ColorPicker );
</span><span class="cx" style="display: block; padding: 0 10px"> }( jQuery ) );
</span></span></pre>
</div>
</div>
</body>
</html>