0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2024-12-27 02:53:48 +01:00
doodle3d-connect/js/libs/jquery.stayInWebApp.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

2014-02-28 13:56:51 +01:00
/*!
* jQuery stayInWebApp Plugin
* version: 0.4 (2012-06-19)
*/
;(function($) {
//extend the jQuery object, adding $.stayInWebApp() as a function
$.extend({
stayInWebApp: function(selector,includeAbsolute) {
//detect iOS full screen mode
if(("standalone" in window.navigator) && window.navigator.standalone) {
//if the selector is empty, default to all links
if(!selector) {
selector = 'a';
}
// ignore absolute links by default
if(!includeAbsolute) {
includeAbsolute = false;
}
//bind to the click event of all specified elements
$("body").delegate(selector,"click",function(event) {
//TODO: execute all other events if this element has more bound events
/* NEEDS TESTING
for(i = 0; i < $(this).data('events'); i++) {
console.log($(this).data('events'));
}
*/
//only stay in web app for links that are set to _self (or not set)
if($(this).attr("target") == undefined || $(this).attr("target") == "" || $(this).attr("target") == "_self") {
//get the destination of the link clicked
var dest = $(this).attr("href");
//if the destination is an absolute url, ignore it
if(!dest.match(/^http(s?)/g) || includeAbsolute) {
//prevent default behavior (opening safari)
event.preventDefault();
//update location of the web app
self.location = dest;
}
}
});
}
} //end stayInWebApp func
});
})( jQuery );