Skip to content
Browse files

add format

  • Loading branch information...
1 parent d0c5778 commit ca350a7c95abc627b7718852e07776fdb5fc696f @bueltge committed Sep 6, 2012
Showing with 173 additions and 0 deletions.
  1. +84 −0 inc/theme-customize.php
  2. +35 −0 inc/theme-options.css
  3. +54 −0 inc/theme-options.js
View
84 inc/theme-customize.php
@@ -0,0 +1,84 @@
+<?php
+/**
+ * Documentation Theme Options in Theme Customizer
+ *
+ * @package WordPress
+ * @subpackage Documentation
+ * @since 09/06/2012
+ */
+
+class Documentation_Customize extends Documentation_Options {
+
+ /**
+ * Identifier, namespace
+ */
+ public static $theme_key = '';
+
+ /**
+ * The option value in the database will be based on get_stylesheet()
+ * so child themes don't share the parent theme's option value.
+ */
+ public static $option_key = '';
+
+ /**
+ * Initialize
+ */
+ public function __construct( $args = NULL ) {
+
+ // Set option key based on get_stylesheet()
+ if ( NULL === $args )
+ $args['theme_key'] = strtolower( get_stylesheet() );
+
+ // Set option key based on get_stylesheet()
+ $this->theme_key = $args['theme_key'];
+ $this->option_key = $this->theme_key . '_theme_options';
+
+ add_action( 'customize_register', array( $this, 'customize_register' ) );
+ }
+
+ /**
+ * Implement theme options into Theme Customizer on Frontend
+ *
+ * @since 08/09/2012
+ * @param $wp_customize Theme Customizer object
+ * @return void
+ */
+ public function customize_register( $wp_customize ) {
+
+ $defaults = parent::get_default_theme_options();
+
+ // create custom section for rewrite url
+ $wp_customize->add_section( $this->option_key . '_rewrite_url', array(
+ 'title' => __( 'Rewrite', 'documentation' ),
+ 'priority' => 35,
+ ) );
+
+ // add field for rewrite url in custom section
+ $wp_customize->add_setting( $this->option_key . '[rewrite_url]', array(
+ 'default' => $defaults['rewrite_url'],
+ 'type' => 'option',
+ 'capability' => 'edit_theme_options',
+ ) );
+
+ $wp_customize->add_control( $this->option_key . '_rewrite_url', array(
+ 'label' => __( 'Rewrite URL', 'documentation' ),
+ 'section' => $this->option_key . '_rewrite_url',
+ 'settings' => $this->option_key . '[rewrite_url]',
+ 'type' => 'text',
+ ) );
+
+ // add field for text color in default section for 'colors'
+ $wp_customize->add_setting( $this->option_key . '[text_color]', array(
+ 'default' => $defaults['text_color'],
+ 'type' => 'option',
+ 'capability' => 'edit_theme_options',
+ ) );
+ // add color field include
+ $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $this->option_key . '_text_color', array(
+ 'label' => __( 'Text Color', 'documentation' ),
+ 'section' => 'colors',
+ 'settings' => $this->option_key . '[text_color]',
+ ) ) );
+ }
+
+} // end class
View
35 inc/theme-options.css
@@ -0,0 +1,35 @@
+#wpcontent select option {
+ padding-right: 5px;
+}
+.image-radio-option td {
+ padding-top: 15px;
+}
+.image-radio-option label {
+ display: block;
+ float: left;
+ margin: 0 30px 20px 2px;
+ position: relative;
+}
+.image-radio-option input {
+ margin: 0 0 10px;
+}
+.image-radio-option span {
+ display: block;
+ width: 136px;
+}
+.image-radio-option img {
+ margin: 0 0 0 -2px;
+}
+#text-color-example {
+ -moz-border-radius: 4px;
+ -webkit-border-radius: 4px;
+ border-radius: 4px;
+ border: 1px solid #dfdfdf;
+ margin: 0 7px 0 3px;
+ padding: 4px 14px;
+}
+
+body.rtl .image-radio-option label {
+ float: right;
+ margin: 0 2px 20px 30px;
+}
View
54 inc/theme-options.js
@@ -0,0 +1,54 @@
+var farbtastic;
+
+( function($) {
+
+ var pickColor = function(a) {
+ farbtastic.setColor(a);
+ $('#text-color').val(a);
+ $('#text-color-example').css('background-color', a);
+ };
+
+ $(document).ready( function() {
+ $('#default-color').wrapInner('<a href="#" />');
+
+ farbtastic = $.farbtastic('#colorPickerDiv', pickColor);
+
+ pickColor( $('#text-color').val() );
+
+ $('.pickcolor').click( function(e) {
+ $('#colorPickerDiv').show();
+ e.preventDefault();
+ });
+
+ $('#text-color').keyup( function() {
+ var a = $('#text-color').val(),
+ b = a;
+
+ a = a.replace(/[^a-fA-F0-9]/, '');
+ if ( '#' + a !== b )
+ $('#text-color').val(a);
+ if ( a.length === 3 || a.length === 6 )
+ pickColor( '#' + a );
+ });
+
+ $(document).mousedown( function() {
+ $('#colorPickerDiv').hide();
+ });
+
+ $('#default-color a').click( function(e) {
+ pickColor( '#' + this.innerHTML.replace(/[^a-fA-F0-9]/, '') );
+ e.preventDefault();
+ });
+
+ $('.image-radio-option.color-scheme input:radio').change( function() {
+ var currentDefault = $('#default-color a'),
+ newDefault = $(this).next().val();
+
+ if ( $('#text-color').val() == currentDefault.text() )
+ pickColor( newDefault );
+
+ currentDefault.text( newDefault );
+ });
+ });
+
+} )(jQuery);

0 comments on commit ca350a7

Please sign in to comment.
Something went wrong with that request. Please try again.