diff --git a/index.html b/index.html index 685b63c..5013121 100644 --- a/index.html +++ b/index.html @@ -24,6 +24,7 @@ + diff --git a/js/Box.js b/js/Box.js index 0c7aebd..42999e4 100644 --- a/js/Box.js +++ b/js/Box.js @@ -25,8 +25,9 @@ function Box() { // create box dom element var link = (boxData.link)? boxData.link : url; + var linkElement = $(""+_self.wifiboxid+""); _element = $("
"); - _element.append(""+_self.wifiboxid+""); + _element.append(linkElement); _element.hide().appendTo(parentElement).fadeIn(500); // create network panel dom element diff --git a/js/libs/jquery.stayInWebApp.js b/js/libs/jquery.stayInWebApp.js new file mode 100644 index 0000000..f27c7f7 --- /dev/null +++ b/js/libs/jquery.stayInWebApp.js @@ -0,0 +1,44 @@ +/*! + * 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 ); \ No newline at end of file diff --git a/js/main.js b/js/main.js index ba3771d..2fc205a 100644 --- a/js/main.js +++ b/js/main.js @@ -62,6 +62,10 @@ $(function() { spinner.spin($preloader[0]); retrieveList(); + + // make sure all links are opened in same WebApp (added to homescreen) + // and they don't start a browser + $.stayInWebApp('a',true); }); function retrieveList() {