more changes and add comicpress 2.8 for options

This commit is contained in:
John Bintz 2009-09-12 16:45:35 -04:00
parent 0ca3eee9cf
commit 41617f42f1
3 changed files with 32 additions and 16 deletions

View File

@ -17,6 +17,7 @@
<p><?php _e('Need some sane defaults for your theme? Click one of the links below to populate the selectors on the left:', 'keyboard-navigation') ?></p> <p><?php _e('Need some sane defaults for your theme? Click one of the links below to populate the selectors on the left:', 'keyboard-navigation') ?></p>
<ul> <ul>
<li><a href="#" class="pre-populate comicpress_28"><?php _e('Default ComicPress 2.8 Theme', 'keyboard-navigation') ?></a></li>
<li><a href="#" class="pre-populate comicpress_25"><?php _e('Default ComicPress 2.5 Theme', 'keyboard-navigation') ?></a></li> <li><a href="#" class="pre-populate comicpress_25"><?php _e('Default ComicPress 2.5 Theme', 'keyboard-navigation') ?></a></li>
</ul> </ul>
</div> </div>
@ -60,6 +61,12 @@
next: "div#menunav a span.next", next: "div#menunav a span.next",
first: "", first: "",
last: "div#header h1 a" last: "div#header h1 a"
},
'comicpress_28': {
previous: ".navi-prev",
next: ".navi-next",
first: ".navi-first",
last: ".navi-last"
} }
}; };

View File

@ -15,7 +15,7 @@ KeyboardNavigation.get_hrefs = function(fields, admin_mode) {
while (top_node) { while (top_node) {
if (top_node.href) { if (top_node.href) {
found_properties[key] = top_node.href; is_found = true; found_properties[key] = top_node.href; is_found = true;
if (highlight_selectors) { if (admin_mode) {
var highlight_a = new Element("a", { "title": key + ": " + instructions, "href": top_node.href, "style": "display: block; position: absolute; border: solid #f00 1px; background-color: #ff0; z-index: 1" }); var highlight_a = new Element("a", { "title": key + ": " + instructions, "href": top_node.href, "style": "display: block; position: absolute; border: solid #f00 1px; background-color: #ff0; z-index: 1" });
highlight_a.setOpacity(0.5); highlight_a.setOpacity(0.5);
highlight_a.clonePosition(top_node); highlight_a.clonePosition(top_node);
@ -33,7 +33,7 @@ KeyboardNavigation.get_hrefs = function(fields, admin_mode) {
} }
} }
if (highlight_selectors) { if (admin_mode) {
if (missing_properties.length > 0) { if (missing_properties.length > 0) {
var message = "[Keyboard Navigation] Missing selectors:\n\n" + missing_properties.join("\n"); var message = "[Keyboard Navigation] Missing selectors:\n\n" + missing_properties.join("\n");
if (top.console) { if (top.console) {

View File

@ -6,6 +6,8 @@ Description: Attach keyboard navigation to blog entries.
Version: 1.0 Version: 1.0
Author: John Bintz Author: John Bintz
Author URI: http://www.coswellproductions.org/wordpress/ Author URI: http://www.coswellproductions.org/wordpress/
Requires at least: 2.7
Tested up to: 2.8.4
Copyright 2008-2009 John Bintz (email : jcoswell@coswellproductions.org) Copyright 2008-2009 John Bintz (email : jcoswell@coswellproductions.org)
@ -29,7 +31,7 @@ class KeyboardNavigation {
function init() { function init() {
wp_enqueue_script('prototype'); wp_enqueue_script('prototype');
add_action('wp_footer', array(&$this, "footer")); add_action('wp_footer', array(&$this, "wp_footer"));
add_action('admin_menu', array(&$this, "admin_menu")); add_action('admin_menu', array(&$this, "admin_menu"));
add_action('admin_head', array(&$this, "admin_head")); add_action('admin_head', array(&$this, "admin_head"));
@ -69,25 +71,32 @@ class KeyboardNavigation {
function KeyboardNavigation() {} function KeyboardNavigation() {}
function footer() { function wp_footer() {
$plugin_url_root = pathfinding_get_admin_url() . '/' . pathfinding_get_plugin_path(); ?> $plugin_dir_url = plugin_dir_url(__FILE__);
<script type="text/javascript" src="<?php echo $plugin_url_root ?>/keyboard_navigation.js"></script> $options = get_option('keyboard-navigation-options');
<script type="text/javascript"> $nonce = wp_create_nonce('keyboard-navigation');
$options = get_option('keyboard-navigation-options');
if (!is_array($options)) { $options = array(); }
?><script type="text/javascript">
var s = document.createElement('script');
s.src = '<?php echo $plugin_dir_url . 'keyboard-navigation.js' ?>';
s.onload = function() {
var keyboard_navigation_fields = {}; var keyboard_navigation_fields = {};
<?php foreach (array_keys($this->fields) as $field) { <?php foreach (array_keys($this->fields) as $field) {
$selector = get_option("keyboard-navigation-selector-${field}"); if (!empty($options['selectors'][$field])) { ?>
if (!empty($selector)) { ?> keyboard_navigation_fields['<?php echo $field ?>'] = "<?php echo addslashes($options['selectors'][$field]) ?>";
keyboard_navigation_fields['<?php echo $field ?>'] = "<?php echo addslashes($selector) ?>";
<?php } <?php }
} ?> } ?>
var highlight_selectors = <?php echo (WP_ADMIN && (get_option("keyboard-navigation-highlight-selected-elements") == 1)) ? "true" : "false" ?>; var highlight_selectors = <?php echo (current_user_can('edit_themes') && $options['highlight']) ? "true" : "false" ?>;
var results = KeyboardNavigation.get_hrefs(keyboard_navigation_fields, highlight_selectors); var results = KeyboardNavigation.get_hrefs(keyboard_navigation_fields, highlight_selectors);
if (results != false) { KeyboardNavigation.add_events(results); } if (results != false) { KeyboardNavigation.add_events(results); }
};
document.getElementsByTagName('body')[0].appendChild(s);
</script> </script>
<?php <?php }
}
function admin_menu() { function admin_menu() {
add_options_page('Keyboard Navigation', __("Keyboard Navigation", 'keyboard-navigation'), 'edit_themes', 'keyboard-navigation', array($this, "link_editor")); add_options_page('Keyboard Navigation', __("Keyboard Navigation", 'keyboard-navigation'), 'edit_themes', 'keyboard-navigation', array($this, "link_editor"));