Last active
January 28, 2016 07:45
-
-
Save caspahouzer/ef7280c653b9ea11430e to your computer and use it in GitHub Desktop.
Used for native functions within webviews in Appcelerator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
//select all a hrefs | |
$(document).on('click', 'a', function (e) { | |
if ($(this).attr('href').indexOf('http') !== -1) { | |
// prevent the default action of opening the link | |
e.preventDefault(); | |
// create the data element | |
var passData = { | |
action: 'openWindow', | |
url: ($(this).attr('href') !== '#') ? $(this).attr('href') : null, | |
title: $(this).html() | |
}; | |
// loop data attributes | |
$.each($(this).data(), function (name, value) { | |
passData[name] = value; | |
}); | |
if ($(this).attr('target') === '_blank') { | |
passData.action = 'openUrl'; | |
} | |
// Fire event for app listener | |
Ti.App.fireEvent(passData.action, passData); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Funktionen | |
openWindow | |
<a href="https://www.test.de/subpage.html" data-action="openWindow">Neues natives Fenster mit URL öffnen</a> | |
oder | |
<a href="#" data-action="openWindow" data-url="https://www.test.de/subpage.html">Neues natives Fenster mit URL öffnen</a> | |
Das data-action Attribut ist an dieser Stelle optional, da generell ALLE Urls erstmal über openWindow aufgerufen werden. | |
Optionale Parameter: | |
data-title string | |
Übergabe eines Titels, sonst wird <a>Text</a> genommen | |
data-modal bool | |
Soll das Fenster modal geöffnet werden? | |
data-modalStyle int | |
Angabe des Aussehens des modal Windows auf dem iPad (0-2) | |
0 = MODAL_PRESENTATION_FULLSCREEN | |
1 = MODAL_PRESENTATION_PAGESHEET | |
2 = MODAL_PRESENTATION_FORMSHEET | |
openUrl | |
<a href="https://www.test.de/subpage.html" data-action="openUrl">Öffne nativen Browser</a> | |
Öffnen einer Seite im nativen Browser des mobilen Gerätes. Es kann z.b. auch Telefonfunktion genutzt werden. In dem Fall als Url "tel:" benutzen | |
Optionale Parameter: | |
data-title (Übergabe eines Titels, sonst wird <a>Text</a> genommen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment