mrkeck Sharing the Love


Comment Out a Portion of Code Convention

if(0){  //Change 0 to 1 to turn on code segment
     //Code that I want to turn on and off

jQuery Full Position of Element on Page

var eleBounds=function(ele){
	var off=ele.offset();
	var bounds={};;;
	return bounds;

Works well with phantomJS clipRect, just have to get the function in the page and return back the object and set clipRect equal to it.

Filed under: jquery, phantomJs No Comments

Javascript: Faster Math.floor and parseInt

var str='123.55';
var num1=~~str; //num=123
var num2=Math.floor(str); //num=123
var num3=parseInt(str); //num=123

~~ operator gives the same result as Math.floor and parseInt but is slightly faster than Math.floor and is 6 times faster than parseInt.

Filed under: Optimization No Comments

Javascript sleep function

var sleepyTime=10*1000;  //10 seconds
//In 10 seconds this will alert("I'm awake!");
alert("I'm awake!");

phantomJs delay until condition is met

var tries=0;
var maxTries=10;
var howOften=2000;
var tom=setInterval(function(){
		return $('#thingy').length>0;
	if(delayResponse || maxTries<=tries){
		//console.log('Found it or out of time');
		//Do stuff now that it is ready

There is a function out there called waitFor but I found this easier to handle


Simulate Mouse Click with Javascript/jQuery

//Find thing you want to click
var ele=$('.thingToClick')[0];
//Function that performs the click
var doClick=function(ele){
  var evt = document.createEvent("MouseEvents");
  evt.initMouseEvent("click", true, true, window,
	0, 0, 0, 0, 0, false, false, false, false, 0, null);
  return ele.dispatchEvent(evt);
//Call the click
Filed under: Javascript, jquery No Comments

jQuery Animation Queue


Filed under: jquery No Comments

jQuery Mobile breaks autoFill on iPhone

To turn autoFill back on use:

For some reason they set it to off by default.

Filed under: jQueryMobile, web No Comments

Javascript Perfomance

Lets you try out different variations and tests them on several browsers to show you which way is faster.

Pretty Awesome!


jQuery Graphing

Highcharts looks great!  If I were doing a non-commercial site I would check this one out heavily.  But since it costs, I'm on to the next one.

jqPlot worked pretty well but had some issues for me.  Some of these issues are most likely me just not knowing what I am doing but I like a library to handle my ignorance.  The data points didn't line up with the grid and when I used a bar graph I couldn't get the x-axis labels to format into a two decimal number.  It looked like it had options to do it but they didn't work for me.

Flot has worked great for me so far.  I like the tooltip, hover, and click stuff.  Looks nice too.  I had the initial call wrong and that made nothing work but I have it right now and am very pleased.