Changeset 690339
- Timestamp:
- 04/01/2013 11:34:37 PM (13 years ago)
- Location:
- side-matter/trunk
- Files:
-
- 1 added
- 3 edited
-
readme.txt (modified) (7 diffs)
-
side-matter.js (modified) (3 diffs)
-
side-matter.php (modified) (9 diffs)
-
uninstall.php (added)
Legend:
- Unmodified
- Added
- Removed
-
side-matter/trunk/readme.txt
r689346 r690339 14 14 Side 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. 15 15 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.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 annotations by Grantland and other websites. 17 17 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 withCSS.18 Works 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. 19 19 20 To use, justplace the Side Matter widget in your sidebar, then enclose sidenote text in a page or post using the `[ref]` shortcode, like so:20 To use, place the Side Matter widget in your sidebar, then enclose sidenote text in a page or post using the `[ref]` shortcode, like so: 21 21 22 22 > Here's the text to annotate.`[ref]`Sidenote text goes here.`[/ref]` … … 24 24 == Installation == 25 25 26 1. Upload the directory `side-matter` to `wp-content/plugins` .26 1. Upload the directory `side-matter` to `wp-content/plugins` (or install it from the Plugins menu). 27 27 2. Activate Side Matter using the Plugins menu. 28 28 3. Using the Widgets menu, place the Side Matter widget in a sidebar used by your pages and/or posts. … … 31 31 > Here's the text to annotate.`[ref]`Sidenote text goes here.`[/ref]` 32 32 33 Side Matter's default settings may be changed using its options menu, located on your Reading Settings admin page.33 5. To modify Side Matter's default settings, use the options menu, located on your Reading Settings screen. 34 34 35 The appearanceof 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.)35 The 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.) 36 36 37 37 == Frequently Asked Questions == … … 39 39 = Where is Side Matter's options menu? = 40 40 41 The options menu can be found on your Reading Settings admin page.41 The options menu can be found on the Reading Settings screen. 42 42 43 = Does Side Matterwork with responsive layouts? =43 = Does it work with responsive layouts? = 44 44 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.)45 Yes. 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.) 46 46 47 = My notes a ppear in the sidebar, but they're bunched together at the top of the sidebar instead of aligningwith their references in the text. =47 = My notes aren't aligned with their references in the text. = 48 48 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, yourtheme 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).49 Your 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). 50 50 51 = My notes appear at a consistentvertical offset from their proper position. =51 = My notes appear at a regular vertical offset from their proper position. = 52 52 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.53 For 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. 54 54 55 = My notes don't appear in the sidebar.=55 = Why doesn't the plugin work with some themes? = 56 56 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.57 WordPress 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. 58 58 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. 59 While 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. 64 60 65 61 = How do I modify the appearance of sidenote list numerals without also restyling sidenote text? = … … 67 63 The 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. 68 64 65 = Is there a way to display Side Matter notes without the widget? = 66 67 Yes. Use the custom action `side_matter_list_notes` in your sidebar template, like so: 68 69 <?php do_action( 'side_matter_list_notes' ); ?> 70 71 This generates an ordered list of Side Matter notes (without the `div` that encloses the widget). 72 69 73 == Screenshots == 70 74 71 75 1. Side Matter captures footnote text using the [ref] shortcode, then automatically positions each footnote alongside its corresponding reference in the text. 72 76 73 2. Side Matter's default settings can be modified using an options menu on the Reading Settings admin page.77 2. Side Matter's default settings can be modified using an options menu on the Reading Settings screen. 74 78 75 79 == Changelog == 76 80 77 81 = 0.8 = 78 * Added an option to d esignate 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. 82 86 83 87 = 0.7 = 84 * Added an options menu to the Reading Settings admin page.88 * Added an options menu to the Reading Settings screen. 85 89 * Made various tweaks for security, performance, and cross-browser compatibility. 86 90 * Paragraphs within sidenotes are now properly wrapped in `p` tags by WordPress. … … 104 108 105 109 = 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.110 This 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. 107 111 108 112 = 0.7 = … … 115 119 This update fixes an error that was preventing plugin activation for some users. Recommended. 116 120 117 == Styling Side Matter with C SS ==121 == Styling Side Matter with Custom CSS == 118 122 119 123 `div.side-matter-widget`. 120 124 121 125 == For Theme Authors == -
side-matter/trunk/side-matter.js
r689346 r690339 9 9 */ 10 10 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`. */ 12 12 var isResponsive = side_matter.is_responsive; // If true, reposition notes on resize/zoom (boolean) 13 13 var useEffects = side_matter.use_effects; // If true, enable jQuery fade effects when positioning notes (boolean) 14 14 var 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)16 15 var htmlClass = side_matter.html_class; // Class to use when selecting Side Matter tags (string; default: 'side-matter') 16 17 17 var isResizing; // Used for resize-timeout function 18 18 … … 24 24 var notePosition = jQuery(note).position().top; // Position of sidenote 25 25 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 noteBuffer26 var finalOffset = (noteOffset < 0) ? 0 : noteOffset; // If offset is negative, set to 0 (prevents layout problems) 27 27 jQuery(note).css('marginTop', finalOffset); // Position note 28 28 } … … 30 30 31 31 jQuery(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 33 33 }); 34 34 35 jQuery(window).load(function() { 36 for (i = 1; i <= 2; i++) { placeNotes(); } // Loop twice to correct any initial misplacements37 if (useEffects == true) {38 jQuery('ol.' + htmlClass + '- ol').fadeTo(200, 1);35 jQuery(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); 39 39 } else { 40 jQuery('ol.' + htmlClass + '- ol').css('opacity', 1);40 jQuery('ol.' + htmlClass + '-list').css('opacity', 1); 41 41 } 42 42 }); 43 43 44 if (isResponsive == true) {44 if (isResponsive == 1) { 45 45 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); } 47 47 var timeoutInterval = 500; // Time (in ms) to throttle the re-positioning loop, preventing script overload on resize (default: 500) 48 48 function doneResizing() { 49 49 placeNotes(); 50 if (useEffects == true) { jQuery('li.' + htmlClass + '-li').fadeTo(200, 1); }50 if (useEffects == 1) { jQuery('li.' + htmlClass + '-note').fadeTo(200, 1); } 51 51 } 52 52 clearTimeout(isResizing); -
side-matter/trunk/side-matter.php
r689352 r690339 30 30 $side_matter = new Side_Matter; 31 31 32 register_uninstall_hook( __FILE__, 'side_matter_uninstall' );33 34 function side_matter_uninstall() {35 delete_option( 'side_matter_options' );36 }37 38 32 class Side_Matter { 39 33 … … 43 37 44 38 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) 47 40 48 41 public function __construct() { // Construct class and set defaults 49 42 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 51 45 add_shortcode( 'ref', array( &$this, 'shortcode' ) ); // Register shortcode 52 add_action( 'widgets_init', array( &$this, 'widget' ) ); // Register widget53 46 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 notes47 add_action( 'side_matter_list_notes', array( &$this, 'list_notes' ) ); // Get HTML list of notes 55 48 56 49 $this->defaults = array( // Set option defaults … … 58 51 'use_effects' => 1, // Enable fade effects (boolean; default: 1) 59 52 '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)61 53 'html_class' => sanitize_html_class( 'side-matter' ), // Class to use for Side Matter tags (string; default: 'side-matter') 62 54 'pages_active' => array( // Pages on which to display Side Matter notes (array) 55 'front' => 0, // Default: 0 63 56 'home' => 0, // Default: 0 64 'front' => 0, // Default: 065 57 'post' => 1, // Default: 1 66 58 'page' => 1 // Default: 1 … … 70 62 $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 71 63 $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 } 91 67 92 68 public function settings() { // Register Side Matter section and fields 93 69 $page = 'reading'; 70 $section = 'side_matter_section'; 94 71 $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 ),116 72 'pages_active' => array( 117 73 'id' => 'pages_active', 118 74 'title' => 'Display Side Matter notes on', 119 75 '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 ) 122 111 ) 123 112 ); 124 113 add_settings_section( 'side_matter_section', 'Side Matter', array( &$this, 'section' ), $page ); 125 114 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'] ); 127 116 } 128 117 register_setting( $page, 'side_matter_options', array( &$this, 'validate' ) ); … … 130 119 131 120 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>'; 133 141 } 134 142 … … 136 144 $effects = array( 'is_responsive', 'use_effects' ); 137 145 $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 } 138 149 foreach ( $effects as $effect ) { 139 150 $this->options[$effect] = ( ! isset( $input[$effect] ) ) ? 0 : $input[$effect]; 140 151 } 141 152 $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 }145 153 return $this->options; 146 154 } 147 155 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 178 161 $class = $this->options['html_class']; 179 162 if ( $this->check_page() ) { 180 163 $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 numeral164 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>"; 182 165 } else { 183 166 return ''; … … 185 168 } 186 169 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 187 183 public function check_page() { // If Side Matter is set to display notes on current page, return true 188 184 189 185 $pages = $this->options['pages_active']; 190 186 187 $front = ( is_front_page() && $pages['front'] ) ? 1 : 0; 191 188 $home = ( is_home() && $pages['home'] ) ? 1 : 0; 192 $front = ( is_front_page() && $pages['front'] ) ? 1 : 0;193 189 $post = ( is_single() && $pages['post'] ) ? 1 : 0; 194 190 $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; 198 194 199 195 } 200 196 201 197 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 208 203 $class = $this->options['html_class']; 209 204 if ( $this->check_page() && isset( $this->notes ) ) { … … 213 208 } 214 209 $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; 221 211 } 222 212 } … … 227 217 228 218 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."; 234 233 } 235 234
Note: See TracChangeset
for help on using the changeset viewer.