Skip to content

Instantly share code, notes, and snippets.

@kbshl
Created October 15, 2014 11:23
Show Gist options
  • Save kbshl/539d6136d43616586628 to your computer and use it in GitHub Desktop.
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
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>');
<?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