Plugin Directory

Changeset 694544


Ignore:
Timestamp:
04/09/2013 02:17:25 PM (13 years ago)
Author:
shockware
Message:

Merge branch 'master' into HEAD

Location:
contact-form-7-datepicker/trunk
Files:
15 added
5 edited

Legend:

Unmodified
Added
Removed
  • contact-form-7-datepicker/trunk/admin.php

    r633957 r694544  
    33class ContactForm7Datepicker_Admin {
    44
    5     public static function init() {
    6         add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_assets'));
    7         add_action('wpcf7_admin_after_general_settings', array(__CLASS__, 'add_meta_box'));
    8         add_action('admin_footer', array(__CLASS__, 'theme_js'));
    9         add_action('wp_ajax_cf7dp_save_settings', array(__CLASS__, 'ajax_save_settings'));
     5    function __construct() {
     6        add_action('admin_enqueue_scripts', array($this, 'enqueue_assets'));
     7        add_action('wpcf7_admin_after_general_settings', array($this, 'add_meta_box'));
     8        add_action('admin_footer', array($this, 'theme_js'));
     9        add_action('wp_ajax_cf7dp_save_settings', array($this, 'ajax_save_settings'));
    1010    }
    1111
    12     public static function enqueue_assets() {
     12    function enqueue_assets() {
    1313        if (is_admin() && ! self::is_wpcf7_page())
    1414            return;
     15
     16        wp_enqueue_script('jquery-ui-datepicker');
    1517
    1618        ContactForm7Datepicker::enqueue_js();
     
    1820    }
    1921
    20     public static function add_meta_box() {
     22    function add_meta_box() {
    2123        if (! current_user_can('publish_pages'))
    2224            return;
     
    3436    }
    3537
    36     public static function theme_metabox() {
     38    function theme_metabox() {
    3739        ?>
    3840
     
    5052    }
    5153
    52     public static function theme_js() {
     54    function theme_js() {
    5355        if (! self::is_wpcf7_page())
    5456            return;
    5557    ?>
    56     <script type="text/javascript">
    57     jQuery(function($){
    58         var $spinner = $(new Image()).attr('src', '<?php echo admin_url('images/wpspin_light.gif'); ?>');
    59         var old_href = '';
     58        <script type="text/javascript">
     59        jQuery(function($){
     60            var $spinner = $(new Image()).attr('src', '<?php echo admin_url('images/wpspin_light.gif'); ?>');
     61            var old_href = '';
    6062
    61         $('#jquery-ui-theme').change(function(){
    62             var style = $(this).val();
     63            $('#jquery-ui-theme').change(function(){
     64                var style = $(this).val();
    6365
    64             var $link = $('#jquery-ui-theme-css');
    65             var href = $link.attr('href');
     66                var $link = $('#jquery-ui-theme-css');
     67                var href = $link.attr('href');
    6668
    67             if (style == 'disabled') {
    68                 old_href = href;
    69                 $link.attr('href', '');
     69                if (style == 'disabled') {
     70                    old_href = href;
     71                    $link.attr('href', '');
    7072
    71                 return;
    72             } else if (href === '') {
    73                 href = old_href;
    74             }
     73                    return;
     74                } else if (href === '') {
     75                    href = old_href;
     76                }
    7577
    76             href = href.replace(/\/themes\/[-a-z]+\//g, '/themes/' + style + '/');
    77             $link.attr('href', href);
    78         });
    79 
    80         $('#save-ui-theme').click(function(){
    81             var data = {
    82                 action: 'cf7dp_save_settings',
    83                 ui_theme: $('#jquery-ui-theme').val()
    84             };
    85 
    86             var $this_spinner = $spinner.clone();
    87 
    88             $(this).after($this_spinner.show());
    89 
    90             $.post(ajaxurl, data, function(response) {
    91                 var $prev = $( '.wrap > .updated, .wrap > .error' );
    92                 var $msg = $(response).hide().insertAfter($('.wrap h2'));
    93                 if ($prev.length > 0)
    94                     $prev.fadeOut('slow', function(){
    95                         $msg.fadeIn('slow');
    96                     });
    97                 else
    98                     $msg.fadeIn('slow');
    99 
    100                 $this_spinner.hide();
     78                href = href.replace(/\/themes\/[-a-z]+\//g, '/themes/' + style + '/');
     79                $link.attr('href', href);
    10180            });
    10281
    103             return false;
     82            $('#save-ui-theme').click(function(){
     83                var data = {
     84                    action: 'cf7dp_save_settings',
     85                    ui_theme: $('#jquery-ui-theme').val()
     86                };
     87
     88                var $this_spinner = $spinner.clone();
     89
     90                $(this).after($this_spinner.show());
     91
     92                $.post(ajaxurl, data, function(response) {
     93                    var $prev = $( '.wrap > .updated, .wrap > .error' );
     94                    var $msg = $(response).hide().insertAfter($('.wrap h2'));
     95                    if ($prev.length > 0)
     96                        $prev.fadeOut('slow', function(){
     97                            $msg.fadeIn('slow');
     98                        });
     99                    else
     100                        $msg.fadeIn('slow');
     101
     102                    $this_spinner.hide();
     103                });
     104
     105                return false;
     106            });
    104107        });
    105     });
    106     </script>
     108        </script>
    107109    <?php
    108110    }
    109111
    110     public static function ajax_save_settings() {
     112    function ajax_save_settings() {
    111113        $successmsg = '<div id="message" class="updated fade"><p><strong>' . __('Options saved.') . '</strong></p></div>';
    112114        $errormsg = '<div id="message" class="error fade"><p><strong>' . __('Options could not be saved.') . '</strong></p></div>';
     
    123125            die($errormsg);
    124126
    125         if (! update_option('cf7dp_ui_theme', $theme))
    126             die($errormsg);
     127        if (get_option('cf7dp_ui_theme') !== $theme)
     128            if (! update_option('cf7dp_ui_theme', $theme))
     129                die($errormsg);
    127130
    128131        die($successmsg);
     
    181184    }
    182185}
     186
     187new ContactForm7Datepicker_Admin;
  • contact-form-7-datepicker/trunk/contact-form-7-datepicker.php

    r662953 r694544  
    55Description: Easily add a date field using jQuery UI's datepicker to your CF7 forms. This plugin depends on Contact Form 7.
    66Author: Aurel Canciu
    7 Version: 2.2.1
     7Version: 2.3
    88Author URI: https://github.com/relu/
    99*/
     
    2929class ContactForm7Datepicker {
    3030
    31     public static function init() {
    32         add_action('plugins_loaded', array(__CLASS__, 'load_date_module'), 10);
     31    const JQUERYUI_VERSION = '1.9.2';
    3332
    34         add_action('wpcf7_enqueue_scripts', array(__CLASS__, 'enqueue_js'));
    35         add_action('wpcf7_enqueue_styles', array(__CLASS__, 'enqueue_css'));
     33    function __construct() {
     34        add_action('plugins_loaded', array($this, 'load_date_module'), 10);
    3635
    37         register_activation_hook(__FILE__, array(__CLASS__, 'activate'));
     36        add_action('wpcf7_enqueue_scripts', array($this, 'enqueue_js'));
     37        add_action('wpcf7_enqueue_styles', array($this, 'enqueue_css'));
     38
     39        register_activation_hook(__FILE__, array($this, 'activate'));
    3840
    3941        if (is_admin()) {
    4042            require_once dirname(__FILE__) . '/admin.php';
    41             ContactForm7Datepicker_Admin::init();
    4243        }
    4344    }
    4445
    45     public static function load_date_module() {
     46    function load_date_module() {
    4647        require_once dirname(__FILE__) . '/date-module.php';
    4748        ContactForm7Datepicker_Date::register();
    4849    }
    4950
    50     public static function activate() {
     51    function activate() {
    5152        if (! get_option('cf7dp_ui_theme'))
    5253            add_option('cf7dp_ui_theme', 'base');
    5354    }
    5455
    55     public static function enqueue_js() {
    56         wp_enqueue_script('jquery-ui-datepicker', null, null, null, true);
     56    function enqueue_js() {
     57        $regional = CF7_DatePicker::get_regional_match();
     58        $proto = is_ssl() ? 'https' : 'http';
    5759
    58         $regional = CF7_DatePicker::get_regional_match();
     60        if (! empty($regional)) {
     61            wp_enqueue_script(
     62                'jquery-ui-' . $regional,
     63                $proto . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::JQUERYUI_VERSION . '/i18n/jquery.ui.datepicker-' . $regional . '.min.js',
     64                array('jquery-ui-datepicker'),
     65                self::JQUERYUI_VERSION,
     66                true
     67            );
     68        }
    5969
    60         if (! $regional)
    61             return;
     70        wp_enqueue_script('jquery-ui-datepicker');
    6271
    63         wp_enqueue_script(
    64             'jquery-ui-' . $regional,
    65             'http://ajax.googleapis.com/ajax/libs/jqueryui/1/i18n/jquery.ui.datepicker-' . $regional . '.min.js',
     72        wp_register_script(
     73            'jquery-ui-effect-core',
     74            plugins_url('js/jquery.ui.effect.min.js', __FILE__),
    6675            array('jquery-ui-datepicker'),
    67             null,
     76            self::JQUERYUI_VERSION,
    6877            true
    6978        );
     79
     80        foreach (CF7_DatePicker::$effects as $effect) {
     81            wp_register_script(
     82                'jquery-ui-effect-' . $effect,
     83                plugins_url('js/jquery.ui.effect-' . $effect . '.min.js', __FILE__),
     84                array('jquery-ui-effect-core'),
     85                self::JQUERYUI_VERSION,
     86                true
     87            );
     88        }
    7089    }
    7190
    72     public static function enqueue_css() {
     91    function enqueue_css() {
    7392        $theme = get_option('cf7dp_ui_theme');
    7493
     
    7695            return;
    7796
    78         wp_enqueue_style('jquery-ui-theme', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/' . $theme . '/jquery-ui.css', array(), '');
     97        $proto = is_ssl() ? 'https' : 'http';
     98
     99        wp_enqueue_style(
     100            'jquery-ui-theme',
     101            $proto . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::JQUERYUI_VERSION . '/themes/' . $theme . '/jquery-ui.css',
     102            '',
     103            self::JQUERYUI_VERSION,
     104            'all'
     105        );
    79106    }
    80107}
    81108
    82 ContactForm7Datepicker::init();
     109new ContactForm7Datepicker;
  • contact-form-7-datepicker/trunk/date-module.php

    r645880 r694544  
    55    public static function register() {
    66        require_once dirname(__FILE__) . '/datepicker.php';
     7
     8        // Remove Contact Form 7's date module
     9        remove_action('init', 'wpcf7_add_shortcode_date', 5);
     10        remove_filter('wpcf7_validate_date', 'wpcf7_date_validation_filter', 10);
     11        remove_filter('wpcf7_validate_date*', 'wpcf7_date_validation_filter', 10);
     12        remove_filter('wpcf7_messages', 'wpcf7_date_messages');
    713
    814        // Register shortcodes
     
    7177            } elseif (preg_match('%^change-year$%i', $option, $matches)) {
    7278                $dpOptions['changeYear'] = true;
    73             } elseif (preg_match('%^year-range:(\d+)-?(\d+)?$%', $option, $matches)) {
    74                 $dpOptions['yearRange'] = $matches[1] . ':' . @$matches[2];
     79            } elseif (preg_match('%^year-range:([-+\d]+)[:-]?([-+\d]+)?$%', $option, $matches)) {
     80                $dpOptions['yearRange'] = $matches[1];
    7581            } elseif (preg_match('%^months:(\d+)$%', $option, $matches)) {
    7682                $dpOptions['numberOfMonths'] = (int) $matches[1];
     
    190196
    191197    private static function animate_dropdown() {
    192         $effects = array(
    193             'show' => __('Show'),
    194             'blind' => __('Blind'),
    195             'clip' => __('Clip'),
    196             'drop' => __('Drop'),
    197             'explode' => __('Explode'),
    198             'fade' => __('Fade'),
    199             'fold' => __('Fold'),
    200             'puff' => __('Puff'),
    201             'slide' => __('Slide'),
    202             'scale' => __('Scale')
    203         );
    204 
    205         $effects = apply_filters('cf7dp_effects', $effects);
    206 
    207198        $html = "<select id=\"animate\">\n";
    208         foreach ($effects as $key => $val) {
    209             $html .= "\t<option value=\"{$key}\">{$val}</option>\n";
     199
     200        foreach (CF7_DatePicker::$effects as $val) {
     201            $html .= '<option value="' . esc_attr($val) . '">' . ucfirst($val) . '</option>';
    210202        }
    211203
  • contact-form-7-datepicker/trunk/datepicker.php

    r662953 r694544  
    22
    33class CF7_DatePicker {
     4
    45    private $input_name;
    56
     
    1819    );
    1920
    20     protected static $regionals = array(
    21         'af' =>'Afrikaans',
    22         'sq' =>'Albanian',
    23         'ar-DZ' =>'Algerian Arabic',
    24         'ar' =>'Arabic',
    25         'hy' =>'Armenian',
    26         'az' =>'Azerbaijani',
    27         'eu' =>'Basque',
    28         'bs' =>'Bosnian',
    29         'bg' =>'Bulgarian',
    30         'ca' =>'Catalan',
    31         'zh-HK' =>'Chinese Hong Kong',
    32         'zh-CN' =>'Chinese Simplified',
    33         'zh-TW' =>'Chinese Traditional',
    34         'hr' =>'Croatian',
    35         'cs' =>'Czech',
    36         'da' =>'Danish',
    37         'nl-BE' =>'Dutch',
    38         'nl' =>'Dutch',
    39         'en-AU' =>'English/Australia',
    40         'en-NZ' =>'English/New Zealand',
    41         'en-GB' =>'English/UK',
    42         'eo' =>'Esperanto',
    43         'et' =>'Estonian',
    44         'fo' =>'Faroese',
    45         'fa' =>'Farsi/Persian',
    46         'fi' =>'Finnish',
    47         'fr' =>'French',
    48         'fr-CH' =>'French/Swiss',
    49         'gl' =>'Galician',
    50         'de' =>'German',
    51         'el' =>'Greek',
    52         'he' =>'Hebrew',
    53         'hu' =>'Hungarian',
    54         'is' =>'Icelandic',
    55         'id' =>'Indonesian',
    56         'it' =>'Italian',
    57         'ja' =>'Japanese',
    58         'kk' =>'Kazakhstan',
    59         'ko' =>'Korean',
    60         'lv' =>'Latvian',
    61         'lt' =>'Lithuanian',
    62         'lb' =>'Luxembourgish',
    63         'mk' =>'Macedonian',
    64         'ml' =>'Malayalam',
    65         'ms' =>'Malaysian',
    66         'no' =>'Norwegian',
    67         'pl' =>'Polish',
    68         'pt' =>'Portuguese',
    69         'pt-BR' =>'Portuguese/Brazilian',
    70         'rm' =>'Rhaeto-Romanic',
    71         'ro' =>'Romanian',
    72         'ru' =>'Russian',
    73         'sr' =>'Serbian',
    74         'sr-SR' =>'Serbian',
    75         'sk' =>'Slovak',
    76         'sl' =>'Slovenian',
    77         'es' =>'Spanish',
    78         'sv' =>'Swedish',
    79         'ta' =>'Tamil',
    80         'th' =>'Thai',
    81         'tj' =>'Tajikistan',
    82         'tr' =>'Turkish',
    83         'uk' =>'Ukranian',
    84         'vi' =>'Vietnamese',
    85         'cy-GB' =>'Welsh/UK',
     21    private static $regionals = array(
     22        'af' => 'Afrikaans',
     23        'sq' => 'Albanian',
     24        'ar-DZ' => 'Algerian Arabic',
     25        'ar' => 'Arabic',
     26        'hy' => 'Armenian',
     27        'az' => 'Azerbaijani',
     28        'eu' => 'Basque',
     29        'bs' => 'Bosnian',
     30        'bg' => 'Bulgarian',
     31        'ca' => 'Catalan',
     32        'zh-HK' => 'Chinese Hong Kong',
     33        'zh-CN' => 'Chinese Simplified',
     34        'zh-TW' => 'Chinese Traditional',
     35        'hr' => 'Croatian',
     36        'cs' => 'Czech',
     37        'da' => 'Danish',
     38        'nl-BE' => 'Dutch',
     39        'nl' => 'Dutch',
     40        'en-AU' => 'English/Australia',
     41        'en-NZ' => 'English/New Zealand',
     42        'en-GB' => 'English/UK',
     43        'eo' => 'Esperanto',
     44        'et' => 'Estonian',
     45        'fo' => 'Faroese',
     46        'fa' => 'Farsi/Persian',
     47        'fi' => 'Finnish',
     48        'fr' => 'French',
     49        'fr-CH' => 'French/Swiss',
     50        'gl' => 'Galician',
     51        'de' => 'German',
     52        'el' => 'Greek',
     53        'he' => 'Hebrew',
     54        'hu' => 'Hungarian',
     55        'is' => 'Icelandic',
     56        'id' => 'Indonesian',
     57        'it' => 'Italian',
     58        'ja' => 'Japanese',
     59        'kk' => 'Kazakhstan',
     60        'ko' => 'Korean',
     61        'lv' => 'Latvian',
     62        'lt' => 'Lithuanian',
     63        'lb' => 'Luxembourgish',
     64        'mk' => 'Macedonian',
     65        'ml' => 'Malayalam',
     66        'ms' => 'Malaysian',
     67        'no' => 'Norwegian',
     68        'pl' => 'Polish',
     69        'pt' => 'Portuguese',
     70        'pt-BR' => 'Portuguese/Brazilian',
     71        'rm' => 'Rhaeto-Romanic',
     72        'ro' => 'Romanian',
     73        'ru' => 'Russian',
     74        'sr' => 'Serbian',
     75        'sr-SR' => 'Serbian',
     76        'sk' => 'Slovak',
     77        'sl' => 'Slovenian',
     78        'es' => 'Spanish',
     79        'sv' => 'Swedish',
     80        'ta' => 'Tamil',
     81        'th' => 'Thai',
     82        'tj' => 'Tajikistan',
     83        'tr' => 'Turkish',
     84        'uk' => 'Ukranian',
     85        'vi' => 'Vietnamese',
     86        'cy-GB' => 'Welsh/UK',
     87    );
     88
     89    public static $effects = array(
     90        'show',
     91        'blind',
     92        'clip',
     93        'drop',
     94        'explode',
     95        'fade',
     96        'fold',
     97        'highlight',
     98        'puff',
     99        'pulsate',
     100        'slide',
     101        'scale',
     102        'shake',
     103        'transfer',
    86104    );
    87105
     
    93111        $this->options = wp_parse_args((array)$options, $this->options);
    94112        $this->options = apply_filters('cf7_datepicker_options', $this->options);
     113
     114        if ('' !== $this->showAnim) {
     115            add_action('wp_footer', array($this, 'enqueue_effect'));
     116        }
    95117    }
    96118
     
    116138
    117139        // Remove watermark class onSelect
    118         $out .= ".datepicker('option', 'onSelect', function(){ $(this).removeClass('watermark'); });\n";
     140        $out .= ".datepicker('option', 'onSelect', function(){ $(this).removeClass('watermark').trigger('change'); });\n";
    119141
    120142        $out = "jQuery(function($){ $out });";
     
    161183        return null;
    162184    }
     185
     186    public function enqueue_effect() {
     187        wp_enqueue_script('jquery-ui-effect-' . $this->showAnim);
     188    }
     189
    163190}
  • contact-form-7-datepicker/trunk/readme.txt

    r662953 r694544  
    33Tags: wordpress, datepicker, calendar, contact form 7, forms, jqueryui
    44Requires at least: 2.9
    5 Tested up to: 3.5
    6 Stable tag: 2.2.1
     5Tested up to: 3.5.1
     6Stable tag: 2.3
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3434
    3535== Changelog ==
     36
     37= 2.3 =
     38* Made it work with CF7 3.4
     39* Use full jquery-ui version on asset paths
     40* Add Date Range feature (thanks @dollardad)
    3641
    3742= 2.2.1 =
Note: See TracChangeset for help on using the changeset viewer.