Tag Archive for jquery

jQuify

javascript:try{_c='green';void(jQuery);}catch(e){_s=document.createElement('script');_s.src='http:/'+'/code.jquery.com/jquery-latest.js';document.getElementsByTagName('body')[0].appendChild(_s);_c='red'}finally{_f=function(){$('body').css('border','1px solid '+_c);if(_c==='green'&&typeof jQuery!='undefined'&&confirm('API?'))_w=window.open('http:/'+'/docs.jquery.com/Core')};void(window.setTimeout(_f,999))}

source

Jquery Limit Input to Numbers

$('input.valid-number').bind('keypress', function(e) {
return ( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) ? false : true ;
})

source

jQuery rollovers

$(document).ready(function() {
// Preload all rollovers
$("#tabs img").each(function() {
// Set the original src
rollsrc = $(this).attr("src");
rollON = rollsrc.replace(/.jpg$/ig,"2.jpg");
$("<img>").attr("src", rollON);
});

// Navigation rollovers
$("#tabs a").mouseover(function(){
imgsrc = $(this).children("img").attr("src");
matches = imgsrc.match(/2/);

// don't do the rollover if state is already ON
if (!matches) {
imgsrcON = imgsrc.replace(/.jpg$/ig,"2.jpg"); // strip off extension
$(this).children("img").attr("src", imgsrcON);
}

});
$("#tabs a").mouseout(function(){
$(this).children("img").attr("src", imgsrc);
});
});

source

Make Joomla’s Debug Window Be Togglable

$(document).ready( function(){

$("#system-debug")
.wrapInner("<div id="debugWrapper"></div>")
.prepend("<a href="javascript:;" id="toggleDebug">Toggle debug</a>");

$("#debugWrapper").hide();
$("#toggleDebug").click(function(){
$("#debugWrapper").toggle();
});
});

source

jQuery dynamic image resizer function

/**
* scaleImage 0.1
*
* Rendez vos sites glissant !
*
* Copyright (c) 2008 Benoit G (http://www.tim-burton.net) based upon
* Licensed under the Creative Commons License:
* <a href="http://creativecommons.org/licenses/by/3.0/" >http://creativecommons.org/licenses/by/3.0/</a>
*
* Date: 2008-08-25
*/

(function($){
$.fn.scaleImage = function(options) {

var defaults = {
maxwidth: 200,
linkclass:'',
icon:true,
thickbox:true
};
var options = $.extend(defaults, options);

return this.each(function() {
obj = $(this);

var width = obj.width();
var height = obj.height();
if (width > options.maxwidth) {
//Set variables	for manipulation
var ratio = (height / width );
var new_width = options.maxwidth;
var new_height = (new_width * ratio);
var classes = options.linkclass+' scaleImage';

//thickbox
if (options.thickbox == true) {
var img_full_link = obj.attr('src');
obj.wrap('<a class="thickbox" title="'+obj.attr('alt')+'" href="'+img_full_link+'"></a>');
tb_init(obj.parent('a'));
}

//Shrink the image and add link to full-sized image
obj.height(new_height).width(new_width);
obj.addClass(classes);

//zoom icon
if (options.icon == true) {
obj.after('<div class="thumb-zoom"> </div>');
obj.hover(function(){
$(this).next('.thumb-zoom').addClass("hover");
},function(){
$(this).next('.thumb-zoom').removeClass("hover");
});
}

}
});
};
})(jQuery);

source

load jquery in firebug

j=document.createElement("SCRIPT");
j.src="http://code.jquery.com/jquery-latest.pack.js";
document.getElementsByTagName("HEAD")[0].appendChild(j);

source

Set text cursor to the begin/end of input/textarea

/* to the END */

$('textarea').each(function(){ //change event or something you want

/* simple js */
if (this.createTextRange) {
var r = this.createTextRange();
r.collapse(false);
r.select();
}

$(this).focus(); //set focus

});

/* to the BEGIN */

$('textarea').each(function(){ //change event or something you want

/* simple js */
if (this.createTextRange) {
var r = this.createTextRange();
r.collapse(true);
r.select();
}

$(this).focus(); //set focus

});

source

jQuery – get mouse position

var mouseX = 0;
var mouseY = 0;
$().mousemove( function(e) {
mouseX = e.pageX;
mouseY = e.pageY;
});

source

localScroll Template

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jquerty localScroll Template</title>

<style type="text/css" media="screen">
#slide_wrapper{
width: 400px;
height: 300px;
overflow: hidden;
}

#slide_box{
width: 2000px;
height: 300px;
}

.section{
float: left;
width: 400px;
height: 300px;
margin: 0 20px 0 0 0;
}

#section01{ background: #ecf; }
#section02{ background: #acf; }
#section03{ background: #cfc; }
#section04{ background: #ffc; }
#section05{ background: #fda; }
</style>

<script src="common/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="common/js/jquery.scrollTo-min.js" type="text/javascript" charset="utf-8"></script>
<script src="common/js/jquery.localscroll-min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#scroll_navi').localScroll({
target: '#slide_wrapper',
axis: 'xy'
});
});
</script>
</head>
<body>
<div id="slide_wrapper"><!-- Static Box contain Sliding Box. set overflow:hidden-->
<div id="slide_box"><!-- Sliding Box, it's Long or Large and contain some sections -->
<div id="section01" class="section">
section01
</div>
<div id="section02" class="section">
section02
</div>
<div id="section03" class="section">
section03
</div>
<div id="section04" class="section">
section04
</div>
<div id="section05" class="section">
section05
</div>
</div>
</div>
<ul id="scroll_navi">
<li id="scroll_navi01"><a href="#section01">section01</a></li>
<li id="scroll_navi02"><a href="#section02">section02</a></li>
<li id="scroll_navi03"><a href="#section03">section03</a></li>
<li id="scroll_navi04"><a href="#section04">section04</a></li>
<li id="scroll_navi05"><a href="#section05">section05</a></li>
</ul>
</body>
</html>

source

jquery firebug log

jQuery.fn.log = function (msg) {
console.log("%s: %o", msg, this);
return this;
};

source