Skip to content

Commit

Permalink
[feature] stdlib: add Client.get_location()
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Heuzard committed Nov 18, 2011
1 parent 6644aca commit 336be65
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
39 changes: 39 additions & 0 deletions opabsl/jsbsl/bslClientOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
11 changes: 10 additions & 1 deletion stdlib/web/client/client.opa
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -148,7 +157,7 @@ type JsFunction = external
setInterval = %%BslClientOnly.setInterval%%
clearTimeout = %%BslClientOnly.clearTimeout%%
clearInterval = %%BslClientOnly.clearInterval%%

get_location = %%BslClientOnly.get_location%%
/*
* Deprecated zone: start
*/
Expand Down

0 comments on commit 336be65

Please sign in to comment.