Get a JavaScript call stack

May 14th, 2013 by Alex No comments »

Things can get really complicated with JavaScript development, and some may need to find out a call stack (or, to find a call trace) of current function/line. It’s actually pretty each with a good modern browser:

console.trace();

That’s it! Running that line in console can give you something like this in Chrome:

(anonymous function)
InjectedScript._evaluateOn
InjectedScript._evaluateAndWrap
InjectedScript.evaluate

Button text vertical align and focus outline in Firefox

January 23rd, 2013 by Alex No comments »

You may see that bug on some buttons having the text displayed too low on a <input type="submit" /> or other <button>s. The fix is very simple, all you need to do is clear padding with a -moz pseudo selector

input::-moz-focus-inner
{ 
    padding: 0;
}

And with same pseudo selector you can clean the outlines that appear after focusing the button, for all types of buttons it may be something like this:

button::-moz-focus-inner,
input[type="reset"]::-moz-focus-inner,
input[type="button"]::-moz-focus-inner,
input[type="submit"]::-moz-focus-inner,
select::-moz-focus-inner,
input[type="file"] > input[type="button"]::-moz-focus-inner {
    border: none;
}

Disable particular element styling by jQuery Mobile

January 11th, 2013 by Alex No comments »

Do you like jQuery Mobile, but want to use your own professional UI? It’s easy to disable styling for particular element just like this:

<input type="text" value="Input text here" data-role="none" />

The data-role="none" will do the trick for you!

Excel and UTF-8 CSV export

November 23rd, 2012 by Alex No comments »

So you probably exported your lovely database, perfectly stored in UTF-8 encoding, and then you open the csv in Excel, and see a bunch of crazy-looking characters where ä, Õ and é should be?

Well, here’s a fix: add a Byte-Order-Mark to your file. Excel just needs it desperately..

header('Content-Type: application/force-download');
header('Content-Description: File Transfer'); 
header('Content-disposition: attachment; filename="export.csv"');
 
echo chr(0xEF).chr(0xBB).chr(0xBF);
 
echo $mycsvoutput;

Load jQuery from a CDN and have a fallback to own host

November 20th, 2012 by Alex No comments »

Just sharing the idea of loading jQuery (or any other library) from CDN, with a fallback to own hosting:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
window.jQuery || document.write(unescape('%3Cscript type="text/javascript" src="/js/jquery-1.8.3.min.js"%3E%3C/script%3E'))
</script>

Also, you can drop the type attribute when you are developing with HTML5 doctype.