Skip to content

Commit

Permalink
Added noscript support
Browse files Browse the repository at this point in the history
  • Loading branch information
Antony Jones committed Apr 21, 2011
1 parent 3652c9b commit 16009d7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
Expand Up @@ -7,6 +7,8 @@ import uk.co.desirableobjects.ajaxuploader.exception.InvalidAttributeValueExcept
class AjaxUploaderTagLib { class AjaxUploaderTagLib {


String currentUploaderUid = null String currentUploaderUid = null
StringWriter htmlOut = new StringWriter()
StringWriter jsOut = new StringWriter()


static final Map<String, List<String>> REQUIRED_ATTRIBUTES = [ static final Map<String, List<String>> REQUIRED_ATTRIBUTES = [
id: [] id: []
Expand Down Expand Up @@ -50,16 +52,10 @@ class AjaxUploaderTagLib {


currentUploaderUid = attrs.id 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') String url = attrs.url ? createLink(attrs) : resource(dir:'ajaxUpload',file:'upload')


body()

out << g.javascript([:], """ out << g.javascript([:], """
var au_${currentUploaderUid} = new qq.FileUploader({ var au_${currentUploaderUid} = new qq.FileUploader({
element: document.getElementById('au-${currentUploaderUid}'), element: document.getElementById('au-${currentUploaderUid}'),
Expand All @@ -69,12 +65,20 @@ class AjaxUploaderTagLib {
doAttributes(attrs)+ doAttributes(attrs)+
doParamsBlock(attrs)+ doParamsBlock(attrs)+


body()+ jsOut.toString()+


""" """
}); });
""") """)


out << """
<div id="au-${currentUploaderUid}">
<noscript>
${htmlOut}
</noscript>
</div>
"""

currentUploaderUid = null currentUploaderUid = null
} }


Expand Down Expand Up @@ -148,8 +152,9 @@ class AjaxUploaderTagLib {
def onComplete = { attrs, body -> def onComplete = { attrs, body ->


validateCallState() validateCallState()
out << """, jsOut << """,
onComplete: function(id, fileName, responseJSON) { ${body()} }""" onComplete: function(id, fileName, responseJSON) { ${body()} }"""
return ''


} }


Expand All @@ -162,32 +167,43 @@ onComplete: function(id, fileName, responseJSON) { ${body()} }"""
def onSubmit = { attrs, body -> def onSubmit = { attrs, body ->


validateCallState() validateCallState()
out << """, jsOut << """,
onSubmit: function(id, fileName) { ${body()} }""" onSubmit: function(id, fileName) { ${body()} }"""
return ''


} }


def onProgress = { attrs, body -> def onProgress = { attrs, body ->


validateCallState() validateCallState()
out << """, jsOut << """,
onProgress: function(id, fileName, loaded, total) { ${body()} }""" onProgress: function(id, fileName, loaded, total) { ${body()} }"""
return ''


} }


def onCancel = { attrs, body -> def onCancel = { attrs, body ->


validateCallState() validateCallState()
out << """, jsOut << """,
onCancel: function(id, fileName) { ${body()} }""" onCancel: function(id, fileName) { ${body()} }"""
return ''


} }


def showMessage = { attrs, body -> def showMessage = { attrs, body ->


validateCallState() validateCallState()
out << """, jsOut << """,
showMessage: function(message) { ${body()} }""" showMessage: function(message) { ${body()} }"""
return ''

}

def noScript = { attrs, body ->

htmlOut << "${body()}"
return ''


} }


Expand Down
Expand Up @@ -224,7 +224,6 @@ class AjaxUploaderTagLibTests extends TagLibUnitTestCase {


} }


/** Not until 0.3
void testNoScriptBlock() { void testNoScriptBlock() {


final String NOSCRIPT_BLOCK = "<h1>No JS!?</h1>" final String NOSCRIPT_BLOCK = "<h1>No JS!?</h1>"
Expand All @@ -233,10 +232,11 @@ class AjaxUploaderTagLibTests extends TagLibUnitTestCase {
{ return tagLib.noScript([:], { return NOSCRIPT_BLOCK }) } { return tagLib.noScript([:], { return NOSCRIPT_BLOCK }) }
) )


assertContains "<noscript>${NOSCRIPT_BLOCK}</noscript>" assertContains """<noscript>
${NOSCRIPT_BLOCK}
</noscript>"""


} }
**/


private assertContains(String expected) { private assertContains(String expected) {
assert tagLib.out.toString().contains(expected) assert tagLib.out.toString().contains(expected)
Expand Down

0 comments on commit 16009d7

Please sign in to comment.