2011年8月25日 星期四

Titanium WebView

Goal: Use Titanium WebView to open a HTML5 file. Upon selection of text inside HTML, highlight and popup a dictionary menu instead of default Copy menu.

Solution 1:
Use webview.addEventListener('click|dblclick|doubletap', function(e)) to capture the touch event, it will override the touch event on HTML itself. i.e. the text selection highlight will be disabled.
 => Unable to get text selection (INFEASIBLE)

P.S. webview's eventListener will capture touch event prior to Javascript's eventHandler: $(document).bind('touchend', function(e)) in HTML

Solution 2:
Use javascript to get selected text:
      var selectedText = window.getSelection().toString();
and show the dictionary popup menu using jquery plugin: TipTip ( http://code.drewwilson.com/entry/tiptip-jquery-plugin )
 => "Copy" menu still appear (Comparatively feasible)

Solution 3:
Fire Titanium app event, e.g. button click, to evaluate HTML page's javascript:
       var selectedText = webview.evalJS("window.getSelection().toString()");

The core of Safari browser is using Webkit engine. So may also make use of the webkit CSS to control browser behavior.

    

沒有留言:

張貼留言