Skip to content

Instantly share code, notes, and snippets.

@ryansukale
ryansukale / ScriptPathFinder.js
Created April 29, 2011 06:16
Find the current directory of your script from within your javascript using jQuery
/*This code returns the path of the currently executing javascript file. This path can then be used to find relative paths to other files like the css files and images that are specific to this js file.
Should come in handy when making jQuery plugins if your script file makes used of script specific css. You can simply use string manipulation to create the relative path for your css.
Recommended use at the top of your plugin.
*/
var jsFilePath = $("head").find("script:last").attr('src');
@ryansukale
ryansukale / maxWidth.js
Created April 30, 2011 07:01
Creating a cross browser max-width value using jQuery
/*Sample code to calculate the max-width of an element via jquery that can be applied to all browsers*/
/*Append the element to the body/anywhere else you want to append the element to, in order to allow the browser to render the initial width of the element*/
var $element = ('<div></div>');
$('body').append($element);
if($element.width()>someWidth){
/*since the max-width property does not work in IE,
we set the max width by comparison after the element is added to the dom*/
$element.css({'width':someWidth});
@ryansukale
ryansukale / jQueryGoogleCDN.html
Created May 1, 2011 06:00
Snippet to use the Google CDN to load jQuery
<!DOCTYPE html>
<!--
The below script tag can be used to load the compressed/minified version of
the jQuery API fromt he Google CDN network. This can help in speeding up the
user's browsing experience if the jQuery library has already been cache'd in
the user's browser when used by some other website. So, instead of the browser
loading the API from your own website, it resuses the cache's version of the
jQuery API.
-->
<html>
@ryansukale
ryansukale / roundall.js
Created May 13, 2011 11:36
A simple jquery plugin to add rounder borders. This plugin adds equal radius round borders.
(function(jQuery){
jQuery.fn.roundall=function(radius){
return this.each(function(){
$(this).css({'-moz-border-radius':radius,'border-radius':radius,'-webkit-border-radius':radius});
});
};
})(jQuery);
@ryansukale
ryansukale / overlay.css
Created May 16, 2011 06:43
CSS class that can be used to create an overlay with a light grey background
.overlay{
position:absolute;
left:0px;
top:0px;
height:0px;
width:100%;
height:100%;
background-color:#fafafa
}
//Displays the sourcecode for the currently
//selected element's first click handler
//in Google Chrome
$($0).data('events')['click'][0]['handler'];
var logEnabled = true;
//Hack for IE. The window.console object is not available until the
//console window has been opened at least once
//Associated stackoverflow post - http://stackoverflow.com/questions/10961430/ie9-not-running-javascript-onload/12924439#12924439
if(!window.console){
console={};
console.log = function(){};
}
@ryansukale
ryansukale / gist:6927680
Last active December 25, 2015 05:49
A short snippet to randomize elements in an array or a jquery collection.
function randomize(arr) {
for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
return arr;
};
@ryansukale
ryansukale / phpForeach
Last active December 31, 2015 04:49
php foreach using a key and a value
foreach ($aMapLikeCollection as $key => $value) {
}
@ryansukale
ryansukale / jquerySnippets
Created January 23, 2014 16:22
Short snippets of code to do commonplace things using jQuery or pure javascript
$(
//Setting the value of a radio button programmatically
$('input[type=radio]').prop('checked', true);
);