merge in new bookmark widget

This commit is contained in:
John Bintz 2009-12-20 22:08:47 -05:00
commit 2ca186d739
8 changed files with 284 additions and 82 deletions

View File

@ -6,18 +6,36 @@ if (function_exists('add_theme_support')) {
}
function __comicpress_widgets_init() {
$available_widgets = array();
if (($dh = opendir(dirname(__FILE__) . '/widgets')) !== false) {
while (($file = readdir($dh)) !== false) {
if (strpos($file, '.inc') !== false) {
$class_name = preg_replace('#\..*$#', '', $file);
require_once(dirname(__FILE__) . '/widgets/' . $file);
register_widget($class_name);
$widget = new $class_name();
if (method_exists($widget, 'init')) { $widget->init(); }
$widget = new $class_name(true);
if (method_exists($widget, 'init')) {
$widget->init();
}
$available_widgets[strtolower($class_name)] = $widget;
}
}
closedir($dh);
}
foreach (wp_get_sidebars_widgets() as $type => $widgets) {
if ($type != 'wp_inactive_widgets') {
foreach ($widgets as $widget_id) {
foreach ($available_widgets as $key => $widget) {
if (strpos(strtolower($widget_id), $key) === 0) {
$widget->is_active();
}
}
}
}
}
}
function __comicpress_init() {

View File

@ -1,72 +1,94 @@
var button_images = {
'clear-tag': {
'off': '3a.gif', 'on': '3.gif'
},
'goto-tag': {
'off': '2a.gif', 'on': '2.gif'
}
};
var BookmarkInfo = Class.create({
'def': {
'permalink': false
},
'initialize': function() {
this.jar = new CookieJar({
'expires': 60 * 60 * 24 * 31,
'path': '/'
});
},
'read': function() {
var bookmark_info = this.jar.get('bookmark-info');
'permalink': false
},
'initialize': function() {
this.jar = new CookieJar({
'expires': 60 * 60 * 24 * 31,
'path': '/'
});
},
'read': function() {
var bookmark_info = this.jar.get('bookmark-info');
if ((typeof(bookmark_info) != 'object') || (bookmark_info == null)) {
bookmark_info = this.def;
}
if ((typeof(bookmark_info) != 'object') || (bookmark_info == null)) {
bookmark_info = this.def;
}
return bookmark_info;
},
'write': function(bookmark_info) {
this.jar.put('bookmark-info', bookmark_info);
if (this.onWrite) { this.onWrite(bookmark_info); }
}
return bookmark_info;
},
'write': function(bookmark_info) {
this.jar.put('bookmark-info', bookmark_info);
if (this.onWrite) { this.onWrite(bookmark_info); }
}
});
Event.observe(window, 'load', function() {
var bookmark_info = new BookmarkInfo();
var info = bookmark_info.read();
var ComicBookmark = {};
ComicBookmark.setup = function(id, mode, url, elements) {
var bookmark_info = new BookmarkInfo();
var info = bookmark_info.read();
if ($('comic-bookmark-holder')) {
var hrefs = {};
$$('#comic-bookmark-holder a').each(function(a) {
if ($(id)) {
var hrefs = {};
$$('#' + id + ' a').each(function(a) {
var name = $w(a.className).shift();
hrefs[name] = a;
});
var set_goto_tag = function(i) {
hrefs['goto-tag'].href = (i.permalink ? i.permalink : "#");
[ 'goto-tag','clear-tag' ].each(function(which) {
hrefs[which].select('img')[0].src = image_root + button_images[which][i.permalink ? "on" : "off"];
});
};
switch (mode) {
case 'three-button':
var set_goto_tag = function(i) {
hrefs['goto-tag'].href = (i.permalink ? i.permalink : "#");
['goto-tag','clear-tag'].each(function(which) {
hrefs[which].innerHTML = elements[which + '-' + (i.permalink ? "on" : "off")];
});
};
bookmark_info.onWrite = function(i) { set_goto_tag(i); }
set_goto_tag(info);
hrefs['tag-page'].innerHTML = elements['tag-page'];
Event.observe(hrefs['tag-page'], 'click', function(e) {
Event.stop(e);
info.permalink = permalink;
bookmark_info.write(info);
});
bookmark_info.onWrite = function(i) { set_goto_tag(i); }
set_goto_tag(info);
Event.observe(hrefs['clear-tag'], 'click', function(e) {
Event.stop(e);
info.permalink = false;
bookmark_info.write(info);
});
hrefs['tag-page'].observe('click', function(e) {
Event.stop(e);
info.permalink = url;
bookmark_info.write(info);
});
Event.observe(hrefs['goto-tag'], 'click', function(e) {
if (hrefs['goto-tag'].href == "#") { Event.stop(e); }
});
}
});
hrefs['goto-tag'].observe('click', function(e) {
if (hrefs['goto-tag'].href == "#") { Event.stop(e); }
});
hrefs['clear-tag'].observe('click', function(e) {
Event.stop(e);
info.permalink = false;
bookmark_info.write(info);
});
break;
case 'one-button':
var set_goto_tag = function(i) {
hrefs['bookmark-clicker'].href = (i.permalink ? i.permalink : "#");
hrefs['bookmark-clicker'].innerHTML = elements['bookmark-clicker-' + (i.permalink ? "on" : "off")];
};
bookmark_info.onWrite = function(i) { set_goto_tag(i); }
set_goto_tag(info);
hrefs['bookmark-clicker'].observe('click', function(e) {
var current_link = info.permalink;
info.permalink = (hrefs['bookmark-clicker'].href.match(/#$/)) ? url : false;
bookmark_info.write(info);
if (hrefs['bookmark-clicker'].href.match(/#$/) == null) {
hrefs['bookmark-clicker'].href = url;
Event.stop(e);
} else {
document.location.href = current_link;
Event.stop(e);
}
});
break;
}
}
};

View File

@ -0,0 +1 @@
<?php

View File

@ -12,9 +12,11 @@ Author URI: http://frumph.net/
class ArchiveDropdownWidget extends WP_Widget {
var $modes;
function ArchiveDropdownWidget() {
$widget_ops = array('classname' => 'ArchiveDropdownWidget', 'description' => __('Display a dropdown list of your archives, styled.','comicpress') );
$this->WP_Widget('comicpress_archive_dropdown', __('ComicPress Archive Dropdown','comicpress'), $widget_ops);
function ArchiveDropdownWidget($skip_widget_init = false) {
if (!$skip_widget_init) {
$widget_ops = array('classname' => __CLASS__, 'description' => __('Display a dropdown list of your archives, styled.','comicpress') );
$this->WP_Widget(__CLASS__, __('ComicPress Archive Dropdown','comicpress'), $widget_ops);
}
$this->modes = array(
'monthly_archive' => __('Monthly archive', 'comicpress'),

View File

@ -1,13 +1,55 @@
<?php
class BookmarkWidget extends WP_Widget {
function BookmarkWidget() {
$widget_ops = array('classname' => __CLASS__, 'description' => __('Allow the user to bookmark a page and then jump to it upon return.','comicpress') );
$this->WP_Widget('comicpress-bookmark', __('ComicPress Bookmark','comicpress'), $widget_ops);
var $text_fields;
function BookmarkWidget($skip_widget_init = false) {
if (!$skip_widget_init) {
$widget_ops = array('classname' => __CLASS__, 'description' => __('Allow the user to bookmark a page and then jump to it upon return.','comicpress') );
$this->WP_Widget(__CLASS__, __('ComicPress Bookmark','comicpress'), $widget_ops);
}
$this->text_fields = array(
'three-button' => array(
'tag-page' => array(
'label' => __('Tag page', 'comicpress'),
'default' => __('Bookmark', 'comicpress')
),
'clear-tag-off' => array(
'label' => __('Clear tag off', 'comicpress'),
'default' => ''
),
'clear-tag-on' => array(
'label' => __('Clear tag on', 'comicpress'),
'default' => __('Clear', 'comicpress')
),
'goto-tag-off' => array(
'label' => __('Goto tag off', 'comicpress'),
'default' => ''
),
'goto-tag-on' => array(
'label' => __('Goto tag on', 'comicpress'),
'default' => __('Goto', 'comicpress')
)
),
'one-button' => array(
'bookmark-clicker-off' => array(
'label' => __('Set bookmark', 'comicpress'),
'default' => __('+Bookmark', 'comicpress')
),
'bookmark-clicker-on' => array(
'label' => __('Use bookmark', 'comicpress'),
'default' => __('&gt;&gt;Bookmark', 'comicpress')
)
)
);
}
function init() {
add_action('wp_head', array(&$this, 'wp_head'));
}
function is_active() {
add_action('template_redirect', array(&$this, 'template_redirect'));
}
@ -24,11 +66,122 @@ class BookmarkWidget extends WP_Widget {
</script>
<?php }
function widget() {
?>
<div id="comic-bookmark-holder">
<a href="#" class="tag-page"><img src="<?php echo get_template_directory_uri() ?>/images/1.gif" /></a><a href="#" class="goto-tag"><img /></a><a href="#" class="clear-tag"><img /></a>
</div>
<?php
function form($instance) {
?>
<div id="<?php echo $this->get_field_id('wrapper') ?>">
<p>
<label><?php _e('Title', 'comicpress') ?><br />
<input class="widefat" type="text"
name="<?php echo $this->get_field_name('title') ?>"
value="<?php echo esc_attr($instance['title']) ?>" />
</label>
</p>
<?php
foreach (array(
'three-button' => __('Three-button mode', 'comicpress'),
'one-button' => __('One-button mode', 'comicpress')
) as $mode => $label) { ?>
<p>
<label>
<input type="radio"
id="<?php echo $this->get_field_id($mode) ?>"
name="<?php echo $this->get_field_name('mode') ?>"
value="<?php echo esc_attr($mode) ?>"
<?php echo $instance['mode'] == $mode ? 'checked="checked"' : '' ?> /> <?php echo $label ?>
</label>
</p>
<div id="<?php echo $this->get_field_id("${mode}-options") ?>"><p>
<?php
foreach ($this->text_fields[$mode] as $name => $info) {
extract($info);
$value = empty($instance[$name]) ? $default : $instance[$name];
?>
<label><?php echo $label ?><br />
<input class="widefat" type="text"
name="<?php echo $this->get_field_name($name) ?>"
value="<?php echo esc_attr($value) ?>" />
</label>
<br /><?php
}
?>
</p></div>
<?php } ?>
</div>
<script type="text/javascript">
(function($) {
var wrapper = '<?php echo $this->get_field_id('wrapper') ?>';
var radios = $('#' + wrapper + ' input[type=radio]');
var show = function() {
radios.each(function() {
$('#' + this.id + '-options')[this.checked ? 'show' : 'hide']();
});
};
radios.click(show);
show();
}(jQuery));
</script>
<?php }
function update($new_instance, $old_instance) {
$instance = array();
$all_text_fields = array('title');
foreach ($this->text_fields as $type => $fields) {
$all_text_fields = array_merge($all_text_fields, array_keys($fields));
}
foreach ($all_text_fields as $key) {
$instance[$key] = strip_tags($new_instance[$key]);
}
if (isset($this->text_fields[$new_instance['mode']])) {
$instance['mode'] = $new_instance['mode'];
} else {
$instance['mode'] = array_shift(array_keys($this->text_fields));
}
return $instance;
}
function widget($args, $instance) {
global $post;
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
if (!empty($title)) { echo $before_title . $title . $after_title; };
$id = 'comic-bookmark-' . md5(rand());
switch ($instance['mode']) {
case 'three-button': ?>
<div class="bookmark-widget" id="<?php echo $id ?>">
<a href="#" class="tag-page"></a>
<a href="#" class="goto-tag"></a>
<a href="#" class="clear-tag"></a>
</div>
<?php break;
case 'one-button': ?>
<div class="bookmark-widget" id="<?php echo $id ?>">
<a href="#" class="bookmark-clicker"></a>
</div>
<?php break;
} ?>
<script type="text/javascript">
(function() {
ComicBookmark.setup('<?php echo $id ?>', '<?php echo $instance['mode'] ?>', '<?php echo get_permalink($post) ?>', {
<?php
$elements = array();
foreach (array_keys($this->text_fields[$instance['mode']]) as $field) {
$elements[] = "'{$field}': '{$instance[$field]}'";
}
echo implode(',', $elements);
?>
});
}());
</script><?php
echo $after_widget;
}
}

View File

@ -10,9 +10,11 @@ Author URI: http://frumph.net/
*/
class BuyThisPrintWidget extends WP_Widget {
function BuyThisPrintWidget() {
$widget_ops = array('classname' => 'ComicPressBuyThisPrint', 'description' => __('Adds a button that goes to the buy print template page.','comicpress') );
$this->WP_Widget('comicpress_buyprint', __('ComicPress BuyPrint','comicpress'), $widget_ops);
function BuyThisPrintWidget($skip_widget_init = false) {
if (!$skip_widget_init) {
$widget_ops = array('classname' => __CLASS__, 'description' => __('Adds a button that goes to the buy print template page.','comicpress') );
$this->WP_Widget(__CLASS__, __('Buy This Print','comicpress'), $widget_ops);
}
}
function init() {
@ -21,7 +23,7 @@ class BuyThisPrintWidget extends WP_Widget {
function widget($args, $instance) {
extract($args, EXTR_SKIP);
echo $before_widget;
$title = apply_filters('widget_title', $instance['title']);
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };

View File

@ -10,9 +10,11 @@ Author URI: http://frumph.net/
class CalendarWidget extends WP_Widget {
function CalendarWidget() {
$widget_ops = array('classname' => 'CalendarWidget', 'description' => __('Display a calendar showing this months posts. (this calendar does not drop lines if there is no title given.)','comicpress') );
$this->WP_Widget('comicpress_calendar', __('ComicPress Calendar','comicpress'), $widget_ops);
function CalendarWidget($skip_widget_init = false) {
if (!$skip_widget_init) {
$widget_ops = array('classname' => __CLASS__, 'description' => __('Display a calendar showing this months posts. (this calendar does not drop lines if there is no title given.)','comicpress') );
$this->WP_Widget(__CLASS__, __('ComicPress Calendar','comicpress'), $widget_ops);
}
}
function widget($args, $instance) {

View File

@ -11,16 +11,18 @@ Author URI: http://frumph.net/
require_once(dirname(__FILE__) . '/../classes/ComicPressNavigation.inc');
class GraphicalNavigationWidget extends WP_Widget {
function GraphicalNavigationWidget() {
$widget_ops = array('classname' => 'WidgetComicPressGraphicalStorylineNavigation', 'description' => __('Displays Graphical Navigation Buttons. (used in comic sidebars)','comicpress') );
$this->WP_Widget('comicpress_graphicalstorylinenavigation', __('ComicPress Comic Navigation','comicpress'), $widget_ops);
function GraphicalNavigationWidget($skip_widget_init = false) {
if (!$skip_widget_init) {
$widget_ops = array('classname' => __CLASS__, 'description' => __('Displays Graphical Navigation Buttons. (used in comic sidebars)','comicpress') );
$this->WP_Widget(__CLASS__, __('Comic Navigation','comicpress'), $widget_ops);
}
}
/**
* Initialize the widget class.
*/
function init() {
add_filter('comicpress_display_navigation_order', array(&$this, 'comicpress_display_navigation_order'));
add_filter('comicpress_display_navigation_order', array($this, 'comicpress_display_navigation_order'));
add_filter('comicpress_display_navigation_link', array(&$this, 'comicpress_display_navigation_link'), 10, 5);
add_filter('comicpress_wrap_navigation_buttons', array(&$this, 'comicpress_wrap_navigation_buttons'), 10, 2);
add_filter('comicpress_navigation_grouping_details', array(&$this, 'comicpress_navigation_grouping_details'));