From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- includes/js/dojox/widget/FileInput.js | 75 +++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 includes/js/dojox/widget/FileInput.js (limited to 'includes/js/dojox/widget/FileInput.js') diff --git a/includes/js/dojox/widget/FileInput.js b/includes/js/dojox/widget/FileInput.js new file mode 100644 index 0000000..40cf58c --- /dev/null +++ b/includes/js/dojox/widget/FileInput.js @@ -0,0 +1,75 @@ +if(!dojo._hasResource["dojox.widget.FileInput"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.widget.FileInput"] = true; +dojo.provide("dojox.widget.FileInput"); +dojo.experimental("dojox.widget.FileInput"); + +dojo.require("dijit.form._FormWidget"); +dojo.require("dijit._Templated"); + +dojo.declare("dojox.widget.FileInput", + dijit.form._FormWidget, + { + // summary: A styled input type="file" + // + // description: A input type="file" form widget, with a button for uploading to be styled via css, + // a cancel button to clear selection, and FormWidget mixin to provide standard dijit.form.Form + // support (FIXME: maybe not fully implemented) + + // label: String + // the title text of the "Browse" button + label: "Browse ...", + + // cancelText: String + // the title of the "Cancel" button + cancelText: "Cancel", + + // name: String + // ugh, this should be pulled from this.domNode + name: "uploadFile", + + templateString:"
\n\t\n\t
\n\t\t\n\t\t
${label}
\n\t\t
${cancelText}
\n\t
\n
\n", + + startup: function(){ + // summary: listen for changes on our real file input + this._listener = dojo.connect(this.fileInput,"onchange",this,"_matchValue"); + this._keyListener = dojo.connect(this.fileInput,"onkeyup",this,"_matchValue"); + }, + + _matchValue: function(){ + // summary: set the content of the upper input based on the semi-hidden file input + this.inputNode.value = this.fileInput.value; + if(this.inputNode.value){ + this.cancelNode.style.visibility = "visible"; + dojo.fadeIn({ node: this.cancelNode, duration:275 }).play(); + } + }, + + setLabel: function(/* String */label,/* String? */cssClass){ + // summary: method to allow use to change button label + this.titleNode.innerHTML = label; + }, + + _onClick: function(/* Event */e){ + // summary: on click of cancel button, since we can't clear the input because of + // security reasons, we destroy it, and add a new one in it's place. + dojo.disconnect(this._listener); + dojo.disconnect(this._keyListener); + this.domNode.removeChild(this.fileInput); + dojo.fadeOut({ node: this.cancelNode, duration:275 }).play(); + + // should we use cloneNode()? can we? + this.fileInput = document.createElement('input'); + this.fileInput.setAttribute("type","file"); + this.fileInput.setAttribute("id",this.id); + this.fileInput.setAttribute("name",this.name); + dojo.addClass(this.fileInput,"dijitFileInputReal"); + this.domNode.appendChild(this.fileInput); + + this._keyListener = dojo.connect(this.fileInput,"onkeyup",this,"_matchValue"); + this._listener = dojo.connect(this.fileInput,"onchange",this,"_matchValue"); + this.inputNode.value = ""; + } + +}); + +} -- cgit v1.2.3