| Project: | Watcher |
| Version: | 6.x-1.4 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | reviewed & tested by the community |
Issue Summary
This patch allows you to choose where to put the watcher toggle link - either at the bottom of the node body (as it does now), or in the standard node links section.
I had to alter some CSS to get the link to display inline and without custom formatting, but its a little theme-specific so I'll just post it here and the module maintainer can integrate with the module as they see fit.
.links .watcher a {
background-image: url(/sites/all/modules/watcher/images/unwatch.gif) !important;
display: inline;
font-weight: normal;
}
.links .watcher a.watcher_node_toggle_watching_link_watched {
background-image: url(/sites/all/modules/watcher/images/watch.gif) !important;
}
.links .watcher a.watcher_node_help_link_to_binder {
display: none;
}
.links .watcher_node_watched {
background: none !important;
}A couple of minor issues I ran into:
- Use of !important in the standard style is nasty - it makes it harder to override in custom css.
- The "eye" background-image in css is a property of the parent element, not the link anchor, therefore it is not clickable. If moved to the anchor element it would be clickable as part of the link (my css above does this in node links mode).
- I would like shorter text when putting the watcher link in the links section (e.g. "Watch this" / "Stop watching" or "Notifications on/off"), but it has to be overridden in code, or using the locale module with a fake English language (yuck). Consider making the default link text strings admin variables? In fact I might go write another patch to enable this.
- Fade in/out when clicked causes problem when using inline links as all links to the right "squash up" to the left when the link disappears, then move back to the right when it reappears.
| Attachment | Size |
|---|---|
| links.patch | 5.43 KB |
Comments
#1
Ok here is another patch adding the ability to customise the watch link text in the admin settings UI.
#2
Solution to the other links shifting left/right when the watcher link fades out then back in:
In watcher.js,
replace
$(el).fadeOut("normal")(1 occurrence)with
$(el).fadeTo("normal", 0.2)and
$(el).fadeIn("normal")(2 occurrences)with
$(el).fadeTo("normal", 1)This does a partial fade, but the whole element does not disappear.
#3
The CSS is the way it is for several reasons, some of them due to legacy. I agree about the important statement, it's nasty, however it shouldn't stop you from overriding it.
I'll take into consideration having the module implement hook_link().
#4
#5
Glad I just found out about this module. The mark/unmark paradigm is very intuitive.
Indeed I would like to see for "watcher" a UI along the lines of the flag module.
In my D6 use case I have already a number of flag/unflag links (with configurable labels):
whether they come from "flags" or "watcher" should be transparent to the user.
I didn't dare to ask for this feature... but here it is. Thank You!
#6
It's coming in the next version for Drupal 6.
#7
was this ever added?
#8
Not yet.
#9
Patch against the current 5.x-1.6 release of watcher.
I don't use Drupal 6 currently, so please don't ask (I'll post it if/when we upgrade).
#10
Patch attached against 6.x-1.3. To summarise it does the following:
- Allows you to put the watcher link in the node links section instead of the node body
- Allows you to change the text used for the links
Hmm no drupal won't let me upload saying some sort of validation error, so here it is in text:
Index: watcher.module
--- watcher.module Base (BASE)
+++ watcher.module Locally Modified (Based On LOCAL)
@@ -162,6 +162,45 @@
}
/**
+ * Return a toggle watching post link array to be displayed in the node links section
+ *
+ * Please note that the JavaScript that handles the AJAX request looks for the class
+ * attribute so do not change it, rather override it with your own CSS rules if you
+ * want to change the appearance of this element.
+ *
+ * @param $uid
+ * The user we'd like to toggle watching for
+ * @param $nid
+ * The node id we're toggling watching for for this user
+ * @param $dest
+ * The URL of the current page, used for redirection afterwards
+ * @param $user_is_watching
+ * A boolean denoting whether uid is watching nid
+ * @param $t
+ * An associative array of localized strings
+ *
+ * @return
+ * An array defining the link properties
+ *
+ */
+function theme_watcher_node_links_toggle_watching_link($uid, $nid, $dest, $user_is_watching, $t = array()) {
+
+ // Set up classes
+ $class_watch_status_link = ( $user_is_watching ? ' watcher_node_toggle_watching_link_watched' : '');
+
+ return array(
+ 'href' => "user/$uid/watcher/toggle/$nid",
+ 'title' => ( $user_is_watching ? $t['watch_toggle_enabled'] : $t['watch_toggle_disabled'] ),
+ 'attributes' => array(
+ 'class' => "watcher_node_toggle_watching_link$class_watch_status_link",
+ 'title' => ( $user_is_watching ? $t['watch_toggle_enabled_title'] : $t['watch_toggle_disabled_title'] ),
+ ),
+ 'query' => $dest,
+ );
+
+}
+
+/**
* Return the help page
*
* @param $content
@@ -222,6 +261,9 @@
'watcher_node_toggle_watching_link' => array(
'arguments' => array('uid' => null, 'nid' => null, 'dest' => null, 'user_is_watching' => null, 't' => array()),
),
+ 'watcher_node_links_toggle_watching_link' => array(
+ 'arguments' => array('uid' => null, 'nid' => null, 'dest' => null, 'user_is_watching' => null, 't' => array()),
+ ),
'watcher_help_page' => array(
'arguments' => array('content' => null),
),
@@ -264,6 +306,16 @@
}
/**
+ * Implementation of hook_link().
+ */
+function watcher_link($type, $object, $teaser = FALSE) {
+ global $user;
+ if ($type == 'node' && _watcher_menu_access_toggle_watching_post($user) && _watcher_node_type_enabled($object)) {
+ return _watcher_node_watch_link($object, $teaser, null);
+ }
+}
+
+/**
* Implementation of hook_menu().
*/
function watcher_menu() {
@@ -725,6 +777,34 @@
'#collapsed' => true,
);
+ $form['togglelink']['watcher_toggle_link_disabled_text'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Link text when node is not being watched'),
+ '#default_value' => variable_get('watcher_toggle_link_disabled_text', t('You are not watching this post, click to start watching')),
+ '#size' => 50,
+ '#maxlength' => 100,
+ );
+
+ $form['togglelink']['watcher_toggle_link_enabled_text'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Link text when node is being watched'),
+ '#description' => t('If your site uses many languages, both these strings can be translated to languages other than the default by using the locale module.'),
+ '#default_value' => variable_get('watcher_toggle_link_enabled_text', t('You are watching this post, click to stop watching')),
+ '#size' => 50,
+ '#maxlength' => 100,
+ );
+
+ $form['togglelink']['watcher_toggle_link_position'] = array(
+ '#type' => 'radios',
+ '#title' => t('Where should "watch this post" toggle links be inserted on each node?'),
+ '#description' => t('This setting applies for both full page view and teasers (if the "display in teasers" option is checked).'),
+ '#options' => array(
+ 'body' => t('At the bottom of the node body'),
+ 'links' => t('In the node links section'),
+ ),
+ '#default_value' => variable_get('watcher_toggle_link_position', 'body'),
+ );
+
$form['togglelink']['watcher_toggle_link_in_teaser'] = array(
'#type' => 'checkbox',
'#title' => t('Display "watch this post" toggle link in teasers.'),
@@ -2172,9 +2252,9 @@
// Make localized strings
$tstrings = array();
- $tstrings['watch_toggle_enabled'] = t('You are watching this post, click to stop watching');
+ $tstrings['watch_toggle_enabled'] = variable_get('watcher_toggle_link_enabled_text', t('You are watching this post, click to stop watching'));
$tstrings['watch_toggle_enabled_title'] = t('This post is being watched. You can track and change email notification setting for this post in your watched posts list (see your user profile)');
- $tstrings['watch_toggle_disabled'] = t('You are not watching this post, click to start watching');
+ $tstrings['watch_toggle_disabled'] = variable_get('watcher_toggle_link_disabled_text', t('You are not watching this post, click to start watching'));
$tstrings['watch_toggle_disabled_title'] = t('Watch posts to be notified when other users comment on them or the posts are changed');
// Build link to the user's list of watched posts
@@ -2198,6 +2278,12 @@
// Add CSS
drupal_add_css(drupal_get_path('module', 'watcher') .'/css/watcher.css');
+ $position = variable_get('watcher_toggle_link_position', 'body');
+ if ($position == 'links') {
+ // Add toggle element to links array
+ return array( 'watcher' => theme('watcher_node_links_toggle_watching_link', $user->uid, $node->nid, $dest, $watching, $tstrings) );
+ }
+ else {
//Add element to node
$node->content['watcher'] = array(
'#value' => theme('watcher_node_toggle_watching_link', $user->uid, $node->nid, $dest, $watching, $tstrings),
@@ -2205,6 +2291,8 @@
);
}
+}
+
/**
* Save user settings for Watcher
*
#11
will this be included in next release?
#12
Patch against 6.x-1.4 attached.
It also contains a fix for #937894: Watcher always sends notifications after updating published comments as we needed it.
#13
Thank you. How would I apply this patch? The usual
Linux command "patch < patchfile" will not take it.
#14
Strange it may be my IDE's fault (I created it using NetBeans). Just eyeballing it the format looks fine.
Try removing the first 2 comment lines at the start?
#15
I see. It's just the filename that is missing in the header. The background image gets scrambled in Garland, as per attachment. Apart from that (not a problem for me, I removed the bg image in anyway) the patch works nicely. Thank you.
#16
Ah yes see my original post #1 up top - you can use some css to stop that happening.
#17
Thanks for your patch, apart from the css issue it worked like a charm!
#18
As this feature is included in the roadmap for version 6.x-1.x, could it be committed to dev?
Also, it would be nice to have a text only display blending in the node links line (as in flags module).
#19
Thank you as well! :)
Works in Dev version as well
#20
#21
I applied the patch from #12 and re-created it using
diff -up. Content of the patch is the same as in #12.#22
Any chance of this being committed before its 4th birthday?