Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions MIT-license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013 Caleb Begly

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,25 @@ This use only links with the class `stay`.

Full links (starting with http) will still open in Safari, as well as links with `target="_blank"`.

To prevent an absolute link from opening in safari, add its domain to the absToStay array property of the options object like this:

$(function() {
var options = {
selector: "a.stay",
absToStay: Array("google.com","test.com","cats"), //allow google.com, test.com, and urls containing the word cats to stay.
};
$.stayInWebApp(options);
});

This can help if you have multiple subdomains eg, test.com, sub.test.com, othersub.test.com. All can be allowed by adding test.com to the array.
- - - - - - - - - -

Master code by [Joe Moses (mrmoses)](https://github.com/mrmoses).

Thanks to [Bryan Murdaugh and David Leininger](http://fivable.com) for the original starting script (mostly for discovering that self.location works).

Thanks to Ben Nadel for posting about how to [detect iOS full screen mode](http://www.bennadel.com/blog/1950-Detecting-iPhone-s-App-Mode-Full-Screen-Mode-For-Web-Applications.htm).
Thanks to Ben Nadel for posting about how to [detect iOS full screen mode](http://www.bennadel.com/blog/1950-Detecting-iPhone-s-App-Mode-Full-Screen-Mode-For-Web-Applications.htm).

Stay for certain absolute urls added by [Caleb R. Begly (techdude)](https://github.com/techdude)

Licensed under the MIT License - See [MIT-License.txt](MIT-license.txt)
48 changes: 33 additions & 15 deletions jquery.stayInWebApp.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,57 @@
/*!
* jQuery stayInWebApp Plugin
https://github.com/mrmoses/jQuery.stayInWebApp
* keeps all internal links in the webapp
* version: 0.4 (2012-06-19)
commits mmoses and techdude
*/

;(function($) {
(function($) {
//extend the jQuery object, adding $.stayInWebApp() as a function
$.extend({
stayInWebApp: function(selector) {
stayInWebApp: function(options) {
if(typeof options=="string"){ //we were not passed an object, but only a selector
//make object
options = {selector:options};
}
//detect iOS full screen mode
console.log(options);
if(("standalone" in window.navigator) && window.navigator.standalone) {
//if the selector is empty, default to all links
if(!selector) {
selector = 'a';
if(!options.selector) {
options.selector = 'a';
}
//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'));
}
*/

$(options.selector).click(function(event) {

//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");
var stay = false; //by default, we do not stay.

//if the destination is an absolute url, ignore it
if(!dest.match(/^http(s?)/g)) {
if(!dest.match(/^http(s?)/g)) { //local urls, keep
stay = true;

} else if(options.absToStay) { //if some absolute urls must stay


//loop throught urls and see if this is one of the ones we should keep
for(var i = 0; i < options.absToStay.length; i++){
if(dest.indexOf(options.absToStay[i]) > 0){
stay = true;
break;
}
}
}

if(stay){ //if we should stay for this url,
//prevent default behavior (opening safari)
event.preventDefault();
//update location of the web app
self.location = dest;
}


}
});
}
Expand Down
3 changes: 2 additions & 1 deletion jquery.stayInWebApp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.