Plugin Directory

Changeset 516773


Ignore:
Timestamp:
03/09/2012 02:41:56 PM (14 years ago)
Author:
VoxPelli
Message:

Now loading the script async and not loading it in the frontend when non-dynamic buttons are used

File:
1 edited

Legend:

Unmodified
Added
Removed
  • flattr/trunk/flattr.php

    r516756 r516773  
    6060     */
    6161    protected function frontend() {
    62         add_action('wp_enqueue_scripts', array($this, 'insert_script'));
     62        if (!in_array(get_option('flattr_button_style'), array('text', 'image'))) {
     63            add_action('wp_print_footer_scripts', array($this, 'insert_script'));
     64        }
    6365
    6466        if (get_option('flattr_aut') || get_option('flattr_aut_page')) {
     
    8183     */
    8284    protected function backend() {
     85        add_action('wp_print_footer_scripts', array($this, 'insert_script'));
    8386        add_action('admin_init', array($this, 'ajax'));
    84         add_action('admin_init', array($this, 'insert_script'));
    8587        add_action('admin_init', array($this, 'insert_wizard'));
    8688        add_action('admin_init', array( $this, 'register_settings') );
     
    291293    }
    292294
    293     /**
    294      * Insert Flattr script between <head></head> tags using Wordpress script hooks
    295      * @see http://codex.wordpress.org/Function_Reference/wp_enqueue_script
    296      */
    297295    public function insert_script() {
    298         wp_deregister_script( 'flattrscript' );
    299         wp_register_script( 'flattrscript', $this->proto . self::API_SCRIPT);
    300         wp_enqueue_script( 'flattrscript' );
     296        ?><script type="text/javascript">
     297          (function() {
     298            var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
     299            s.type = 'text/javascript';
     300            s.async = true;
     301            s.src = '<?php echo $this->proto . self::API_SCRIPT; ?>';
     302            t.parentNode.insertBefore(s, t);
     303          })();
     304        </script><?php
    301305    }
    302306   
Note: See TracChangeset for help on using the changeset viewer.