Topic: Innecesary newlines

Hi, this might be one of the most irrelevant features requested on this forum, still is easy and quick.

The current javascript code that gets printed in the HEAD, will automatically add "\n" at the beginning of the print process. Shouldn't that depend on the developer? Some of us like to keep the code very clean, and that also covers blank lines in-between the code.

<meta name='robot' content='all' />
                                                            <-------- THIS ***
<script type='text/javascript' charset='UTF-8'>
/* <![CDATA[ */
try { if (undefined == xajax.config) xajax.config = {}; } catch (e) { xajax = {}; xajax.config = {}; };
xajax.config.requestURI = 'http://localhost/_template/';
xajax.config.statusMessages = true;
xajax.config.waitCursor = true;
xajax.config.version = 'unknown';
xajax.config.legacy = false;
xajax.config.defaultMode = 'asynchronous';
xajax.config.defaultMethod = 'POST';
/* ]]> */
</script>
<script type='text/javascript' src='http://localhost/_template/lib/xajax/xajax_js/xajax_core.js' charset='UTF-8'></script>
<script type='text/javascript' charset='UTF-8'>
/* <![CDATA[ */
window.setTimeout(
 function () {
  var scriptExists = false;
  try { if (xajax.isLoaded) scriptExists = true; }
  catch (e) {}
  if (!scriptExists) {
   alert('Error: the xajax Javascript component could not be included. Perhaps the URL is incorrect?\nURL: http://localhost/_template/lib/xajax/xajax_js/xajax_core.js');
  }
 },
2000
);
/* ]]> */
</script>
                                                            <-------- AND THIS ***
<script type='text/javascript' charset='UTF-8'>
/* <![CDATA[ */
xajax_msg = function() { return xajax.request( { xjxfun: 'msg' }, { parameters: arguments } ); };
/* ]]> */
</script>

I know i can remove the "\n" by myself, but it would be nice to have a compact javascript printed out, instead of that big pile of code. Better yet, an argument could be called that prints the output in a compressed way. For example:

<script type='text/javascript' charset='UTF-8'>try{if(undefined==xajax.config)xajax.config={};}catch(e){xajax={};xajax.config={};};xajax.config.requestURI='http://localhost/_template/';xajax.config.statusMessages=true;xajax.config.waitCursor=true;xajax.config.version='unknown';xajax.config.legacy=false;xajax.config.defaultMode='asynchronous';xajax.config.defaultMethod='POST';</script><script type='text/javascript' src='http://localhost/_template/lib/xajax/xajax_js/xajax_core.js' charset='UTF-8'></script><script type='text/javascript' charset='UTF-8'>window.setTimeout(function(){var scriptExists=false;try{if(xajax.isLoaded)scriptExists=true;}catch(e){}if(!scriptExists){alert('Error: the xajax Javascript component could not be included. Perhaps the URL is incorrect?\nURL: http://localhost/_template/lib/xajax/xajax_js/xajax_core.js');}},2000);</script><script type='text/javascript' charset='UTF-8'>xajax_msg=function(){return xajax.request({xjxfun:'msg'},{parameters:arguments});};</script>
Using xajax 0.5

Re: Innecesary newlines

asantos,

Thank you.  I don't think this is silly or irrelevent at all.

I'll keep this in mind (or one of us can add it to the feature request list on sourceforge so it won't be forgotten).

I spent the time to add the ability to defer the script generation to an external 'file'... and that worked out pretty good; I don't think adding a flag to surpress the formatting will be too hard.  (In fact, I was already thinking of this change the last time I went through that code... it should be a matter of changing about 4 lines of code) big_smile

I'm thinking, two settings: Normal (as it is now), Compact (no whitespace, unless necessary)

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

Re: Innecesary newlines

yikes i didnt know about that feature (script generation to an external file).
Im searching in the wiki but i cant find anything related to that.

Using xajax 0.5

Re: Innecesary newlines

You can enable this with:

$xajax->configure('deferScriptGeneration', true);

However, I strongly recommend the revision from SVN as I finally resolved an issue with the order of the plugins (thanks to another forum member for tracking that down!)  ... or wait another day or two for beta 4 (honestly, I'm working very hard to get beta 4 ready... anyone have a few hours a day they could give to me? lol)

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

5 (edited by asantos 2007-08-29 5:42:34 AM)

Re: Innecesary newlines

nice feature. Still it does print the entire timeout stuff in there :s
this is what i got printed:

<script type='text/javascript' charset='UTF-8'>
/* <![CDATA[ */
window.setTimeout(
 function () {
  var scriptExists = false;
  try { if (xajax.isLoaded) scriptExists = true; }
  catch (e) {}
  if (!scriptExists) {
   alert('Error: the xajax Javascript component could not be included. Perhaps the URL is incorrect?\nURL: http://localhost/_template/lib/xajax/xajax_js/xajax_core.js');
  }
 },
2000
);
/* ]]> */

</script>

<script type='text/javascript' src='http://localhost/_template/?xjxGenerateJavascript=c3a55922e3a69a0fd388c360c4ad7973' charset='UTF-8'></script>
Using xajax 0.5

Re: Innecesary newlines

If you are confident that the xajax javascript files will be served reliably by your server, you can remove the timeout javascript using:

$xajax->configure('scriptLoadTimeout', 0);

Use caution, however... if the script file fails to load for whatever reason, the user will see javascript errors but the errors are unlikely to give them a clue as to the cause, nor the resolution.

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

Re: Innecesary newlines

nice!
since i know for sure the xajax will be served for sure, i have no problems by hiding the timeout script.

sorry to ask all those things, they are still not on the wiki hehe (or at least i couldnt find them).

thanks again,
andres

Using xajax 0.5

8 (edited by asantos 2007-09-20 6:50:20 AM)

Re: Innecesary newlines

Actually i have a problem.

When using:

$xajax->configure('deferScriptGeneration',true);

I get this on my page:

<script type='text/javascript' src='http://localhost/_template/rino/login.php?xjxGenerateJavascript=536af9574ed38e2f611ee85fb9c470af' charset='UTF-8'></script>

But the xajax functions are no longer available when i try to call them from:

<button type="submit" onClick="xajax_login(xajax.getFormValues('frmLogin'));">Login</button>

Why?


...
BTW, http://localhost/_template/rino/login.php?xjxGenerateJavascript=536af9574ed38e2f611ee85fb9c470a throws me this:

-<xjx>
<cmd n="dbg">Invalid script or style request.</cmd>
</xjx>
Using xajax 0.5

Re: Innecesary newlines

However, I strongly recommend the revision from SVN as I finally resolved an issue with the order of the plugins (thanks to another forum member for tracking that down!)  ... or wait another day or two for beta 4

Have you updated to xajax 0.5 beta 4b ?  If not, please do so.  Previously, the plugins were not ordered, which caused the hash to change from page load phase to script generation phase, thus returning the error you list.

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

Re: Innecesary newlines

sorry i missed that yikes
i'll download xajax  4b.

do you know when a stable version with that feature will be available?

Using xajax 0.5

11 (edited by asantos 2007-09-24 5:03:55 PM)

Re: Innecesary newlines

uploaded to b4.
still this link throws this error:
http://localhost/_template/rino/login.php?xjxGenerateJavascript=6b6233797e96f3b1f4f6514f19bb0624

<xjx>
<cmd n="dbg">Invalid script or style request.</cmd>
</xjx>
Using xajax 0.5

Re: Innecesary newlines

I just downloaded the final release of xajax 0.5 but this feature doesnt seem to work.

$xajax->configure('deferScriptGeneration', true);

Is it still on development?

Using xajax 0.5