1 var tagCreation = window.tagCreation;
6 'addTagFromSlug': function(triggeringLink) {
7 var id = triggeringLink.id.replace(/^ajax_add_/, '') + '_input';
8 var slug = document.getElementById(id).value;
10 var name = slug.split(' ');
11 for(var i=0;i<name.length;i++) {
12 name[i] = name[i].substr(0,1).toUpperCase() + name[i].substr(1);
14 name = name.join(' ');
15 slug = name.toLowerCase().replace(/ /g, '-').replace(/[^\w-]/g, '');
17 var href = triggeringLink.href;
22 $.post(href, data, function(data){
23 newId = html_unescape(data.pk);
24 newRepr = html_unescape(data.unicode);
25 var toId = id.replace(/_input$/, '_to');
26 elem = document.getElementById(toId);
27 var o = new Option(newRepr, newId);
28 SelectBox.add_to_cache(toId, o);
29 SelectBox.redisplay(toId);
32 'init': function(id) {
33 tagCreation.cache[id] = {}
34 var input = tagCreation.cache[id].input = document.getElementById(id + '_input');
35 var select = tagCreation.cache[id].select = document.getElementById(id + '_from');
36 var addLinkTemplate = document.getElementById('add_' + input.id.replace(/_input$/, '')).cloneNode(true);
37 var addLink = tagCreation.cache[id].addLink = document.createElement('A');
38 addLink.id = 'ajax_add_' + id;
39 addLink.className = addLinkTemplate.className;
40 addLink.href = addLinkTemplate.href;
41 addLink.appendChild($(addLinkTemplate).children()[0].cloneNode(false));
42 addLink.innerHTML += " <span style='vertical-align:text-top;'>Add this tag</span>"
43 addLink.style.marginLeft = "20px";
44 addLink.style.display = "block";
45 addLink.style.backgroundPosition = "10px 5px";
46 addLink.style.width = "120px";
47 $(input).after(addLink);
48 if (window.grappelli) {
49 addLink.parentNode.style.backgroundPosition = "6px 8px";
51 addLink.style.marginTop = "5px";
53 tagCreation.toggleButton(id);
54 addEvent(input, 'keyup', function() {
55 tagCreation.toggleButton(id);
57 addEvent(addLink, 'click', function(e) {
59 tagCreation.addTagFromSlug(addLink);
62 'toggleButton': function(id) {
63 var addLink = tagCreation.cache[id].addLink;
64 var select = $(tagCreation.cache[id].select);
65 if (select[0].options.length == 0) {
66 if (addLink.style.display == 'none') {
67 addLink.style.display = 'block';
68 select.height(select.height() - $(addLink).outerHeight(false))
71 if (addLink.style.display == 'block') {
72 select[0].style.height = null;
73 addLink.style.display = 'none';