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
<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>
I do not know if TM 2.0 supports this, but this could be sent by TM automatically if an user will show up something as HTMLoutput (?)
--Hans
On Sep 25, 2008, at 12:29 PM, Hans-Jörg Bibiko wrote:
<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>
I do not know if TM 2.0 supports this, but this could be sent by TM automatically if an user will show up something as HTMLoutput (?)
at the very least we can add it to the HTMLOutput.show command and web_preview. This would take care of 99% of the cases. For other commands, they can do without.
—Alex
On 25.09.2008, at 12:46, Alex Ross wrote:
On Sep 25, 2008, at 12:29 PM, Hans-Jörg Bibiko wrote:
<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>
I do not know if TM 2.0 supports this, but this could be sent by TM automatically if an user will show up something as HTMLoutput (?)
at the very least we can add it to the HTMLOutput.show command and web_preview. This would take care of 99% of the cases. For other commands, they can do without.
Well, I would say 97% because I use these functions rarely but it would be a step into the right direction ;)
--Hans
On Sep 25, 2008, at 1:07 PM, Hans-Jörg Bibiko wrote:
On 25.09.2008, at 12:46, Alex Ross wrote:
On Sep 25, 2008, at 12:29 PM, Hans-Jörg Bibiko wrote:
<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>
I do not know if TM 2.0 supports this, but this could be sent by TM automatically if an user will show up something as HTMLoutput (?)
at the very least we can add it to the HTMLOutput.show command and web_preview. This would take care of 99% of the cases. For other commands, they can do without.
Well, I would say 97% because I use these functions rarely but it would be a step into the right direction ;)
If you are dumping anything to the html output window, then you should be using HTMLOutput.show or at least web_preview… :)
—Alex
On 25.09.2008, at 13:17, Alex Ross wrote:
at the very least we can add it to the HTMLOutput.show command and web_preview. This would take care of 99% of the cases. For other commands, they can do without.
Well, I would say 97% because I use these functions rarely but it would be a step into the right direction ;)
If you are dumping anything to the html output window, then you should be using HTMLOutput.show or at least web_preview… :)
Yes :) But sometimes I want to have a plain HTML window without the TextMate banner. Maybe one could provide an option in HTMLOutput.show à la HTMLOutput.show(:title => "My Title", :no_banner)
--Hans
On Sep 25, 2008, at 1:36 PM, Hans-Jörg Bibiko wrote:
at the very least we can add it to the HTMLOutput.show command and web_preview. This would take care of 99% of the cases. For other commands, they can do without.
Well, I would say 97% because I use these functions rarely but it would be a step into the right direction ;)
If you are dumping anything to the html output window, then you should be using HTMLOutput.show or at least web_preview… :)
Yes :) But sometimes I want to have a plain HTML window without the TextMate banner. Maybe one could provide an option in HTMLOutput.show à la HTMLOutput.show(:title => "My Title", :no_banner)
Sure, this is a good idea.
—Alex
I found a tiny bug in my JS script. How to escape ' and ".
This should work:
s.replace(/\x27/g,"’").replace(/"/g,'\"')
<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.replace(/\x27/ g,"’").replace(/"/g,'\"')+"";}'",null);}; confirm = function(s){TextMate.system('"$DIALOG" -e -p '{messageTitle="JavaScript";informativeText="'+s.replace(/\x27/ g,"’").replace(/"/g,'\"')+'";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>
If someone could verify this I'd be appreciated ;)
--Hans
Arrgh, wait:
<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.replace(/\x27/ g,"’").replace(/"/g,'\"')+"";}'",null);}; confirm = function(s){TextMate.system(""$DIALOG" -e -p '{messageTitle="JavaScript";informativeText=""+s.replace(/\x27/ g,"’").replace(/"/g,'\"')+"";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>
I forgot to change " ' for confirm as well. It's really tricky ;}
--Hans
And, hoepfully, finally I fixed the issue if you do this
try{...} catch(e) {alert(e)}
and e is an object
then this will work in a browser but for "$DIALOG" one has to write "e.toString()" that's why:
<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.toString().replace(/\x27/g,"’").replace(/"/g,'\"') +"";}'",null);}; confirm = function(s){TextMate.system(""$DIALOG" -e -p '{messageTitle="JavaScript";informativeText= ""+s.toString().replace(/\x27/g,"’").replace(/"/g,'\"') +"";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>
Puuuh,
--Hans
On Thu, Sep 25, 2008 at 9:16 AM, Hans-Jörg Bibiko bibiko@eva.mpg.de wrote: …
awesome. Now implemented in Javascript Tools: http://github.com/subtleGradient/javascript-tools.tmbundle/tree/master/Comma...
The Javascript Runner now logs errors to the web inspector console as well as alerting with the filepath & corrected line number.
I used try/throw/catch to find out the current line number and then offset the line number of your actual error.
-- Thomas Aylott subtleGradient.com
On 25.09.2008, at 18:42, Thomas Aylott wrote:
On Thu, Sep 25, 2008 at 9:16 AM, Hans-Jörg Bibiko bibiko@eva.mpg.de wrote: …
awesome. Now implemented in Javascript Tools: http://github.com/subtleGradient/javascript-tools.tmbundle/tree/ master/Commands/Test%20Javascript.tmCommand
The Javascript Runner now logs errors to the web inspector console as well as alerting with the filepath & corrected line number.
I used try/throw/catch to find out the current line number and then offset the line number of your actual error.
Excellent!! I will try whether I can adapt your code to the error handling of Objective-J (I know it's a stony way but maybe I can find a way).
--Hans