jQuery its ‘document ready’ can be written on different ways.
I have seen a lot of scripts already still using a old way of checking if the DOM is ready for action like this:
1 2 3 4 5 | window.onDomReady = myFunction; function myFunction() { alert('hello'); } |
or (which is not smart cause onload waits for even the images to be loaded):
1 2 3 4 5 | window.onload = myFunction; function myFunction() { alert('hello'); } |
jQuery has a nicer way to implement this with the following piece of code:
1 2 3 | $(document).ready(function() { // your code here }); |
However you can write this even a bit shorter than most people already do by using the above code, like this:
1 2 3 | $(function() { // your code here }); |
I hope you find this useful, make something nice with jQuery!
How to control a Flash movie from Javascript and use Javascript from Flash movies
Personally I dislike the usage of Flash in my websites but our clients request a lot that they want animations. Now it happens that they want the animation to act upon an action to a non-flash object. This can be difficult if you have no idea how to do that. If you read below, you should have no problem with getting this job done
Control your Flash Movie from Javascript:
// Play movie document.getElementById('myFlashMovie').Play(); // Stop movie document.getElementById('myFlashMovie').StopPlay(); // Rewind movie to beginning document.getElementById('myFlashMovie').Rewind(); // Goto next frame of MovieClip document.getElementById('myFlashMovie').TGetProperty(nameOfTargetMovieClip, propertyIndex); // Goto next frame of TimeLine document.getElementById('myFlashMovie').GotoFrame(frameNum); // Zoom in or out the flash movie document.getElementById('myFlashMovie').Zoom(relative percentage); // Set variable and make it available via ActionScript document.getElementById('myFlashMovie').SetVariable(variableName, variableValue); // Get variable for usage in JavaScript var myVariable = document.getElementById('myFlashMovie').GetVariable(variableName);
To control Javascript functions you can call it like this:
ActionScript 1/2
getURL("javascript:name_of_your_function();");
ActionScript 3 direct call
var url:String = "javascript:name_of_your_function();"; var request:URLRequest = new URLRequest(url); try { navigateToURL(request); } catch (e:Error) { trace("Error occurred!"); }
ActionScript 3 event mouse click call
movieClipName.addEventListener(MouseEvent.CLICK, callLink); function callLink:void { var url:String = "javascript:name_of_your_function();"; var request:URLRequest = new URLRequest(url); try { navigateToURL(request); } catch (e:Error) { trace("Error occurred!"); } }
For some more information about these methods, please check out the Adobe website.
I hope this helps you out with getting that Flash Movie behave like you want it to
How to get parameters from query string with JavaScript
I don't remember where I found this piece of code, but it works nice to get query string parameters
function getURLParam(strParamName) { var strReturn = ''; var strHref = window.location.href; if (strHref.indexOf("?") > -1){ var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase(); var aQueryString = strQueryString.split("&"); for (var iParam = 0; iParam < aQueryString.length; iParam++) { if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1) { var aParam = aQueryString[iParam].split("="); strReturn = aParam[1]; break; } } } return unescape(strReturn); }
it works quite simple, first it grabs all data after the question mark in the url, then it splits this result on the & character and then it splits again on the equal character. The result of that exists out of two pieces, the first is the key and the second the value of that key.
Count words or characters in a textarea with JavaScript
If you don't want to use a framework like jQuery and just script with native JavaScript this might become handy to use.
Check the following sites:
Words
http://www.javascriptkit.com/script/script2/countwords.shtml
Characters
http://www.javascriptkit.com/script/script2/charcount.shtml
Good luck
How to fix inconsistent line ending (EOL) style with find and Perl
If you work with subversion you might get this error when you got files that have been edited on different operating systems like Windows, Linux, FreeBSD or Mac OS X.
Well, the fix is quite simple. You simply replace the wrong line endings with right ones depending of which you want. In my situation I want unix style line endings.
Replace in PHP/JavaScript files:
find ./ -name '*.php' -type f -exec perl -i -wpe 's/rn/n/g' '{}' ; find ./ -name '*.php' -type f -exec perl -i -wpe 's/r/n/g' '{}' ; find ./ -name '*.js' -type f -exec perl -i -wpe 's/rn/n/g' '{}' ; find ./ -name '*.js' -type f -exec perl -i -wpe 's/r/n/g' '{}' ;
In case you want to replace them in multiple file types you can adjust the command. In this example we want to replace in the following file types:
- asp
- cfm
- css
- html
- js
- php
- pl
- txt
Use the following commands:
find ./ -name '*.asp' -or -name '*.cfm' -or -name '*.css' -or -name '*.html' -or -name '*.js' -or -name '*.php' -or -name '*.pl' -or -name '*.txt' -type f -exec perl -i -wpe 's/rn/n/g' '{}' ; find ./ -name '*.asp' -or -name '*.cfm' -or -name '*.css' -or -name '*.html' -or -name '*.js' -or -name '*.php' -or -name '*.pl' -or -name '*.txt' -type f -exec perl -i -wpe 's/r/n/g' '{}' ;
Keep in mind, you may use these commands on your own risk. I'm not responsible if you lose your work
Now you should be able to commit your files again




