/[drupal]/contributions/modules/opencalais/calais.js
ViewVC logotype

Contents of /contributions/modules/opencalais/calais.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sun Apr 20 20:22:10 2008 UTC (19 months, 1 week ago) by febbraro
Branch: MAIN
CVS Tags: DRUPAL-6--1-4, DRUPAL-5--1-1, DRUPAL-5--1-0, DRUPAL-5--1-3, DRUPAL-5--1-2, DRUPAL-6--1-0, DRUPAL-6--1-1, DRUPAL-6--1-2, DRUPAL-6--1-3, DRUPAL-5--1-5, DRUPAL-5--1-4, HEAD
Branch point for: DRUPAL-5, DRUPAL-6--1, DRUPAL-6--2
Changes since 1.1: +66 -0 lines
File MIME type: text/javascript
initial checkin from phase2 repo
1
2 $(document).ready(function() {
3
4 $('.calais_keyword').click(function() {
5 var tags = $('#' + $(this).attr('for'));
6 var keyword = $(this).text();
7
8 // TODO: When we move to a revent jQuery, replace is() with hasClass()
9 if($(this).is('.calais_keyword_selected')) {
10 calaisRemoveKeyword(tags, keyword);
11 $(this).removeClass('calais_keyword_selected');
12 }
13 else {
14 calaisAddKeyword(tags, keyword);
15 $(this).addClass('calais_keyword_selected');
16 }
17
18 });
19
20 $('.calais_keyword').each( function() {
21 var tags = $('#' + $(this).attr('for'));
22 var keyword = $(this).text();
23
24 if (tags.val().indexOf(keyword) != -1) {
25 $(this).addClass('calais_keyword_selected');
26 }
27
28 });
29 });
30
31 /**
32 * Insert keyword, adding a comma if necessary
33 */
34 function calaisAddKeyword(tags, keyword) {
35 var current = $.trim(tags.val());
36 if(current.indexOf(keyword) == -1) {
37 if(current == '') {
38 tags.val(keyword);
39 }
40 else{
41 tags.val(current + ',' + keyword);
42 }
43 }
44 }
45
46 /**
47 * Remove the keyword and cleanup any comma nonsense
48 */
49 function calaisRemoveKeyword(tags, keyword) {
50 var current = $.trim(tags.val());
51 var index = current.indexOf(keyword);
52 if(index >= 0) {
53 // Deal with funky spaces around commas
54 current = current.replace(/ +,/, ',');
55 current = current.replace(/, +/, ',');
56
57 // Remove the keyword
58 current = current.replace(keyword, '');
59
60 // Deal with a remaining extra comma
61 current = current.replace(/^,/, '');
62 current = current.replace(/,$/, '');
63 current = current.replace(/,,/, ',');
64 tags.val(current);
65 }
66 }

  ViewVC Help
Powered by ViewVC 1.1.2