Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added noscript support

  • Loading branch information...
commit 16009d7cc2deb0c981dbe01e622e70bbae7c1d3d 1 parent 3652c9b
Antony Jones authored
View
44 grails-app/taglib/uk/co/desirableobjects/ajaxuploader/AjaxUploaderTagLib.groovy
@@ -7,6 +7,8 @@ import uk.co.desirableobjects.ajaxuploader.exception.InvalidAttributeValueExcept
class AjaxUploaderTagLib {
String currentUploaderUid = null
+ StringWriter htmlOut = new StringWriter()
+ StringWriter jsOut = new StringWriter()
static final Map<String, List<String>> REQUIRED_ATTRIBUTES = [
id: []
@@ -50,16 +52,10 @@ class AjaxUploaderTagLib {
currentUploaderUid = attrs.id
- out << """
- <div id="au-${currentUploaderUid}">
- <noscript>
- <p>Please enable JavaScript to use file uploader.</p>
- </noscript>
- </div>
- """
-
String url = attrs.url ? createLink(attrs) : resource(dir:'ajaxUpload',file:'upload')
+ body()
+
out << g.javascript([:], """
var au_${currentUploaderUid} = new qq.FileUploader({
element: document.getElementById('au-${currentUploaderUid}'),
@@ -69,12 +65,20 @@ class AjaxUploaderTagLib {
doAttributes(attrs)+
doParamsBlock(attrs)+
- body()+
+ jsOut.toString()+
"""
});
""")
+ out << """
+ <div id="au-${currentUploaderUid}">
+ <noscript>
+ ${htmlOut}
+ </noscript>
+ </div>
+ """
+
currentUploaderUid = null
}
@@ -148,8 +152,9 @@ class AjaxUploaderTagLib {
def onComplete = { attrs, body ->
validateCallState()
- out << """,
+ jsOut << """,
onComplete: function(id, fileName, responseJSON) { ${body()} }"""
+ return ''
}
@@ -162,32 +167,43 @@ onComplete: function(id, fileName, responseJSON) { ${body()} }"""
def onSubmit = { attrs, body ->
validateCallState()
- out << """,
+ jsOut << """,
onSubmit: function(id, fileName) { ${body()} }"""
+ return ''
}
def onProgress = { attrs, body ->
validateCallState()
- out << """,
+ jsOut << """,
onProgress: function(id, fileName, loaded, total) { ${body()} }"""
+ return ''
}
def onCancel = { attrs, body ->
validateCallState()
- out << """,
+ jsOut << """,
onCancel: function(id, fileName) { ${body()} }"""
+ return ''
}
def showMessage = { attrs, body ->
validateCallState()
- out << """,
+ jsOut << """,
showMessage: function(message) { ${body()} }"""
+ return ''
+
+ }
+
+ def noScript = { attrs, body ->
+
+ htmlOut << "${body()}"
+ return ''
}
View
6 test/unit/uk/co/desirableobjects/ajaxuploader/AjaxUploaderTagLibTests.groovy
@@ -224,7 +224,6 @@ class AjaxUploaderTagLibTests extends TagLibUnitTestCase {
}
- /** Not until 0.3
void testNoScriptBlock() {
final String NOSCRIPT_BLOCK = "<h1>No JS!?</h1>"
@@ -233,10 +232,11 @@ class AjaxUploaderTagLibTests extends TagLibUnitTestCase {
{ return tagLib.noScript([:], { return NOSCRIPT_BLOCK }) }
)
- assertContains "<noscript>${NOSCRIPT_BLOCK}</noscript>"
+ assertContains """<noscript>
+ ${NOSCRIPT_BLOCK}
+ </noscript>"""
}
- **/
private assertContains(String expected) {
assert tagLib.out.toString().contains(expected)
Please sign in to comment.
Something went wrong with that request. Please try again.