/[drupal]/contributions/modules/topichubs/topichubs.js
ViewVC logotype

Contents of /contributions/modules/topichubs/topichubs.js

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


Revision 1.1 - (show annotations) (download) (as text)
Tue Mar 3 23:53:11 2009 UTC (8 months, 3 weeks ago) by febbraro
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Branch point for: DRUPAL-6--1, DRUPAL-6--2
File MIME type: text/javascript
initial import from svn
1
2 Drupal.behaviors.topichub = function (context) {
3
4 // Display term select for chosen vocab
5 $("#vocabulary-selector:not(.topichubs-processed)").each(function() {
6 $(this).change(function(){
7 var vid = $(this).val();
8 if(vid != "") {
9 $(".topichub-term-selector").hide();
10 $("#terms-" + vid + "-selector-wrapper").show();
11 }
12 });
13 $(this).addClass('topichubs-processed');
14 });
15
16 // Add selected term to the specified condition
17 $("#topichub-add-term:not(.topichubs-processed)").each(function(){
18 $(this).click(function(){
19 var vid = $("#vocabulary-selector").val();
20 if(vid != "") {
21 var vocab = $("#vocabulary-selector option:selected").text();
22 var tid = $("#term-" + vid + "-selector").val();
23 var term = $("#term-" + vid + "-selector option:selected").text();
24 var condition = $("#condition-selector").val();
25
26 // Add Label and delete image
27 var termSpan = document.createElement("span");
28 $(termSpan).addClass('condition-term');
29 $(termSpan).append(vocab + ": <span class='term-name'>" + term + '</span>');
30
31 var remove = document.createElement("a");
32 $(remove).addClass("topichub-term-remove");
33 $(remove).attr({
34 href: "javascript:void(0);",
35 title: "Remove",
36 tid: tid,
37 condition: condition,
38 });
39 $(remove).html(Drupal.settings.topichubs.delete_img[0]);
40 $(termSpan).append(remove);
41
42 // Add to hidden
43 var terms = $("#conditions-" + condition).val();
44 if(terms == "") {
45 terms = tid;
46 }
47 else {
48 terms += "," + tid;
49 $(termSpan).prepend("<span class='operator'>AND</span>");
50 }
51 $("#conditions-" + condition).val(terms);
52 $("#condition-wrapper-" + condition).append(termSpan);
53 Drupal.attachBehaviors(termSpan);
54 return false;
55 }
56 });
57 $(this).addClass('topichubs-processed');
58 });
59
60 $("a.topichub-term-remove:not(.topichubs-processed)").each(function(){
61 $(this).click(function() {
62 var tid = $(this).attr('tid');
63 var condition = $(this).attr('condition');
64 var terms = $("#conditions-" + condition).val();
65
66 if(terms.indexOf(',') == -1) {
67 termsArray = new Array(terms);
68 }
69 else {
70 termsArray = terms.split(",");
71 }
72
73 for(index in termsArray) {
74 if(termsArray[index] == tid) {
75 termsArray.splice(index, 1);
76 break;
77 }
78 index++;
79 }
80 $("#conditions-" + condition).val(termsArray.join(','));
81
82 // Remove from the UI
83 $(this).parent("span.condition-term").remove();
84
85 // Remove leading AND if one exists.
86 var firstChildInSpan = $("#condition-wrapper-" + condition + " span:first span:first-child");
87 if($(firstChildInSpan).hasClass('operator')) {
88 $(firstChildInSpan).remove();
89 }
90 });
91 $(this).addClass('topichubs-processed');
92 });
93
94 // UI for Plugin Settings
95 $("div.plugin-label:not(.topichubs-processed)").each(function(){
96 if($(this).is(':first-child')) {
97 $(this).addClass('plugin-label-active');
98 }
99 $(this).click(function() {
100 var id = $(this).attr('id');
101 $("div.plugin-settings").hide();
102 $("#" + id + "-form").show();
103 $("div.plugin-label").removeClass('plugin-label-active');
104 $(this).addClass('plugin-label-active');
105 });
106 $(this).addClass('topichubs-processed');
107 });
108
109 $("div.plugin-settings:not(.topichubs-processed)").each(function(){
110 if(!$(this).is(':first-child')) {
111 $(this).hide();
112 }
113 $(this).addClass('topichubs-processed');
114 });
115
116 };

  ViewVC Help
Powered by ViewVC 1.1.2