Plugin Directory

Changeset 1454781


Ignore:
Timestamp:
07/14/2016 02:56:33 PM (10 years ago)
Author:
firimar
Message:

small refactoring

Location:
wp-magnific-popup/trunk
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • wp-magnific-popup/trunk/js/wpmp.js

    r1454500 r1454781  
    22    if (typeof wpmp_options !== 'undefined')
    33    {
    4         if (typeof wpmp_options.image_class !== 'undefined')
    5         {
     4
    65            console.log(wpmp_options);
    7             if (wpmp_options.image_class) {
    8                 jQuery('.' + wpmp_options.image_class).magnificPopup({
     6            if (typeof wpmp_options.image !== 'undefined' && wpmp_options.image.class) {
     7                jQuery('.' + wpmp_options.image.class).magnificPopup({
    98                    type: 'image',
    109                    closeOnContentClick: true,
    1110                    image: {
    12                         verticalFit: wpmp_options.image_vertical_fit
     11                        verticalFit: typeof wpmp_options.image.vertical_fit !== 'undefined' && wpmp_options.image.vertical_fit
    1312                    },
    1413                    zoom: {
    15                         enabled: wpmp_options.image_zoom_enabled,
     14                        enabled: typeof wpmp_options.image.zoom_enabled !== 'undefined' && wpmp_options.image.zoom_enabled,
    1615                        duration: 300
    1716                    }
     
    1918            }
    2019
    21             if (wpmp_options.gallery_class) {
    22                 jQuery('.' + wpmp_options.gallery_class).magnificPopup({
     20            if (typeof wpmp_options.gallery !== 'undefined' && wpmp_options.gallery.class) {
     21                jQuery('.' + wpmp_options.gallery.class).magnificPopup({
    2322                    delegate: 'a',
    2423                    type: 'image',
    2524                    tLoading: wpmp_options.image_loading_text,
    26                     //mainClass: 'mfp-img-mobile',
    2725                    gallery: {
    2826                        enabled: true,
     
    3937            }
    4038
    41             if (wpmp_options.iframe_class) {
    42                 jQuery('.' + wpmp_options.iframe_class).magnificPopup({
     39            if (typeof wpmp_options.iframe !== 'undefined' && wpmp_options.iframe.class) {
     40                jQuery('.' + wpmp_options.iframe.class).magnificPopup({
    4341                    type: 'iframe',
    4442                    disableOn: 700,
     
    4947            }
    5048
    51             if (wpmp_options.div_class) {
    52                 jQuery('.' + wpmp_options.div_class).magnificPopup({
     49            if (typeof wpmp_options.div !== 'undefined' && wpmp_options.div.class) {
     50                jQuery('.' + wpmp_options.div.class).magnificPopup({
    5351                    type: 'inline',
    5452                    closeBtnInside: true,
     
    5755            }
    5856        }
    59     }
    6057});
  • wp-magnific-popup/trunk/wp_magnific_popup.php

    r1454500 r1454781  
    1818        add_action( 'admin_init', array($this, 'register_settings') );
    1919        add_action( 'plugins_loaded', array($this, 'load_textdomain') );
     20        add_filter( 'plugin_action_links', array($this, 'plugin_action_links'), 10, 2 );
     21        add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
     22    }
     23
     24    function admin_scripts()
     25    {
     26        wp_enqueue_script('jquery-ui-core');
     27        wp_enqueue_script('jquery-ui-tabs');
     28
     29        wp_enqueue_script('wpmp-admin', plugins_url('js/admin.js', __FILE__), array('jquery', 'jquery-ui-tabs'));
     30    }
     31
     32    function plugin_action_links($links, $file)
     33    {
     34        if( false === strpos( $file, basename(__FILE__) ) )
     35            return $links;
     36
     37        $settings_link = '<a href="options-general.php?page=wp-magnific-popup">' . esc_html__( 'Settings', 'wp-magnific-popup' ) . '</a>';
     38        array_unshift( $links, $settings_link );
     39
     40        return $links;
    2041    }
    2142
     
    3455    function wp_head()
    3556    {
     57
    3658        ?>
    3759        <script type="text/javascript">
    3860            var wpmp_options = {
    39                 image_class: '<?=get_option('wpmp_image_class')?>',
    40                 gallery_class: '<?=get_option('wpmp_gallery_class')?>',
     61                image: <?=json_encode(get_option('wpmp_image_settings'))?>,
     62                gallery: <?=json_encode(get_option('wpmp_gallery_settings'))?>,
     63                iframe: <?=json_encode(get_option('wpmp_iframe_settings'))?>,
     64                div: <?=json_encode(get_option('wpmp_div_settings'))?>,
    4165                image_loading_text: '<?=__('Loading image #%curr%...', 'wp-magnific-popup')?>',
    42                 image_error_text: '<?=__('<a href="%url%">The image #%curr%</a> could not be loaded.', 'wp-magnific-popup')?>',
    43                 image_vertical_fit: <?= get_option('wpmp_image_vertical_fit') == 1 ? 'true' : 'false' ?>,
    44                 image_zoom_enabled: <?= get_option('wpmp_image_zoom_enabled') == 1 ? 'true' : 'false' ?>,
    45                 iframe_class: '<?=get_option('wpmp_iframe_class')?>',
    46                 div_class: '<?=get_option('wpmp_div_class')?>',
     66                image_error_text: '<?=__('<a href="%url%">The image #%curr%</a> could not be loaded.', 'wp-magnific-popup')?>'
    4767            };
    4868        </script>
     
    5979    {
    6080        ?>
     81
    6182        <div class="wrap">
    6283            <h2><?php _e('WP Magnific Popup Settings', 'wp-magnific-popup') ?></h2>
    6384            <form method="post" action="options.php">
    6485                <?php settings_fields( 'wp-magnific-popup-settings-group' ); ?>
    65                 <table class="form-table ps-form-table">
    66                     <tr>
    67                         <th colspan="2"><h3><?php _e('Images', 'wp-magnific-popup') ?></h3></th>
    68                     </tr>
    69                     <tr>
    70                         <th><?php _e('CSS class for images', 'wp-magnific-popup') ?>:</th>
    71                         <td><input type="text" name="wpmp_image_class" value="<?=get_option('wpmp_image_class')?>" /></td>
    72                     </tr>
    73                     <tr>
    74                         <th><?php _e('Vertical Fit', 'wp-magnific-popup') ?>:</th>
    75                         <td><input type="checkbox" name="wpmp_image_vertical_fit" value="1" <?php if (get_option('wpmp_image_vertical_fit') == 1) echo 'checked="checked"';?> /></td>
    76                     </tr>
    77                     <tr>
    78                         <th><?php _e('Enable Zoom Animation', 'wp-magnific-popup') ?>:</th>
    79                         <td><input type="checkbox" name="wpmp_image_zoom_enabled" value="1" <?php if (get_option('wpmp_image_zoom_enabled') == 1) echo 'checked="checked"';?> /></td>
    80                     </tr>
    81                     <tr>
    82                         <th colspan="2"><h3><?php _e('Galleries', 'wp-magnific-popup') ?></h3></th>
    83                     </tr>
    84                     <tr>
    85                         <th><?php _e('CSS class for galleries', 'wp-magnific-popup') ?>:</th>
    86                         <td><input type="text" name="wpmp_gallery_class" value="<?=get_option('wpmp_gallery_class')?>" /></td>
    87                     </tr>
    88                     <tr>
    89                         <th colspan="2"><h3><?php _e('Iframes', 'wp-magnific-popup') ?></h3></th>
    90                     </tr>
    91                     <tr>
    92                         <th><?php _e('CSS class for iframes', 'wp-magnific-popup') ?>:</th>
    93                         <td><input type="text" name="wpmp_iframe_class" value="<?=get_option('wpmp_iframe_class')?>" /></td>
    94                     </tr>
    95                     <tr>
    96                         <th colspan="2"><h3><?php _e('Dialogs', 'wp-magnific-popup')?></h3></th>
    97                     </tr>
    98                     <tr>
    99                         <th><?php _e('CSS class for dialogs', 'wp-magnific-popup') ?>:</th>
    100                         <td><input type="text" name="wpmp_div_class" value="<?=get_option('wpmp_div_class')?>" /></td>
    101                     </tr>
    102                 </table>
     86                <div id="wpmp_tabs">
     87                    <ul>
     88                        <li><a href="#wpmp_images"><?php _e('Images', 'wp-magnific-popup') ?></a></li>
     89                        <li><a href="#wpmp_galleries"><?php _e('Galleries', 'wp-magnific-popup') ?></a></li>
     90                        <li><a href="#wpmp_iframe"><?php _e('Iframes', 'wp-magnific-popup') ?></a></li>
     91                        <li><a href="#wpmp_dialog"><?php _e('Dialogs', 'wp-magnific-popup')?></a></li>
     92                    </ul>
     93                    <div id="wpmp_images">
     94                        <table class="form-table ps-form-table">
     95                            <tr>
     96                                <th><?php _e('CSS class for images', 'wp-magnific-popup') ?>:</th>
     97                                <td><input type="text" name="wpmp_image_settings[class]" value="<?=$this->get_wpmp_option('image', 'class')?>" /></td>
     98                            </tr>
     99                            <tr>
     100                                <th><?php _e('Vertical Fit', 'wp-magnific-popup') ?>:</th>
     101                                <td><input type="checkbox" name="wpmp_image_settings[vertical_fit]" value="1" <?php if ($this->get_wpmp_option('image', 'vertical_fit') == 1) echo 'checked="checked"';?> /></td>
     102                            </tr>
     103                            <tr>
     104                                <th><?php _e('Enable Zoom Animation', 'wp-magnific-popup') ?>:</th>
     105                                <td><input type="checkbox" name="wpmp_image_settings[zoom_enabled]" value="1" <?php if ($this->get_wpmp_option('image', 'zoom_enabled') == 1) echo 'checked="checked"';?> /></td>
     106                            </tr>
     107                        </table>
     108                    </div>
     109                    <div id="wpmp_galleries">
     110                        <table class="form-table ps-form-table">
     111                            <tr>
     112                                <th><?php _e('CSS class for galleries', 'wp-magnific-popup') ?>:</th>
     113                                <td><input type="text" name="wpmp_gallery_settings[class]" value="<?=$this->get_wpmp_option('gallery', 'class')?>" /></td>
     114                            </tr>
     115                        </table>
     116                    </div>
     117                    <div id="wpmp_iframe">
     118                        <table class="form-table ps-form-table">
     119                            <tr>
     120                                <th><?php _e('CSS class for iframes', 'wp-magnific-popup') ?>:</th>
     121                                <td><input type="text" name="wpmp_iframe_settings[class]" value="<?=$this->get_wpmp_option('iframe', 'class')?>" /></td>
     122                            </tr>
     123                        </table>
     124                    </div>
     125                    <div id="wpmp_dialog">
     126                        <table class="form-table ps-form-table">
     127                            <tr>
     128                                <th><?php _e('CSS class for dialogs', 'wp-magnific-popup') ?>:</th>
     129                                <td><input type="text" name="wpmp_div_settings[class]" value="<?=$this->get_wpmp_option('div', 'class')?>" /></td>
     130                            </tr>
     131                        </table>
     132                    </div>
     133                </div>
     134
    103135                <p class="submit">
    104136                    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
     
    109141    }
    110142
     143    function get_wpmp_option($section, $option)
     144    {
     145        $arr = get_option('wpmp_'.$section.'_settings');
     146
     147        if ($arr)
     148        {
     149            if (isset($arr[$option]))
     150                return $arr[$option];
     151        }
     152        return '';
     153    }
     154
    111155    function register_settings()
    112156    {
    113         register_setting( 'wp-magnific-popup-settings-group', 'wpmp_gallery_class' );
    114         register_setting( 'wp-magnific-popup-settings-group', 'wpmp_image_class' );
    115         register_setting( 'wp-magnific-popup-settings-group', 'wpmp_image_vertical_fit' );
    116         register_setting( 'wp-magnific-popup-settings-group', 'wpmp_image_zoom_enabled' );
    117         register_setting( 'wp-magnific-popup-settings-group', 'wpmp_iframe_class' );
    118         register_setting( 'wp-magnific-popup-settings-group', 'wpmp_div_class' );
     157        register_setting( 'wp-magnific-popup-settings-group', 'wpmp_image_settings' );
     158        register_setting( 'wp-magnific-popup-settings-group', 'wpmp_gallery_settings' );
     159        register_setting( 'wp-magnific-popup-settings-group', 'wpmp_iframe_settings' );
     160        register_setting( 'wp-magnific-popup-settings-group', 'wpmp_div_settings' );
    119161    }
    120162
     
    126168function install_wp_magnific_popup()
    127169{
    128     if (!get_option('wpmp_image_class'))
    129         update_option('wpmp_image_class', 'mpopup');
    130     if (!get_option('wpmp_iframe_class'))
    131         update_option('wpmp_iframe_class', 'mpopup_iframe');
    132     if (!get_option('wpmp_div_class'))
    133         update_option('wpmp_div_class', 'mpopup_div');
    134     if (!get_option('wpmp_gallery_class'))
    135         update_option('wpmp_gallery_class', 'popup-gallery');
     170    if (!get_option('wpmp_image_settings'))
     171        update_option('wpmp_image_settings', array(
     172            'class' => 'mpopup',
     173            'vertical_fit' => 1,
     174            'zoom_enabled' => 0
     175        ));
     176
     177    if (!get_option('wpmp_gallery_settings'))
     178        update_option('wpmp_gallery_settings', array(
     179            'class' => 'popup-gallery'
     180        ));
     181
     182    if (!get_option('wpmp_iframe_settings'))
     183        update_option('wpmp_iframe_settings', array(
     184            'class' => 'mpopup_iframe'
     185        ));
     186
     187    if (!get_option('wpmp_div_settings'))
     188        update_option('wpmp_div_settings', array(
     189            'class' => 'mpopup_div'
     190        ));
    136191}
Note: See TracChangeset for help on using the changeset viewer.