Skip to content

Commit

Permalink
Initial commit of demonstration files
Browse files Browse the repository at this point in the history
  • Loading branch information
rachelbaker committed Nov 27, 2012
0 parents commit 5b46036
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

codekit-config.json
21 changes: 21 additions & 0 deletions admin-option-view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/** WordPress Administration Bootstrap */
require_once './admin.php';
if ( !current_user_can('edit_posts') )
wp_die(__('Cheatin&#8217; uh?'));
?>
<div class="wrap">
<div id="icon-tools" class="icon32 icon32-posts-deprecated_log"><br></div><?php echo "<h2>".__('Iris Color Picker Demo')."</h2>";?>
<form method="post" action="options.php">
<?php settings_fields( 'iris_cpdemo_plugin_options' ); ?>
<?php $options = get_option( 'iris_cpdemo_options' );?>

<ul>
<li><label for="link_color"><?php echo __('Link Color'); ?>: </label>
<input name="iris_cpdemo_options[link_color]" id="link-color" type="text" value="<?php if ( isset( $options['link_color'] ) ) echo $options['link_color']; ?>" />
</li>
</ul>

<?php submit_button();?>
</form>
</div>
39 changes: 39 additions & 0 deletions cp-demo-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*!
* Iris Color Picker Demo Script
* @author: Rachel Baker ( rachel@rachelbaker.me )
*/
(function ($) {
"use strict";

var default_color = 'fbfbfb';

function pickColor(color) {
$('#link-color').val(color);
}
function toggle_text() {
link_color = $('#link-color');
if ('' === link_color.val().replace('#', '')) {
link_color.val(default_color);
pickColor(default_color);
} else {
pickColor(link_color.val());
}
}

$(document).ready(function () {
var link_color = $('#link-color');
link_color.wpColorPicker({
change: function (event, ui) {
pickColor(link_color.wpColorPicker('color'));
},
clear: function () {
pickColor('');
}
});
$('#link-color').click(toggle_text);

toggle_text();

});

}(jQuery));
30 changes: 30 additions & 0 deletions cp-demo-script.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*!
* Iris Color Picker Demo Script
* @author: Rachel Baker ( rachel@rachelbaker.me )
*/(function($) {
"use strict";
function pickColor(color) {
$("#link-color").val(color);
}
function toggle_text() {
link_color = $("#link-color");
if ("" === link_color.val().replace("#", "")) {
link_color.val(default_color);
pickColor(default_color);
} else pickColor(link_color.val());
}
var default_color = "fbfbfb";
$(document).ready(function() {
var link_color = $("#link-color");
link_color.wpColorPicker({
change: function(event, ui) {
pickColor(link_color.wpColorPicker("color"));
},
clear: function() {
pickColor("");
}
});
$("#link-color").click(toggle_text);
toggle_text();
});
})(jQuery);
96 changes: 96 additions & 0 deletions cp-demo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/*
Plugin Name: Iris Color Picker Demo
Plugin URI: http://www.rachelbaker.me
Description: Demonstrating how to use the new Iris color picker
Version: 1.0
Author: Rachel Baker
Author URI: http://www.rachelbaker.me
Author Email: rachel@rachelbaker.me
License:
Color Picker Demo
Copyright (C) 2012 Rachel Baker, Plugged In Consulting, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

add_action('admin_init', 'iris_cpdemo_init' );
add_action('admin_menu', 'iris_cpdemo_add_options_page');
add_action( 'admin_enqueue_scripts', 'iris_cpdemo_admin_enqueue_scripts' );

/**
* Uses the Settings_API to register the plugin options.
* Options are saved in the wp_options table under the Option Name.
*
* Option group is iris_cpdemo_plugin_options
* Option name is iris_cpdemo_options
*
* Initialized with admin_init hook
*/
function iris_cpdemo_init(){
register_setting( 'iris_cpdemo_plugin_options', 'iris_cpdemo_options', 'iris_cpdemo_validate_options' );
}

/**
* Adds the plugin's option page to the Settings menu section.
* Defines plugin options page parameters.
*
* Initialized with admin_menu hook
*/
function iris_cpdemo_add_options_page() {
add_options_page('Iris Color Picker Demo', 'Iris Demo', 'manage_options', __FILE__, 'iris_cpdemo_display_options');
}

/**
* Displays plugin options page view
*
* Initialized in iris_cpdemo_add_options_page()
*/
function iris_cpdemo_display_options() {
include "admin-option-view.php";
}

/**
* Santizes input from plugin options page.
* Uses sanitize_text_field to strip html from input text.
* @param array $input
* @return array $input
*/
function iris_cpdemo_validate_options($input) {
// strip html from textboxes
sanitize_text_field($input);
return $input;
}

/**
* Load the built-in 'wp-color-picker' script and style.
* Load the plugin specific 'cp-demo-custom' script that handles
* the use of the wp-color-picker script on our plugin options page.
*
* @param string $hook current admin screen suffix
*
* Initialized with admin_enqueue_scripts hook
*/
function iris_cpdemo_admin_enqueue_scripts($hook) {
// bail early if this is not the plugin option screen
if( 'settings_page_color-picker-demo/cp-demo' !== $hook ) {
return;
}
// load the wp-color-picker script and style
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_script( 'cp_demo-custom', plugins_url( 'cp-demo-script.min.js', __FILE__ ), array( 'jquery', 'wp-color-picker' ), '1.0', true );
wp_enqueue_style( 'wp-color-picker' );
}

0 comments on commit 5b46036

Please sign in to comment.