Plugin Directory

Changeset 690339


Ignore:
Timestamp:
04/01/2013 11:34:37 PM (13 years ago)
Author:
setzer
Message:

Update development version

Location:
side-matter/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • side-matter/trunk/readme.txt

    r689346 r690339  
    1414Side Matter turns your footnotes into sidenotes, magically aligning each note in the sidebar next to its corresponding reference in the text. The plugin's easy-to-use shortcode and widget make it a lightweight, visually elegant tool for annotating your posts and pages.
    1515
    16 Like marginal notes in a printed text, sidebar notes are well-suited to cross-references, citations, digressions, and commentary. The effect is similar to that used for sidenotes by Grantland and other websites.
     16Like marginal notes in a printed text, sidebar notes are well-suited to cross-references, citations, digressions, and commentary. The effect is similar to that used for annotations by Grantland and other websites.
    1717
    18 Side Matter works well with many popular base themes, such as Twenty Twelve, Twenty Ten, Responsive, Pinboard, and Toolbox. It's responsive by default, and includes a set of built-in classes to allow styling sidenotes and references with CSS.
     18Works well with many popular base themes, such as Twenty Twelve, Twenty Ten, Responsive, and Toolbox. The plugin is responsive by default, and includes a set of built-in classes for custom styling using CSS.
    1919
    20 To use, just place the Side Matter widget in your sidebar, then enclose sidenote text in a page or post using the `[ref]` shortcode, like so:
     20To use, place the Side Matter widget in your sidebar, then enclose sidenote text in a page or post using the `[ref]` shortcode, like so:
    2121
    2222> Here's the text to annotate.`[ref]`Sidenote text goes here.`[/ref]`
     
    2424== Installation ==
    2525
    26 1. Upload the directory `side-matter` to `wp-content/plugins`.
     261. Upload the directory `side-matter` to `wp-content/plugins` (or install it from the Plugins menu).
    27272. Activate Side Matter using the Plugins menu.
    28283. Using the Widgets menu, place the Side Matter widget in a sidebar used by your pages and/or posts.
     
    3131> Here's the text to annotate.`[ref]`Sidenote text goes here.`[/ref]`
    3232
    33 Side Matter's default settings may be changed using its options menu, located on your Reading Settings admin page.
     335. To modify Side Matter's default settings, use the options menu, located on your Reading Settings screen.
    3434
    35 The appearance of sidenotes and references can be customized by editing the stylesheet `side-matter/side-matter.css` or copying its contents to your theme's stylesheet and modifying as needed. (The latter option is recommended, as it preserves custom CSS when the plugin is updated.)
     35The styling of sidenotes and references can be customized by editing the stylesheet `side-matter/side-matter.css` or copying its contents to your theme's stylesheet and modifying as needed. (The latter option is recommended, as it preserves custom CSS when the plugin is updated.)
    3636
    3737== Frequently Asked Questions ==
     
    3939= Where is Side Matter's options menu? =
    4040
    41 The options menu can be found on your Reading Settings admin page.
     41The options menu can be found on the Reading Settings screen.
    4242
    43 = Does Side Matter work with responsive layouts? =
     43= Does it work with responsive layouts? =
    4444
    45 Yes. By default, Side Matter will automatically re-position sidenotes to their proper places when the browser window is resized or zoomed. This function can be disabled using Side Matter's options menu on the Reading Settings page. (Disabling responsive sidenotes is a good idea if your theme layout is not responsive; doing so will lighten script load when a user resizes her browser.)
     45Yes. By default, the plugin will automatically re-position sidenotes to their proper places when the browser window is resized or zoomed. This function can be disabled using Side Matter's options menu on the Reading Settings screen. (Disabling responsive sidenotes is a good idea if your theme layout is not responsive; doing so will avoid unnecessary script load on browser resize.)
    4646
    47 = My notes appear in the sidebar, but they're bunched together at the top of the sidebar instead of aligning with their references in the text. =
     47= My notes aren't aligned with their references in the text. =
    4848
    49 Your theme may not be loading `side-matter/side-matter.js`, the script that aligns Side Matter notes. Check the page source to see if `side-matter.js` has been linked; if not, the problem may lie with your theme templates. In order to properly display Side Matter notes, your theme must include calls to [`wp_head()`](http://codex.wordpress.org/Function_Reference/wp_head) and [`wp_footer()`](http://codex.wordpress.org/Function_Reference/wp_footer).
     49Your theme may be failing to load `side-matter/side-matter.js`, the script that aligns Side Matter notes. Check the page source to see if `side-matter.js` has been linked; if not, the problem may lie with your theme templates. In order to properly enqueue the script, a theme must include calls to [`wp_head()`](http://codex.wordpress.org/Function_Reference/wp_head) and [`wp_footer()`](http://codex.wordpress.org/Function_Reference/wp_footer).
    5050
    51 = My notes appear at a consistent vertical offset from their proper position. =
     51= My notes appear at a regular vertical offset from their proper position. =
    5252
    53 For one reason or another, some themes cause Side Matter notes to appear at a regular vertical offset from their corresponding references in the text. Side Matter's options menu includes a field with which you can arbitrarily adjust the vertical offset of your sidenotes.
     53For one reason or another, some themes cause notes to appear at an offset from their corresponding references in the text. Side Matter's options menu (found on the Reading Settings screen) includes a field with which you can arbitrarily adjust your notes' vertical positioning.
    5454
    55 = My notes don't appear in the sidebar. =
     55= Why doesn't the plugin work with some themes? =
    5656
    57 Be sure you've placed the Side Matter widget in the sidebar that appears on the page in question. Also, make sure that your theme's stylesheet is not somehow interfering with the display of your notes.
     57WordPress themes vary widely. Some themes don't include a sidebar; others don't enqueue scripts correctly; still others are laid out in a way that doesn't cooperate with Side Matter.
    5858
    59 If your notes still aren't showing up, Side Matter may be incompatible with your current theme.
    60 
    61 = Why doesn't Side Matter work with some themes? =
    62 
    63 WordPress themes vary widely in their structure, styling, and adherence to community development standards. While Side Matter works well with many popular base themes that feature a sidebar (including Twenty Twelve, Twenty Ten, Responsive, and Toolbox), it isn't guaranteed to display sidenotes properly within all themes. If you have questions about making the plugin work with a particular theme, your best resource may be the theme developer.
     59While the plugin works well with most popular base themes that feature a sidebar (including Twenty Twelve, Twenty Ten, Responsive, and Toolbox), it isn't guaranteed to display notes perfectly within all themes. If you need help getting the plugin to work with a specific theme, your best resource may be the theme developer.
    6460
    6561= How do I modify the appearance of sidenote list numerals without also restyling sidenote text? =
     
    6763The stylesheet `side-matter/side-matter.css` includes instructions for styling sidenote numerals and text separately. In short, styles applied to the `ol.side-matter-list` or `li.side-matter-note` tag classes will affect list numerals; styles applied to the `div.side-matter-text` tag class will affect sidenote text only.
    6864
     65= Is there a way to display Side Matter notes without the widget? =
     66
     67Yes. Use the custom action `side_matter_list_notes` in your sidebar template, like so:
     68
     69    <?php do_action( 'side_matter_list_notes' ); ?>
     70
     71This generates an ordered list of Side Matter notes (without the `div` that encloses the widget).
     72
    6973== Screenshots ==
    7074
    71751. Side Matter captures footnote text using the [ref] shortcode, then automatically positions each footnote alongside its corresponding reference in the text.
    7276
    73 2. Side Matter's default settings can be modified using an options menu on the Reading Settings admin page.
     772. Side Matter's default settings can be modified using an options menu on the Reading Settings screen.
    7478
    7579== Changelog ==
    7680
    7781= 0.8 =
    78 * Added an option to designate the types of pages on which sidenotes appear.
    79 * In-text references now link to sidenotes by way of `li id` instead of `a` tags, which have been removed. This fixes a stubborn layout issue in some themes wherein sidenote text appeared a line below the corresponding numeral.
    80 * Plugin now includes an optional stylesheet, `style.css`, for custom user CSS, which will be preserved on future updates.
    81 * Sidebar widget may now be given a title (e.g. "Notes").
     82* Added an option to display sidenotes on selected page types.
     83* In-text references now link to sidenotes via `li id` in place of `a` anchors. This fixes a layout issue in some themes.
     84* Added a guide for [incorporating custom CSS](http://wordpress.org/extend/plugins/side-matter/other_notes/) to plugin documentation.
     85* Widget panel now links to options menu on Reading Settings screen.
    8286
    8387= 0.7 =
    84 * Added an options menu to the Reading Settings admin page.
     88* Added an options menu to the Reading Settings screen.
    8589* Made various tweaks for security, performance, and cross-browser compatibility.
    8690* Paragraphs within sidenotes are now properly wrapped in `p` tags by WordPress.
     
    104108
    105109= 0.8 =
    106 This update includes bug fixes along with several new features, such as the option to display sidenotes on designated page types. Users who have modified their copy of `side-matter.css` are advised to make a backup copy before updating.
     110This update includes several fixes and new features. Users who have modified their copy of `side-matter.css` are advised to make a backup copy before updating.
    107111
    108112= 0.7 =
     
    115119This update fixes an error that was preventing plugin activation for some users. Recommended.
    116120
    117 == Styling Side Matter with CSS ==
     121== Styling Side Matter with Custom CSS ==
    118122
    119 
     123`div.side-matter-widget`.
    120124
    121125== For Theme Authors ==
  • side-matter/trunk/side-matter.js

    r689346 r690339  
    99*/
    1010
    11 /* isResponsive, useEffects, noteAdjust, noteBuffer, and htmlClass obtain their values from `side-matter.php` */
     11/* These variables obtain their values from the settings fields in `side-matter.php`. */
    1212var isResponsive = side_matter.is_responsive; // If true, reposition notes on resize/zoom (boolean)
    1313var useEffects = side_matter.use_effects; // If true, enable jQuery fade effects when positioning notes (boolean)
    1414var noteAdjust = side_matter.note_adjust; // Distance to arbitrarily offset note position, in px (integer)
    15 var noteBuffer = side_matter.note_buffer; // Minimum note offset; must be equal to or greater than 0, or problems occur (integer)
    1615var htmlClass = side_matter.html_class; // Class to use when selecting Side Matter tags (string; default: 'side-matter')
     16
    1717var isResizing; // Used for resize-timeout function
    1818
     
    2424        var notePosition = jQuery(note).position().top; // Position of sidenote
    2525        var noteOffset = refPosition - notePosition - noteAdjust; // Get current offset from reference to note, minus noteAdjust
    26         var finalOffset = (noteOffset < noteBuffer) ? noteBuffer : noteOffset; // If offset is less than noteBuffer, apply noteBuffer
     26        var finalOffset = (noteOffset < 0) ? 0 : noteOffset; // If offset is negative, set to 0 (prevents layout problems)
    2727        jQuery(note).css('marginTop', finalOffset); // Position note
    2828    }
     
    3030
    3131jQuery(document).ready(function() {
    32     jQuery('ol.' + htmlClass + '-ol').css('opacity', 0);
     32    jQuery('ol.' + htmlClass + '-list').css('opacity', 0); // Make notes briefly transparent to prevent unsightly flickering on load
    3333});
    3434
    35 jQuery(window).load(function() {
    36     for (i = 1; i <= 2; i++) { placeNotes(); } // Loop twice to correct any initial misplacements
    37     if (useEffects == true) {
    38         jQuery('ol.' + htmlClass + '-ol').fadeTo(200, 1);
     35jQuery(window).load(function() { // Position notes and fade in
     36    for (i = 1; i <= 2; i++) { placeNotes(); } // Loop twice to correct any misplacements on first load
     37    if (useEffects == 1) {
     38        jQuery('ol.' + htmlClass + '-list').fadeTo(200, 1);
    3939    } else {
    40         jQuery('ol.' + htmlClass + '-ol').css('opacity', 1);
     40        jQuery('ol.' + htmlClass + '-list').css('opacity', 1);
    4141    }
    4242});
    4343
    44 if (isResponsive == true) {
     44if (isResponsive == 1) {
    4545    jQuery(window).resize(function() { // Reposition notes on resize/zoom
    46         if (useEffects == true) { jQuery('li.' + htmlClass + '-li').fadeTo(20, 0.2); }
     46        if (useEffects == 1) { jQuery('li.' + htmlClass + '-note').fadeTo(20, 0.2); }
    4747        var timeoutInterval = 500; // Time (in ms) to throttle the re-positioning loop, preventing script overload on resize (default: 500)
    4848        function doneResizing() {
    4949            placeNotes();
    50             if (useEffects == true) { jQuery('li.' + htmlClass + '-li').fadeTo(200, 1); }
     50            if (useEffects == 1) { jQuery('li.' + htmlClass + '-note').fadeTo(200, 1); }
    5151        }
    5252        clearTimeout(isResizing);
  • side-matter/trunk/side-matter.php

    r689352 r690339  
    3030$side_matter = new Side_Matter;
    3131
    32 register_uninstall_hook( __FILE__, 'side_matter_uninstall' );
    33 
    34 function side_matter_uninstall() {
    35     delete_option( 'side_matter_options' );
    36 }
    37 
    3832class Side_Matter {
    3933
     
    4337
    4438    public $notes = array(); // Container for Side Matter notes (array)
    45     public $note_id; // Number of current note; used as key in $notes (integer)
    46     public $note_text = ''; // Text of current note; used as value in $notes (string)
     39    public $note_count; // Count of notes; used as key in $notes (integer)
    4740
    4841    public function __construct() { // Construct class and set defaults
    4942
    50         add_action( 'admin_init', array( &$this, 'settings' ) ); // Register settings fields
     43        add_action( 'admin_init', array( &$this, 'settings' ) ); // Register settings section
     44        add_action( 'widgets_init', array( &$this, 'widget' ) ); // Register widget
    5145        add_shortcode( 'ref', array( &$this, 'shortcode' ) ); // Register shortcode
    52         add_action( 'widgets_init', array( &$this, 'widget' ) ); // Register widget
    5346        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue' ) ); // Enqueue script and stylesheet; embed prefs in side-matter.js
    54         add_action( 'side_matter_list_notes', array( &$this, 'list_notes' ), 11, 2 ); // Get HTML list of notes
     47        add_action( 'side_matter_list_notes', array( &$this, 'list_notes' ) ); // Get HTML list of notes
    5548
    5649        $this->defaults = array( // Set option defaults
     
    5851            'use_effects' => 1, // Enable fade effects (boolean; default: 1)
    5952            'note_adjust' => 0, // Arbitrary note offset, in px (integer; default: 0; accepts positive and negative numbers)
    60             'note_buffer' => 0, // Arbitrary note buffer, in px (integer; default: 0; must be 0 or greater, or layout problems occur)
    6153            'html_class' => sanitize_html_class( 'side-matter' ), // Class to use for Side Matter tags (string; default: 'side-matter')
    6254            'pages_active' => array( // Pages on which to display Side Matter notes (array)
     55                'front' => 0, // Default: 0
    6356                'home' => 0, // Default: 0
    64                 'front' => 0, // Default: 0
    6557                'post' => 1, // Default: 1
    6658                'page' => 1 // Default: 1
     
    7062        $this->options = wp_parse_args( get_option( 'side_matter_options' ), $this->defaults ); // Get options from database; apply defaults in place of any that are not set
    7163        $this->version = '0.8'; // Set current version of Side Matter
    72         $this->note_id = 0; // Set number from which to begin note count (integer; default: 0)
    73 
    74     }
    75 
    76     public function widget() { // Register widget
    77         register_widget( 'Side_Matter_Widget' );
    78     }
    79 
    80     public function enqueue() { // Enqueue script and stylesheet; embed settings in side-matter.js
    81         if ( $this->check_page() ) {
    82             wp_enqueue_script( 'side-matter', plugins_url( 'side-matter.js', __FILE__ ), array( 'jquery' ), $this->version, true );
    83             wp_localize_script( 'side-matter', 'side_matter', array( 'is_responsive' => __( $this->options['is_responsive'] ), 'use_effects' => __( $this->options['use_effects'] ), 'note_adjust' => __( $this->options['note_adjust'] ), 'note_buffer' => __( $this->options['note_buffer'] ), 'html_class' => __( $this->options['html_class'] ) ) ); // Use wp_localize_script() to embed these variables in side-matter.js
    84             wp_enqueue_style( 'side-matter', plugins_url( 'side-matter.css', __FILE__ ), null, $this->version );
    85         }
    86     }
    87 
    88     /*
    89     Settings menu functions
    90     */
     64        $this->note_count = 0; // Set number from which to begin note count (integer; default: 0)
     65
     66    }
    9167
    9268    public function settings() { // Register Side Matter section and fields
    9369        $page = 'reading';
     70        $section = 'side_matter_section';
    9471        $fields = array(
    95             'is_responsive' => array(
    96                 'id' => 'is_responsive',
    97                 'title' => '<label for="is_responsive_field">Responsive Sidenotes</label>',
    98                 'callback' => array( &$this, 'is_responsive_field' ),
    99                 'page' => $page,
    100                 'section' => 'side_matter_section'
    101                 ),
    102             'use_effects' => array(
    103                 'id' => 'use_effects',
    104                 'title' => '<label for="use_effects_field">Transition Effects</label>',
    105                 'callback' => array( &$this, 'use_effects_field' ),
    106                 'page' => $page,
    107                 'section' => 'side_matter_section'
    108                 ),
    109             'note_adjust' => array(
    110                 'id' => 'note_adjust',
    111                 'title' => '<label for="note_adjust_field">Adjust vertical offset of sidenotes by</label>',
    112                 'callback' => array( &$this, 'note_adjust_field' ),
    113                 'page' => $page,
    114                 'section' => 'side_matter_section'
    115                 ),
    11672            'pages_active' => array(
    11773                'id' => 'pages_active',
    11874                'title' => 'Display Side Matter notes on',
    11975                'callback' => array( &$this, 'pages_active_field' ),
    120                 'page' => $page,
    121                 'section' => 'side_matter_section'
     76                'args' => array(
     77                    'pages' => array(
     78                        'front' => 'Front page',
     79                        'home' => 'Posts page',
     80                        'post' => 'Single posts',
     81                        'page' => 'Single pages'
     82                        )
     83                    )
     84                ),
     85            'is_responsive' => array(
     86                'id' => 'is_responsive',
     87                'title' => 'Responsive Sidenotes',
     88                'callback' => array( &$this, 'is_responsive_field' ),
     89                'args' => array(
     90                    'label_for' => 'is_responsive',
     91                    'text_append' => 'Enable responsive positioning on page resize and zoom'
     92                    )
     93                ),
     94            'use_effects' => array(
     95                'id' => 'use_effects',
     96                'title' => 'Transition Effects',
     97                'callback' => array( &$this, 'use_effects_field' ),
     98                'args' => array(
     99                    'label_for' => 'use_effects',
     100                    'text_append' => 'Enable fade effects on page load, resize, and zoom'
     101                    )
     102                ),
     103            'note_adjust' => array(
     104                'id' => 'note_adjust',
     105                'title' => 'Adjust vertical offset of sidenotes by',
     106                'callback' => array( &$this, 'note_adjust_field' ),
     107                'args' => array(
     108                    'label_for' => 'note_adjust',
     109                    'text_append' => 'px'
     110                    )
    122111                )
    123112        );
    124113        add_settings_section( 'side_matter_section', 'Side Matter', array( &$this, 'section' ), $page );
    125114        foreach ( $fields as $option => $parameter ) {
    126             add_settings_field( $fields[$option]['id'], $fields[$option]['title'], $fields[$option]['callback'], $fields[$option]['page'], $fields[$option]['section'] );
     115            add_settings_field( $fields[$option]['id'], $fields[$option]['title'], $fields[$option]['callback'], $page, $section, $fields[$option]['args'] );
    127116        }
    128117        register_setting( $page, 'side_matter_options', array( &$this, 'validate' ) );
     
    130119   
    131120    public function section() { // Text to place at beginning of settings section
    132         echo '<p>Use the following options to control the appearance and functionality of notes generated by the Side Matter plugin.</p>';
     121        echo 'Use the following options to control the appearance and functionality of notes generated by the Side Matter plugin.';
     122    }
     123
     124    public function pages_active_field( $args ) { // Field for pages_active option
     125        foreach ( $args['pages'] as $page => $page_name ) {
     126            echo "<label><input type='checkbox' name='side_matter_options[pages_active][{$page}]' value='1' " . checked( 1, $this->options['pages_active'][$page], false ) . " /> {$page_name}</label><br />";
     127        }
     128        echo '<p class="description">' . __( 'These conditions may override one another in some instances, as when a static page is set as your front page.' ) . '</p>';
     129    }
     130
     131    public function is_responsive_field( $args ) { // Field for is_responsive option
     132        echo "<p><label><input id='is_responsive' type='checkbox' name='side_matter_options[is_responsive]' value='1' " . checked( 1, $this->options['is_responsive'], false ) . ' /> ' . $args['text_append'] . '</label></p>';
     133    }
     134
     135    public function use_effects_field( $args ) { // Field for use_effects option
     136        echo "<p><label><input id='use_effects' type='checkbox' name='side_matter_options[use_effects]' value='1' " . checked( 1, $this->options['use_effects'], false ) . ' /> ' . $args['text_append'] . '</label></p>';
     137    }
     138
     139    public function note_adjust_field( $args ) { // Field for note_adjust option
     140        echo '<label><input id="note_adjust" name="side_matter_options[note_adjust]" type="number" step="1" max="1000" min="-1000" value="' . $this->options['note_adjust'] . '" class="small-text" /> ' . $args['text_append'] . '</label><p class="description">' . __( 'A positive value will push notes up; a negative value will push notes down.' ) . '</p>';
    133141    }
    134142
     
    136144        $effects = array( 'is_responsive', 'use_effects' );
    137145        $pages = $this->defaults['pages_active'];
     146        foreach ( $pages as $page => $setting ) {
     147            $this->options['pages_active'][$page] = ( ! isset( $input['pages_active'][$page] ) ) ? 0 : $input['pages_active'][$page];
     148        }
    138149        foreach ( $effects as $effect ) {
    139150            $this->options[$effect] = ( ! isset( $input[$effect] ) ) ? 0 : $input[$effect];
    140151        }
    141152        $this->options['note_adjust'] = ( ! isset( $input['note_adjust'] ) ) ? $this->defaults['note_adjust'] : intval( $input['note_adjust'] );
    142         foreach ( $pages as $page => $setting ) {
    143             $this->options['pages_active'][$page] = ( ! isset( $input['pages_active'][$page] ) ) ? 0 : $input['pages_active'][$page];
    144         }
    145153        return $this->options;
    146154    }
    147155
    148     public function is_responsive_field() {
    149         echo "<p><label><input id='is_responsive_field' type='checkbox' name='side_matter_options[is_responsive]' value='1' " . checked( 1, $this->options['is_responsive'], false ) . " /> Enable responsive positioning on page resize and zoom</label></p>";
    150 
    151     }
    152 
    153     public function use_effects_field() {
    154         echo "<p><label><input id='use_effects_field' type='checkbox' name='side_matter_options[use_effects]' value='1' " . checked( 1, $this->options['use_effects'], false ) . " /> Enable fade effects on page load, resize, and zoom</label></p>";
    155     }
    156 
    157     public function note_adjust_field() {
    158         echo '<input id="note_adjust_field" name="side_matter_options[note_adjust]" type="number" step="1" max="1000" min="-1000" value="' . $this->options['note_adjust'] . '" class="small-text" /> px<p class="description">A positive figure will push notes upward, while a negative figure will push them downward.</p>';
    159     }
    160 
    161     public function pages_active_field() {
    162         $pages = array(
    163             // 'home' => 'Home page',
    164             'front' => 'Front page',
    165             'post' => 'Posts',
    166             'page' => 'Pages' );
    167         foreach ( $pages as $page => $description ) {
    168             echo "<label><input type='checkbox' name='side_matter_options[pages_active][{$page}]' value='1' " . checked( 1, $this->options['pages_active'][$page], false ) . " /> {$description}</label><br />";
    169         }
    170         echo '<p class="description">Note that these conditions may overlap (for instance, a static page may be designated as your home page). Any page template must include a sidebar for widgets in order to display the Side Matter widget.</p>';
    171     }
    172 
    173     /*
    174     Note functions
    175     */
    176 
    177     public function shortcode( $atts, $content = null ) { // Capture shortcoded text and return reference numeral markup
     156    public function widget() { // Register widget
     157        register_widget( "Side_Matter_Widget" );
     158    }
     159
     160    public function shortcode( $atts, $content = null ) { // Capture shortcoded text and return reference numeral
    178161        $class = $this->options['html_class'];
    179162        if ( $this->check_page() ) {
    180163            $this->add_note( $content );
    181             return "<a id='ref-{$this->note_id}' class='{$class} {$class}-ref {$class}-ref-{$this->note_id}' href='#note-{$this->note_id}'><sup class='{$class} {$class}-sup {$class}-sup-{$this->note_id}'>{$this->note_id}</sup></a>"; // Return reference numeral
     164            return "<a id='ref-{$this->note_count}' class='{$class} {$class}-ref {$class}-ref-{$this->note_count}' href='#note-{$this->note_count}'><sup class='{$class} {$class}-sup {$class}-sup-{$this->note_count}'>{$this->note_count}</sup></a>";
    182165        } else {
    183166            return '';
     
    185168    }
    186169
     170    public function enqueue() { // Enqueue script and stylesheet; embed settings in side-matter.js
     171        if ( $this->check_page() ) {
     172            wp_enqueue_script( 'side-matter', plugins_url( 'side-matter.js', __FILE__ ), array( 'jquery' ), $this->version, true );
     173            wp_localize_script( 'side-matter', 'side_matter', array( // Embed settings in side-matter.js
     174                'is_responsive' => __( $this->options['is_responsive'] ),
     175                'use_effects' => __( $this->options['use_effects'] ),
     176                'note_adjust' => __( $this->options['note_adjust'] ),
     177                'html_class' => __( $this->options['html_class'] ) )
     178                );
     179            wp_enqueue_style( 'side-matter', plugins_url( 'side-matter.css', __FILE__ ), null, $this->version );
     180        }
     181    }
     182
    187183    public function check_page() { // If Side Matter is set to display notes on current page, return true
    188184
    189185        $pages = $this->options['pages_active'];
    190186
     187        $front = ( is_front_page() && $pages['front'] ) ? 1 : 0;
    191188        $home = ( is_home() && $pages['home'] ) ? 1 : 0;
    192         $front = ( is_front_page() && $pages['front'] ) ? 1 : 0;
    193189        $post = ( is_single() && $pages['post'] ) ? 1 : 0;
    194190        $page = ( is_page() && $pages['page'] ) ? 1 : 0;
    195         $pages_table = array( $home, $front, $post, $page );
    196 
    197         if ( in_array( 1, $pages_table ) ) { return true; } else { return false; }
     191        $pages_table = array( $front, $home, $post, $page );
     192
     193        if ( in_array( 1, $pages_table ) ) return true;
    198194
    199195    }
    200196
    201197    public function add_note( $shortcode_content ) { // Accept shortcoded text and add it to array $notes
    202         $this->note_id++;
    203         $this->note_text = $shortcode_content;
    204         $this->notes[$this->note_id] = $this->note_text; // Add note to end of array $notes
    205     }
    206 
    207     public function list_notes( $widget = false, $widget_id = null ) { // Generate HTML-formatted list of notes; if $widget_enclose is true, then enclose in widget <div> tags
     198        $this->note_count++;
     199        $this->notes[$this->note_count] = $shortcode_content; // Add note to end of array $notes
     200    }
     201
     202    public function list_notes() { // Generate HTML-formatted list of notes
    208203        $class = $this->options['html_class'];
    209204        if ( $this->check_page() && isset( $this->notes ) ) {
     
    213208            }
    214209            $notes_list .= '</ol>';
    215             if ( $widget ) {
    216                 $id = ( isset( $widget_id ) ) ? "id='{$widget_id}' " : '';
    217                 echo "<div {$id}class='widget {$class} {$class}-widget'>{$notes_list}</div>";
    218             } else {
    219                 echo $notes_list;
    220             }
     210            echo $notes_list;
    221211        }
    222212    }
     
    227217
    228218    public function __construct() {
    229         parent::__construct( 'side-matter', __( 'Side Matter' ), array( 'description' => __( 'Display Side Matter annotations in an ordered list' ) ) );
    230     }
    231 
    232     public function widget( $args, $instance ) { // Widget content
    233         do_action( 'side_matter_list_notes', true, $this->id ); // Call list_notes() in widget-enclosed format
     219        parent::__construct( 'side-matter', __( 'Side Matter' ), array( 'description' => __( 'Display Side Matter notes in an ordered list' ) ) );
     220    }
     221
     222    public function widget( $args, $instance ) { // Output widget content
     223        global $side_matter;
     224        $class = $side_matter->options['html_class'];
     225        echo "<div id='{$this->id}' class='widget {$class} {$class}-widget'>";
     226        do_action( 'side_matter_list_notes' ); // Call list_notes() in widget-enclosed format
     227        echo '</div>';
     228    }
     229
     230    public function form( $instance ) { // Widget options form
     231        $url = admin_url( 'options-reading.php' );
     232        echo "Modify Side Matter's default settings using the options menu on the <a href='{$url}'>Reading Settings</a> screen.";
    234233    }
    235234
Note: See TracChangeset for help on using the changeset viewer.