Plugin Directory

Changeset 755142


Ignore:
Timestamp:
08/12/2013 03:23:58 PM (13 years ago)
Author:
shockware
Message:

Print datepicker javascript to wp_footer #58

Location:
contact-form-7-datepicker/trunk
Files:
2 edited

Legend:

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

    r695340 r755142  
    22
    33class ContactForm7Datepicker_Date {
     4
     5    static $inline_js = array();
    46
    57    public static function register() {
     
    2628        // Messages
    2729        add_filter('wpcf7_messages', array(__CLASS__, 'messages'));
     30
     31        // Print inline javascript
     32        add_action('wp_print_footer_scripts', array(__CLASS__, 'print_inline_js'), 99999);
    2833    }
    2934
     
    140145        $dp = new CF7_DatePicker($dp_selector, $dpOptions);
    141146
    142         return sprintf('<span class="wpcf7-form-control-wrap %s">%s %s</span>%s',
     147        self::$inline_js[] = $dp->generate_code($inline);
     148
     149        return sprintf('<span class="wpcf7-form-control-wrap %s">%s %s</span>',
    143150            esc_attr($name),
    144151            $input,
    145             $validation_error,
    146             $dp->generate_code($inline)
     152            $validation_error
    147153        );
    148154    }
     
    195201    }
    196202
     203    public static function print_inline_js() {
     204        if (! wp_script_is('jquery-ui-datepicker', 'done') || empty(self::$inline_js))
     205            return;
     206
     207        $out = implode("\n\t", self::$inline_js);
     208        $out = "jQuery(function($){\n\t$out\n});";
     209
     210        echo "\n<script type=\"text/javascript\">\n{$out}\n</script>\n";
     211    }
     212
    197213    private static function animate_dropdown() {
    198214        $html = "<select id=\"animate\">\n";
  • contact-form-7-datepicker/trunk/datepicker.php

    r694544 r755142  
    138138
    139139        // Remove watermark class onSelect
    140         $out .= ".datepicker('option', 'onSelect', function(){ $(this).removeClass('watermark').trigger('change'); });\n";
     140        if (! $inline)
     141            $out .= ".datepicker('option', 'onSelect', function(){ $(this).removeClass('watermark').trigger('change'); })";
    141142
    142         $out = "jQuery(function($){ $out });";
     143        $out .= ".datepicker('refresh');";
    143144
    144         return "\n<script type=\"text/javascript\">{$out}</script>\n";
     145        return $out;
    145146    }
    146147
Note: See TracChangeset for help on using the changeset viewer.