Plugin Directory

Changeset 1017981


Ignore:
Timestamp:
11/01/2014 06:33:35 PM (11 years ago)
Author:
blocknot.es
Message:

Settings screen, Javascript editor, polymer-element tag

Location:
polymer-components
Files:
7 added
6 edited

Legend:

Unmodified
Added
Removed
  • polymer-components/trunk/polymer-admin.js

    r1015780 r1017981  
    11/**
    2  * Plugin Name: Polymer
     2 * Plugin Name: Polymer Components
    33 * Author: Mattia Roccoberton
    44 * Author URI: http://blocknot.es
     
    99    document.getElementById( 'docs_' + group ).href = url + '#' + document.getElementById( 'sel_' + group ).value;
    1010}
     11
     12window.onload = function() {
     13    var poly_javascript = document.getElementById( 'poly_javascript' );
     14    if( poly_javascript != null )
     15    {
     16        CodeMirror.fromTextArea( poly_javascript, {
     17            dragDrop: false,
     18            indentWithTabs: true,
     19            lineNumbers: true,
     20            smartIndent: false
     21        });
     22    }
     23};
  • polymer-components/trunk/polymer-admin.php

    r1017008 r1017981  
    11<?php
     2if ( !defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
     3
     4define( 'PLUGIN_MAIN', 'polymer-components/polymer-components.php' );
     5
    26class polymer_admin
    37{
     8    private $options;
     9
    410    function __construct()
    511    {
     
    713        add_action( 'add_meta_boxes', array( &$this, 'add_meta_boxes' ) );
    814        add_action( 'admin_init', array( &$this, 'admin_init' ) );
     15        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
    916        add_action( 'save_post', array( &$this, 'save_post' ) );
     17    // --- Filters ---
     18        add_filter( 'plugin_action_links_' . PLUGIN_MAIN, array( &$this, 'plugin_action_links' ), 10, 1 );
    1019    }
    1120
     
    1726
    1827    function admin_init()
     28    {   // action
     29        $this->options = get_option( 'polymer-options' );
     30        wp_enqueue_style( 'poly-admin-style', plugin_dir_url( __FILE__ ) . 'polymer-admin.css' );
     31        wp_enqueue_style( 'poly-admin-codemirror-style', plugin_dir_url( __FILE__ ) . 'codemirror/codemirror.css' );
     32        wp_register_script( 'poly-admin-scripts', plugin_dir_url( __FILE__ ) . 'polymer-admin.js', array() );
     33        wp_register_script( 'poly-admin-codemirror', plugin_dir_url( __FILE__ ) . 'codemirror/codemirror.min.js', array() );
     34        wp_register_script( 'poly-admin-codemirror-js', plugin_dir_url( __FILE__ ) . 'codemirror/javascript.js', array() );
     35        wp_enqueue_script( 'poly-admin-scripts' );
     36        wp_enqueue_script( 'poly-admin-codemirror' );
     37        wp_enqueue_script( 'poly-admin-codemirror-js' );
     38    // Settings
     39        register_setting(
     40            'polymer-settings-general',
     41            'polymer-options'
     42            //, array( $this, 'sanitize' ) // Sanitize
     43        );
     44        add_settings_section(
     45            'polymer-section-general', // ID
     46            'General settings', // Title
     47            array( $this, 'print_section_info' ), // Callback
     48            'polymer-settings' // Page
     49        );
     50        add_settings_field(
     51            'polymer-js-posts', // ID
     52            'JS in posts', // Title
     53            array( $this, 'field_js_posts' ), // Callback
     54            'polymer-settings', // Page
     55            'polymer-section-general' // Section           
     56        );
     57        add_settings_field(
     58            'polymer-js-pages', // ID
     59            'JS in pages', // Title
     60            array( $this, 'field_js_pages' ), // Callback
     61            'polymer-settings', // Page
     62            'polymer-section-general' // Section           
     63        );
     64    }
     65
     66    function admin_menu()
     67    {   // action
     68        add_options_page(
     69            'Settings Admin',
     70            'Polymer settings',
     71            'manage_options',
     72            'polymer-settings',
     73            array( $this, 'create_admin_page' )
     74        );
     75    }
     76
     77    function create_admin_page()
     78    {   // callback
     79?>
     80    <div id="polymer-settings" class="wrap">
     81        <?php screen_icon(); ?>
     82        <h2>Polymer settings</h2>
     83        <form method="post" action="options.php">
     84        <?php
     85            settings_fields( 'polymer-settings-general' );
     86            do_settings_sections( 'polymer-settings' );
     87            submit_button();
     88        ?>
     89        </form>
     90    </div>
     91<?php
     92    }
     93
     94    function field_js_pages()
    1995    {
    20         wp_register_script( 'poly-admin-scripts', plugin_dir_url( __FILE__ ) . 'polymer-admin.js', array() );
    21         wp_enqueue_script( 'poly-admin-scripts' );
     96        if( $this->options !== FALSE )
     97        {
     98            $checked = isset( $this->options['polymer-js-pages'] ) && !empty( $this->options['polymer-js-pages'] );
     99        }
     100        else $checked = TRUE;
     101        echo '<input type="checkbox" id="polymer-js-pages" name="polymer-options[polymer-js-pages]"', $checked ? ' checked="checked"' : '', '/> <label for="polymer-js-pages">', __('Javascript editor in pages'), '</label>';
     102    }
     103
     104    function field_js_posts()
     105    {
     106        if( $this->options !== FALSE )
     107        {
     108            $checked = isset( $this->options['polymer-js-posts'] ) && !empty( $this->options['polymer-js-posts'] );
     109        }
     110        else $checked = TRUE;
     111        echo '<input type="checkbox" id="polymer-js-posts" name="polymer-options[polymer-js-posts]"', $checked ? ' checked="checked"' : '', '/> <label for="polymer-js-posts">', __('Javascript editor in posts'), '</label>';
     112    }
     113
     114    function plugin_action_links( $links )
     115    {
     116        array_unshift( $links, '<a href="' . admin_url( 'options-general.php?page=polymer-settings' ) . '">'. __('Settings') . '</a>' );
     117        return $links;
    22118    }
    23119
     
    47143            if( $group == 'core' ) $url = 'http://www.polymer-project.org/docs/elements/core-elements.html';
    48144            else if( $group == 'paper' ) $url = 'http://www.polymer-project.org/docs/elements/paper-elements.html';
     145            else if( $group == 'polymer' ) continue;
    49146            //echo '<h4 style="margin: 10px 0 5px 0">', $group, ':</h4>';
    50147            echo $sep, '<b>', $group, '</b>:&nbsp; ';
     
    57154        }
    58155        echo "</div>\n";
    59         echo '<div><b>Javascript code</b>:</div>';
    60         $val = get_post_meta( $post->ID, 'poly_javascript', TRUE );
    61         echo '<textarea name="poly_javascript" style="width: 100%" cols="80" rows="6">', stripslashes( $val ), '</textarea>', "\n";
     156        if(      $post->post_type == 'post' ) $poly_javascript = isset( $this->options['polymer-js-posts'] ) && !empty( $this->options['polymer-js-posts'] );
     157        else if( $post->post_type == 'page' ) $poly_javascript = isset( $this->options['polymer-js-pages'] ) && !empty( $this->options['polymer-js-pages'] );
     158        else $poly_javascript = FALSE;
     159        if( $poly_javascript )
     160        {
     161            echo '<div style="border-bottom: 1px solid #aaa; padding-bottom: 5px"><b>Javascript code</b>:</div>';
     162            $val = get_post_meta( $post->ID, 'poly_javascript', TRUE );
     163            echo '<textarea name="poly_javascript" id="poly_javascript" style="width: 100%" cols="80" rows="6">', stripslashes( $val ), '</textarea>', "\n";
     164        }
     165        echo "</div>\n";
    62166    }
     167
     168    public function print_section_info() { }
    63169
    64170    function save_post( $post_id )
     
    88194
    89195        if( isset( $_POST['poly_javascript'] ) && !empty( $_POST['poly_javascript'] ) ) update_post_meta( $post_id, 'poly_javascript', addslashes( $_POST['poly_javascript'] ) );
    90 
    91         //var_dump( $_POST ); exit;
    92         /* if( isset( $_POST['lq_body_padding_top'] ) )
    93         {
    94             $val = intval( $_POST['lq_body_padding_top'] );
    95             if( $val < 0 ) $val = -1;
    96             update_post_meta( $post_id, 'lq_body_padding_top', $val );
    97         } */
    98196    }
    99197}
  • polymer-components/trunk/polymer-components.css

    r1015780 r1017981  
    11/**
    2  * Plugin Name: Polymer
     2 * Plugin Name: Polymer Components
    33 * Author: Mattia Roccoberton
    44 * Author URI: http://blocknot.es
  • polymer-components/trunk/polymer-components.php

    r1017013 r1017981  
    33 * Plugin Name: Polymer Components
    44 * Plugin URI: http://blocknot.es/
    5  * Description: Add Polymer support to your website!
    6  * Version: 1.0.6
     5 * Description: Add Polymer elements to your website!
     6 * Version: 1.1.0
    77 * Author: Mattia Roccoberton
    88 * Author URI: http://blocknot.es
     
    8282        'paper-toast'              => 'paper-toast/paper-toast.html',
    8383        'paper-toggle-button'      => 'paper-toggle-button/paper-toggle-button.html',
     84    // misc
     85        'polymer-element'          => 'polymer/polymer.html',
    8486    );
    8587    var $requirements = array(
     
    102104        'social-icons'        => 'core-icons/social-icons.html',
    103105    );
     106    var $options;
    104107
    105108    function __construct()
    106109    {
     110        $this->options = get_option( 'polymer-options' );
    107111        if( !is_admin() )
    108112        {
  • polymer-components/trunk/polymer-shortcodes.php

    r1015780 r1017981  
    11<?php
     2if ( !defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
     3
    24class polymer_shortcodes
    35{
  • polymer-components/trunk/readme.txt

    r1017020 r1017981  
    55Requires at least: 3.5.0
    66Tested up to: 4.0
    7 Stable tag: 1.0.6
     7Stable tag: 1.1.0
    88License: GPL3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.txt
    1010
    11 Add Polymer components to your website!
     11Add Polymer elements to your website!
    1212Polymer brings an implementation of Google Material Design to the web.
    1313
     
    1616This plugin allows to add Polymer elements in your posts and pages. The same components used in Android Lollypop. You can use the HTML editor with the Polymer tags or the shortcode *[poly]* for all the elements. The correct HTML libraries will be loaded automatically when you use a Polymer tag.
    1717Polymer documentation page: http://www.polymer-project.org/
     18
     19Features:
     20
     21* Polymer tags directly available (core & paper) in posts and pages with the HTML editor;
     22* [poly] shortcode to access to the Polymer tags;
     23* auto import the necessary HTML components;
     24* Javascript editor in posts / pages admin;
     25* documentation links for each tag.
    1826
    1927Shortcode syntax: [poly ELEMENT-TAG ELEMENT-OPTIONS]
     
    2533Examples:
    2634
    27 * [poly core-icon icon="favorite"][/poly]
    28 * [poly paper-checkbox][/poly]
    29 * [poly paper-button raised style="color: green"]A green button[/poly]
    30 * [poly paper-item icon="home" label="Test link"]<a href="http://www.google.it" target="_blank"></a>[/poly]
     35    [poly core-icon icon="favorite"][/poly]
     36    [poly paper-checkbox][/poly]
     37    [poly paper-button raised style="color: green"]A green button[/poly]
     38    [poly paper-item icon="home" label="Test link"]<a href="http://www.google.it" target="_blank"></a>[/poly]
    3139
    3240== Installation ==
    3341
    34 1. Install and activate the plugin
     421. Install the plugin
     431. Activate it
    35441. Edit a post or a page
    36 1. Add one or more Polymer tags (in the HTML editor) or use the shortcode
     451. Use the shortcode to add Polymer elements and/or add directly Polymer tags (in the HTML editor)
    3746
    3847== Frequently Asked Questions ==
     
    4049= How can I interact with the Polymer elements? =
    4150
    42 You can add your Javascript code for your page or post, under the content editor there is a textarea in Polymer components meta box.
     51You can add your Javascript code for your page or post in the Javascript editor under the content editor - Polymer Components meta box.
    4352Sample code to open a dialog from a button click:
    4453
     
    4958    });
    5059
     60= Can I create my elements? =
     61
     62Yes, you can use the *polymer-element* tag in posts and pages included the script block.
     63
    5164== Screenshots ==
    5265
    53 1. Some Polymer components in a post
     661. Some Polymer elements in a post
     672. Polymer Components meta box in post / page editor
     683. A custom element
    5469
    5570== Upgrade Notice ==
    5671
     72= 1.1.0 =
     73* New settings screen
     74* New settings: JS in pages / posts
     75* Improved Javascript editor
     76* Added polymer-element tag
    5777= 1.0.6 =
    5878* Added Javascript textarea to posts and pages
     
    6484== Changelog ==
    6585
     86= 1.1.0 =
     87* New settings screen
     88* New settings: JS in pages / posts
     89* Improved Javascript editor
     90* Added polymer-element tag
    6691= 1.0.6 =
    6792* Added Javascript textarea to posts and pages
Note: See TracChangeset for help on using the changeset viewer.