Created
October 15, 2014 11:23
-
-
Save kbshl/539d6136d43616586628 to your computer and use it in GitHub Desktop.
Convert HTML Links to Titanium Mobile App Links that fire Ti.App.Events
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
var convertedHTML = htmlString; | |
// event-handler for app | |
convertedHTML = htmlString.replace(/<a href="((http|https)[^"]+)"[^>]*>(.*?)<\/a>/gmi, '<a href="$1" onclick="Ti.App.fireEvent(\'app:webViewClick\', {link: \'$1\'}); return false;">$3</a>'); | |
// mailto special | |
convertedHTML = convertedHTML.replace(/<a href="mailto:([^"]+)"[^>]*>(.*?)<\/a>/gmi, '<a href="mailto:$1" onclick="Ti.App.fireEvent(\'app:webViewClick\', {linkType: \'email\', link: \'$1\'}); return false;">$2</a>'); |
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
<?php | |
// Event-Handler für Titanium-Framework | |
$sText = preg_replace('~<a href="((http|https)[^"]+)"[^>]*>(.*?)</a>~si', '<a href="\\1" onclick="Ti.App.fireEvent(\'app:webViewClick\', {link: \'\\1\'}); return false;">\\3</a>', $sText); | |
// mailto spezial | |
$sText = preg_replace('~<a href="mailto:([^"]+)"[^>]*>(.*?)</a>~si', '<a href="mailto:\\1" onclick="Ti.App.fireEvent(\'app:webViewClick\', {email: \'\\1\'}); return false;">\\2</a>', $sText); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment