Browse files

[feature] stdlib: add Client.get_location()

  • Loading branch information...
1 parent 6644aca commit 336be657d36977a5d47f75e175aaafcc13d160bd Hugo Heuzard committed Nov 18, 2011
Showing with 49 additions and 1 deletion.
  1. +39 −0 opabsl/jsbsl/bslClientOnly.js
  2. +10 −1 stdlib/web/client/client.opa
View
39 opabsl/jsbsl/bslClientOnly.js
@@ -20,6 +20,7 @@
##extern-type style_constructor
##extern-type insertion_handlers
##extern-type dom_element
+##extern-type Client.location
##extern-type Dom.event
##extern-type dom
##extern-type Xhtml.private_dom_element_list
@@ -418,3 +419,41 @@ function getStableCookie()
if (tmp != null) return js_some(tmp[1]);
return js_none;//What does this case cover, exactly?
}
+
+##register get_location : -> Client.location
+##args()
+{
+ var host = "";
+ var hostname = "";
+ var href = "";
+ var origin = "";
+ var pathname = "";
+ var protocol = "";
+ var port = "";
+ if(window && window.location){
+ var l = window.location;
+ if(l.host) host=l.host;
+ if(l.hostname) hostname=l.hostname;
+ if(l.href) href=l.href;
+ if(l.origin) origin=l.origin;
+ if(l.pathname) pathname=l.pathname;
+ if(l.port) port = l.port;
+ if(l.protocol) protocol = l.protocol;
+ }
+ var fhost = static_field_of_name("host");
+ var fhostname = static_field_of_name("hostname");
+ var fhref = static_field_of_name("href");
+ var forigin = static_field_of_name("origin");
+ var fpathname = static_field_of_name("pathname");
+ var fprotocol = static_field_of_name("protocol");
+ var fport = static_field_of_name("port");
+ var r = empty_constructor();
+ r = add_field(r,fhost,host);
+ r = add_field(r,fhostname,hostname);
+ r = add_field(r,fhref,href);
+ r = add_field(r,forigin,origin);
+ r = add_field(r,fpathname,pathname);
+ r = add_field(r,fprotocol,protocol);
+ r = add_field(r,fport,port);
+ return r;
+}
View
11 stdlib/web/client/client.opa
@@ -16,6 +16,15 @@
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
@abstract type Client.Anchor.handler = -> void
+type Client.location = {
+ host : string
+ hostname : string
+ href : string
+ origin : string
+ pathname : string
+ port : string
+ protocol : string
+}
type position = {x:int y:int} // FIXME: MOVE or KILL
@@ -148,7 +157,7 @@ type JsFunction = external
setInterval = %%BslClientOnly.setInterval%%
clearTimeout = %%BslClientOnly.clearTimeout%%
clearInterval = %%BslClientOnly.clearInterval%%
-
+ get_location = %%BslClientOnly.get_location%%
/*
* Deprecated zone: start
*/

0 comments on commit 336be65

Please sign in to comment.