// $Id: upload.js,v 1.8.2.1 2006/05/05 11:57:19 killes Exp $ // Global killswitch if (isJsEnabled()) { addLoadEvent(weblinkerAutoAttach); } /** * Attaches the AJAX behaviour to links on the edit page. */ function weblinkerAutoAttach() { var a_tags = document.getElementsByTagName('a'); for (i = 0; a_tag = a_tags[i]; i++) { if (a_tag && hasClass(a_tag, 'weblinker-target')) { var uri = "/node/add/weblinks/mini-form"; var href = a_tag.href; var text = a_tag.innerHTML; var id = a_tag.id; var button_id = id+'-button'; var wrapper_id = id+'-wrapper'; var weblinkerHandler = new jsWeblinker(uri, button_id, wrapper_id, text, href); } } /* $('table.weblinker-summary tr').each( function(){ alert(this); }); */ } /** * JS Weblinker object. */ function jsWeblinker(uri, button_id, wrapper_id, text, href) { this.button = $(button_id); this.uri = uri; this.text = text; this.href = href; this.wrapper = $(wrapper_id); var weblinkerHandler = this; if(this.button){ this.button.onclick=function(event) { // inside this func, the current weblinker properties should be available in scope? var button = this; // replace self with the inline form wrapper = weblinkerHandler.wrapper; wrapper.innerHTML = ""; wrapper.setAttribute('style','border:1px dotted blue;display:block;height:40px;padding:1em'); // Insert progressbar and stretch to take the same space. this.progress = new progressBar('uploadprogress'); this.progress.setProgress(-1, 'Preparing form'); this.progress.element.style.width = '28em'; this.progress.element.style.height = wrapper.offsetHeight +'px'; wrapper.appendChild(this.progress.element); // start the fetch get_string = weblinkerHandler.uri ; get_string += '/?edit[url]='+ encodeURIComponent(href); get_string += '&edit[title]='+ encodeURIComponent(text); get_string += '&edit[parent_nid]='+ drupal_nid; this.transport = HTTPGet(get_string , weblinkerHandler.receive, weblinkerHandler); } } } /** * HTTP callback function. * displays the mini edit form inline */ jsWeblinker.prototype.receive = function (data, xmlHttp, weblinkerHandler) { // Remove progressbar // removeNode(weblinkerHandler.progress.element); weblinkerHandler.progress = null; // Replace form and re-attach behaviour weblinkerHandler.wrapper.setAttribute('style','border:2px dotted blue;display:block;padding:1em'); weblinkerHandler.wrapper.innerHTML = data; } function show_weblink_form(url,text,element){ alert(this); } /** * Handler for the form redirection submission. */ jsWeblinker.prototype.onsubmit = function () { var hide = $(this.hide); // Insert progressbar and stretch to take the same space. this.progress = new progressBar('uploadprogress'); this.progress.setProgress(-1, 'Uploading file'); this.progress.element.style.width = '28em'; this.progress.element.style.height = hide.offsetHeight +'px'; hide.parentNode.insertBefore(this.progress.element, hide); // Hide file form (cannot use display: none, this mysteriously aborts form // submission in Konqueror) hide.style.position = 'absolute'; hide.style.left = '-2000px'; } /** * Handler for the form redirection completion. */ jsWeblinker.prototype.oncomplete = function (data) { // Remove progressbar removeNode(this.progress.element); this.progress = null; // Replace form and re-attach behaviour $(this.wrapper).innerHTML = data; uploadAutoAttach(); } /** * Handler for the form redirection error. */ jsWeblinker.prototype.onerror = function (error) { alert('An error occurred:\n\n'+ error); // Remove progressbar removeNode(this.progress.element); this.progress = null; // Undo hide $(this.hide).style.position = 'static'; $(this.hide).style.left = '0px'; }