Skip to content

Commit

Permalink
[TIMOB-6426] Added uric parser, Fixed canOpenURL() function
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindelusions committed Dec 3, 2011
1 parent 6c50486 commit a622d98
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions mobileweb/src/Ti.Platform/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,38 @@
set: function(val){return false;}
});


function _canOpenURL(str) {
var o = _canOpenURL.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
i = 14;

while (i--) uri[o.key[i]] = m[i] || "";

uri[o.q.name] = {};
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
if ($1) uri[o.q.name][$1] = $2;
});

return uri;
};

_canOpenURL.options = {
strictMode: false,
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
q: {
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?) (((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
};

_canOpenURL.options.strictMode = true;

// Methods
api.canOpenURL = function(url){
// Lots of stuff going on here. Basically we want to match any protocol urls ie: http, ftp, etc.
Expand Down

0 comments on commit a622d98

Please sign in to comment.