[TxMt] HTML output window: JavaScrip alert() and confirm()

Hans-Jörg Bibiko bibiko at eva.mpg.de
Thu Sep 25 10:04:53 UTC 2008


Hi,

up to now it is not possible to use the JavaScript functions alert()  
and confirm() within TM's HTML output window.

But there is a solution (unfortunately this does not work for the HTML  
preview :( ).

The only thing I do is to write a kind of wrapper for these functions  
by using TextMate.system('"$DIALOG" -e ...').

<script type="text/javascript" charset="utf-8">
     try {
         if (TextMate.system("", function (task) { })) {
             var __TM_confirm_Status;
             alert = function(s){TextMate.system('"$DIALOG" -e -p  
\'{messageTitle="JavaScript";informativeText="'+s+'";}\'',null);};
             confirm = function(s){TextMate.system('"$DIALOG" -e -p  
\'{messageTitle="JavaScript";informativeText="'+s 
+'";buttonTitles=("OK","Cancel");}\'',null).onreadoutput=function(s) 
{if(s==1) 
{__TM_confirm_Status 
=false}else{__TM_confirm_Status=true}};return(__TM_confirm_Status)};
         }
     } catch(e) {}
</script>

The try block will be only executed if the code will be showed up in  
TM HTML output window.

If you put these lines into your HTML code the page will work within a  
normal browser as well as in TM's HTML output window.

Attached is a demo command. Simply press the buttons ;)

BTW With this approach I can prompt JavaScript errors by using simply  
"alert(err)" inside of TM ;)

--Hans


-------------- next part --------------
A non-text attachment was scrubbed...
Name: JSAlertAndConfirm.tmCommand
Type: application/octet-stream
Size: 1848 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20080925/9ca7c9c1/attachment.tmCommand>
-------------- next part --------------



More information about the textmate mailing list