javascriptRouter in IE6、7、8 Syntax Error!! #2092

Closed
yinyousong opened this Issue Nov 26, 2013 · 3 comments

Comments

Projects
None yet
3 participants
def javascriptRouter(name: String, ajaxMethod: Option[String], host: String, routes: JavascriptReverseRoute*): String = {
  """|var %s = {}; (function(_root){
         |var _nS = function(c,f,b){var e=c.split(f||"."),g=b||_root,d,a;for(d=0,a=e.length;d<a;d++){g=g[e[d]]=g[e[d]]||{}}return g}
         |var _qS = function(items){var qs = ''; for(var i=0;i<items.length;i++) {if(items[i]) qs += (qs ? '&' : '') + items[i]}; return qs ? ('?' + qs) : ''}
         |var _s = function(p,s){return p+((s===true||(s&&s.secure))?'s':'')+'://'}
         |var _wA = function(r){return {%s method:r.method,url:r.url,absoluteURL: function(s){return _s('http',s)+'%s'+r.url},webSocketURL: function(s){return _s('ws',s)+'%s'+r.url}}}
         |%s
         |})(%s)
      """.stripMargin.format(
    name,
    ajaxMethod.map("ajax:function(c){c=c||{};c.url=r.url;c.type=r.method;return " + _ + "(c)},").getOrElse(""),
    host,
    host,
    routes.map { route =>
      "_nS('%s'); _root.%s = %s".format(
        route.name.split('.').dropRight(1).mkString("."),
        route.name,
        route.f,
        route.name)
    }.mkString("\n"),
    name)
}

javascript code in IE 6 7 8 syntax error,the lost ';'

Collaborator

baloo commented Dec 13, 2013

Using zentask generated javascript router:

var jsRoutes = {}; (function(_root){
var _nS = function(c,f,b){var e=c.split(f||"."),g=b||_root,d,a;for(d=0,a=e.length;d<a;d++){g=g[e[d]]=g[e[d]]||{}}return g}
var _qS = function(items){var qs = ''; for(var i=0;i<items.length;i++) {if(items[i]) qs += (qs ? '&' : '') + items[i]}; return qs ? ('?' + qs) : ''}
var _s = function(p,s){return p+((s===true||(s&&s.secure))?'s':'')+'://'}
var _wA = function(r){return {ajax:function(c){c=c||{};c.url=r.url;c.type=r.method;return jQuery.ajax(c)}, method:r.method,type:r.method,url:r.url,absoluteURL: function(s){return _s('http',s)+'localhost:9000'+r.url},webSocketURL: function(s){return _s('ws',s)+'localhost:9000'+r.url}}}
_nS('controllers.Projects'); _root.controllers.Projects.add = 
      function() {
      return _wA({method:"POST", url:"/" + "projects"})
      }

_nS('controllers.Projects'); _root.controllers.Projects.delete = 
      function(project) {
      return _wA({method:"DELETE", url:"/" + "projects/" + (function(k,v) {return v})("project", project)})
      }

_nS('controllers.Projects'); _root.controllers.Projects.rename = 
      function(project) {
      return _wA({method:"PUT", url:"/" + "projects/" + (function(k,v) {return v})("project", project)})
      }

_nS('controllers.Projects'); _root.controllers.Projects.addGroup = 
      function() {
      return _wA({method:"POST", url:"/" + "projects/groups"})
      }

_nS('controllers.Projects'); _root.controllers.Projects.deleteGroup = 
      function(group) {
      return _wA({method:"DELETE", url:"/" + "projects/groups" + _qS([(function(k,v) {return encodeURIComponent(k)+'='+encodeURIComponent(v)})("group", group)])})
      }

_nS('controllers.Projects'); _root.controllers.Projects.renameGroup = 
      function(group) {
      return _wA({method:"PUT", url:"/" + "projects/groups" + _qS([(function(k,v) {return encodeURIComponent(k)+'='+encodeURIComponent(v)})("group", group)])})
      }

_nS('controllers.Projects'); _root.controllers.Projects.addUser = 
      function(project) {
      return _wA({method:"POST", url:"/" + "projects/" + (function(k,v) {return v})("project", project) + "/team"})
      }

_nS('controllers.Projects'); _root.controllers.Projects.removeUser = 
      function(project) {
      return _wA({method:"DELETE", url:"/" + "projects/" + (function(k,v) {return v})("project", project) + "/team"})
      }

_nS('controllers.Tasks'); _root.controllers.Tasks.addFolder = 
      function() {
      return _wA({method:"POST", url:"/" + "tasks/folder"})
      }

_nS('controllers.Tasks'); _root.controllers.Tasks.renameFolder = 
      function(project,folder) {
      return _wA({method:"PUT", url:"/" + "project/" + (function(k,v) {return v})("project", project) + "/tasks/folder" + _qS([(function(k,v) {return encodeURIComponent(k)+'='+encodeURIComponent(v)})("folder", folder)])})
      }

_nS('controllers.Tasks'); _root.controllers.Tasks.deleteFolder = 
      function(project,folder) {
      return _wA({method:"DELETE", url:"/" + "projects/" + (function(k,v) {return v})("project", project) + "/tasks/folder" + _qS([(function(k,v) {return encodeURIComponent(k)+'='+encodeURIComponent(v)})("folder", folder)])})
      }

_nS('controllers.Tasks'); _root.controllers.Tasks.index = 
      function(project) {
      return _wA({method:"GET", url:"/" + "projects/" + (function(k,v) {return v})("project", project) + "/tasks"})
      }

_nS('controllers.Tasks'); _root.controllers.Tasks.add = 
      function(project,folder) {
      return _wA({method:"POST", url:"/" + "projects/" + (function(k,v) {return v})("project", project) + "/tasks" + _qS([(function(k,v) {return encodeURIComponent(k)+'='+encodeURIComponent(v)})("folder", folder)])})
      }

_nS('controllers.Tasks'); _root.controllers.Tasks.update = 
      function(task) {
      return _wA({method:"PUT", url:"/" + "tasks/" + (function(k,v) {return v})("task", task)})
      }

_nS('controllers.Tasks'); _root.controllers.Tasks.delete = 
      function(task) {
      return _wA({method:"DELETE", url:"/" + "tasks/" + (function(k,v) {return v})("task", task)})
      }

})(jsRoutes)

It looks like ie is right, for once. It look like delete is a reserved word in javascript (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Reserved_Words) and it stops with an "unexpected identifier" on this.

Collaborator

baloo commented Dec 13, 2013

I'm not sure whether #2164 fixes the issue here. But there was a parsing error before commit in the PR and after, everything looks fine.

@baloo baloo pushed a commit to baloo/Play20 that referenced this issue Dec 13, 2013

Arthur Gautier [#2092] Fix js in ie 63b7d71

jroper added the ddd label Aug 21, 2014

Owner

jroper commented Aug 21, 2014

Due to the lack of response from the OP, I'm going to assume it did fix it.

jroper closed this Aug 21, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment