Plugin Directory

Changeset 368919


Ignore:
Timestamp:
04/05/2011 03:58:51 AM (15 years ago)
Author:
gluten
Message:

load default options from a function instead of using multiple globals

File:
1 edited

Legend:

Unmodified
Added
Removed
  • galleria-galleria/trunk/galleria-galleria.php

    r368028 r368919  
    22/*
    33Plugin Name: Galleria Galleria
    4 Plugin URI:
     4Plugin URI: https://github.com/samargulies/galleria-galleria/
    55Description: Transform standard WordPress galleries into galleria slideshows.
    66Version: 0.1.1
     
    1717http://galleria.aino.se/
    1818
    19 Mr. Philip Arthur Moore for IE debugging
     19Mr. Philip Arthur Moore for IE debugging of Photo Galleria
    2020http://www.philiparthurmoore.com
    2121
     
    7474}
    7575
    76 function galleria_galleria_admin_head() {
    77 
    7876/**
    7977 * Prints out the inline javascript needed for the colorpicker and choosing
     
    8179 */
    8280 
    83 ?>
    84 
    85 <script type="text/javascript">
    86     jQuery(document).ready(function($) {
    87            
    88         // Color Picker
    89         $('.colorSelector').each(function(){
    90             var Othis = this; //cache a copy of the this variable for use inside nested function
    91             var initialColor = $(Othis).next('input').attr('value');
    92             $(this).ColorPicker({
    93             color: initialColor,
    94             onShow: function (colpkr) {
    95             $(colpkr).fadeIn(500);
    96             return false;
    97             },
    98             onHide: function (colpkr) {
    99             $(colpkr).fadeOut(500);
    100             return false;
    101             },
    102             onChange: function (hsb, hex, rgb) {
    103             $(Othis).children('div').css('backgroundColor', '#' + hex);
    104             $(Othis).next('input').attr('value','#' + hex);
    105         }
    106         });
    107         }); //end color picker
    108     });//end document ready functions
    109 </script>
    110 
    111 <?php
    112 }
    113 
     81function galleria_galleria_admin_head() {
     82    ?>
     83    <script type="text/javascript">
     84        jQuery(document).ready(function($) {
     85               
     86            // Color Picker
     87            $('.colorSelector').each(function(){
     88                var Othis = this; //cache a copy of the this variable for use inside nested function
     89                var initialColor = $(Othis).next('input').attr('value');
     90                $(this).ColorPicker({
     91                color: initialColor,
     92                onShow: function (colpkr) {
     93                $(colpkr).fadeIn(500);
     94                return false;
     95                },
     96                onHide: function (colpkr) {
     97                $(colpkr).fadeOut(500);
     98                return false;
     99                },
     100                onChange: function (hsb, hex, rgb) {
     101                $(Othis).children('div').css('backgroundColor', '#' + hex);
     102                $(Othis).next('input').attr('value','#' + hex);
     103            }
     104            });
     105            }); //end color picker
     106        });//end document ready functions
     107    </script>
     108    <?php
     109}
    114110
    115111/**
     
    117113 */
    118114
    119 $design_options = array(
    120     'classic' => array(
    121         'value' =>  'classic',
    122         'label' => __( 'Classic' )
    123     ),
    124     'dots' => array(
    125         'value' =>  'dots',
    126         'label' => __( 'Dots' )
    127     ),
    128 /*
    129         'fullscreen' => array(
    130         'value' =>  'fullscreen',
    131         'label' => __( 'Fullscreen' )
    132     )
    133 */
    134 );
    135 
    136 $transition_options = array(
    137     'fade' => array(
    138         'value' =>  'fade',
    139         'label' => __( 'Fade' )
    140     ),
    141     'flash' => array(
    142         'value' =>  'flash',
    143         'label' => __( 'Flash' )
    144     ),
    145     'slide' => array(
    146         'value' => 'slide',
    147         'label' => __( 'Slide' )
    148     ),
    149     'fadeslide' => array(
    150         'value' => 'fadeslide',
    151         'label' => __( 'Fade & Slide' )
    152     )
    153 );
    154 
    155 $image_options = array(
    156     'medium' => array(
    157         'value' =>  'medium',
    158         'label' => __( 'Medium' )
    159     ),
    160     'large' => array(
    161         'value' =>  'large',
    162         'label' => __( 'Large' )
    163     )
    164 );
     115function galleria_galleria_default_options() {
     116
     117    $options['design'] = array(
     118        'classic' => array(
     119            'value' =>  'classic',
     120            'label' => __( 'Classic' )
     121        ),
     122        'dots' => array(
     123            'value' =>  'dots',
     124            'label' => __( 'Dots' )
     125        ),
     126    /*
     127            'fullscreen' => array(
     128            'value' =>  'fullscreen',
     129            'label' => __( 'Fullscreen' )
     130        )
     131    */
     132    );
     133   
     134    $options['transition'] = array(
     135        'fade' => array(
     136            'value' =>  'fade',
     137            'label' => __( 'Fade' )
     138        ),
     139        'flash' => array(
     140            'value' =>  'flash',
     141            'label' => __( 'Flash' )
     142        ),
     143        'slide' => array(
     144            'value' => 'slide',
     145            'label' => __( 'Slide' )
     146        ),
     147        'fadeslide' => array(
     148            'value' => 'fadeslide',
     149            'label' => __( 'Fade & Slide' )
     150        )
     151    );
     152   
     153    $options['image'] = array(
     154        'medium' => array(
     155            'value' =>  'medium',
     156            'label' => __( 'Medium' )
     157        ),
     158        'large' => array(
     159            'value' =>  'large',
     160            'label' => __( 'Large' )
     161        )
     162    );
     163   
     164    return $options;
     165}
     166
    165167
    166168/**
     
    169171 
    170172function galleria_galleria_options_do_page() {
    171     global $design_options, $transition_options, $image_options;
     173    $defaults = galleria_galleria_default_options();
    172174
    173175    if ( ! isset( $_REQUEST['updated'] ) )
     
    199201                                $r = '';
    200202
    201                                 foreach ( $design_options as $option ) {
     203                                foreach ( $defaults['design'] as $option ) {
    202204                                    $label = $option['label'];
    203205                                    if ( $selected == $option['value'] ) // Make default first in list
     
    227229                                $r = '';
    228230
    229                                 foreach ( $transition_options as $option ) {
     231                                foreach ( $defaults['transition'] as $option ) {
    230232                                    $label = $option['label'];
    231233                                    if ( $selected == $option['value'] ) // Make default first in list
     
    285287                                $r = '';
    286288
    287                                 foreach ( $image_options as $option ) {
     289                                foreach ( $defaults['image'] as $option ) {
    288290                                    $label = $option['label'];
    289291                                    if ( $selected == $option['value'] ) // Make default first in list
     
    325327 */
    326328function galleria_galleria_options_validate( $input ) {
    327     global $design_options, $transition_options;
     329    $defaults = galleria_galleria_default_options();
    328330
    329331    // Our checkbox value is either 0 or 1
     
    333335   
    334336    if ( ! isset( $input['color'] ) ) {
    335         $input['color'] = '#000';
     337        $input['color'] = '#000000';
    336338    }
    337339   
     
    343345   
    344346    // Our select option must actually be in our array of select options
    345     if ( ! array_key_exists( $input['design'], $design_options ) )
     347    if ( ! array_key_exists( $input['design'], $defaults['design'] ) )
    346348        $input['design'] = null;
    347349
    348350    // Our select option must actually be in our array of select options
    349     if ( ! array_key_exists( $input['transition'], $transition_options ) )
     351    if ( ! array_key_exists( $input['transition'], $defaults['transition'] ) )
    350352        $input['transition'] = null;
    351353
     
    365367    wp_enqueue_script('galleria', plugins_url( '/js/galleria-1.2.2.min.js', __FILE__ ), array('jquery'));
    366368    wp_print_scripts('galleria');
    367     galleria_galleria_scripts_head();
     369    galleria_galleria_script_options();
    368370}
    369371add_action('wp_footer', 'galleria_galleria_load_scripts' );
     
    372374 * Add scripts to head
    373375 */
    374 function galleria_galleria_scripts_head(){
     376 
     377function galleria_galleria_script_options(){
    375378    // Retreive our plugin options
    376379    $galleria_galleria = get_option( 'galleria_galleria' );
Note: See TracChangeset for help on using the changeset viewer.