| 1 |
// $Id: active_tags.js,v 1.1 2008/09/12 08:31:03 darrenmuk Exp $
|
| 2 |
|
| 3 |
function activetags_activate(context) {
|
| 4 |
if ($(context).length == 1) {
|
| 5 |
var tagarea = activetags_widget(context);
|
| 6 |
$(context).before(tagarea);
|
| 7 |
Drupal.behaviors.autocomplete(document);
|
| 8 |
}
|
| 9 |
$('.add-tag:not(.tag-processed)').click(function() {
|
| 10 |
activetags_add(context, $(this).prev().val());
|
| 11 |
activetags_update(context);
|
| 12 |
$(this).prev().val('');
|
| 13 |
}).addClass('tag-processed');
|
| 14 |
|
| 15 |
if ($.browser.mozilla) {
|
| 16 |
$('.tag-entry:not(.tag-processed)').keypress(activetags_check_enter).addClass('tag-processed');
|
| 17 |
} else {
|
| 18 |
$('.tag-entry:not(.tag-processed)').keydown(activetags_check_enter).addClass('tag-processed');
|
| 19 |
}
|
| 20 |
|
| 21 |
jQuery.each($(context + ' input.form-text').attr('value').split(','), function (i, v) {
|
| 22 |
if (jQuery.trim(v) != '') {
|
| 23 |
activetags_add(context, v);
|
| 24 |
}
|
| 25 |
});
|
| 26 |
|
| 27 |
$(context).hide();
|
| 28 |
}
|
| 29 |
|
| 30 |
function activetags_check_enter(event) {
|
| 31 |
if (event.keyCode == 13) {
|
| 32 |
$('#autocomplete').each(function () {
|
| 33 |
this.owner.hidePopup();
|
| 34 |
})
|
| 35 |
$(this).next().click();
|
| 36 |
event.preventDefault();
|
| 37 |
return false;
|
| 38 |
}
|
| 39 |
}
|
| 40 |
|
| 41 |
function activetags_add(context, v) {
|
| 42 |
if (jQuery.trim(v) != '') {
|
| 43 |
$(context).prev().children('.tag-holder').append('<div class="tag-tag"><span class="tag-text">'+
|
| 44 |
jQuery.trim(v)+'</span><span class="remove-tag">x</span></div>');
|
| 45 |
$('.remove-tag:not(.tag-processed)').click(function() {
|
| 46 |
$(this).parent().remove();
|
| 47 |
activetags_update(context);
|
| 48 |
}).addClass('tag-processed');
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
| 52 |
function activetags_update(context) {
|
| 53 |
$(context).children('input.form-text').val('');
|
| 54 |
$(context).prev().children('.tag-holder').children().children('.tag-text').each(function(i) {
|
| 55 |
if(i==0) {
|
| 56 |
$(context).children('input.form-text').val($(this).text());
|
| 57 |
} else {
|
| 58 |
$(context).children('input.form-text').val(
|
| 59 |
$(context).children('input.form-text').val() + ', ' + $(this).text()
|
| 60 |
);
|
| 61 |
}
|
| 62 |
});
|
| 63 |
}
|
| 64 |
|
| 65 |
function activetags_widget(context) {
|
| 66 |
var vid = context.substr(20,1);
|
| 67 |
return '<div id="'+context+'-activetags" class="form-item">'+
|
| 68 |
'<label for="'+context+'-edit-tags">'+ $(context + ' label').text() +'</label>'+
|
| 69 |
'<div class="tag-holder"></div>'+
|
| 70 |
'<input type="text" class="tag-entry form-autocomplete" size="30" id="active-tag-edit0'+vid+'" />'+
|
| 71 |
'<input type="button" value="add" class="add-tag">'+
|
| 72 |
'<input class="autocomplete" type="hidden" id="active-tag-edit0'+vid+'-autocomplete" '+
|
| 73 |
'value="'+Drupal.settings.basePath+'taxonomy/autocomplete/'+vid+'" disabled="disabled" />'+
|
| 74 |
'</div>';
|
| 75 |
}
|
| 76 |
|
| 77 |
Drupal.behaviors.tagger = function (context) {
|
| 78 |
jQuery.each(Drupal.settings['active_tags'],function(i, v) {
|
| 79 |
if ($(v).length == 1) {
|
| 80 |
activetags_activate(v);
|
| 81 |
}
|
| 82 |
});
|
| 83 |
}
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|