DrupalBin
Submit Code
About
Recent Posts
Code
Fix for Fix for Code
Fix for Code
Code
Node type whitelist
an axe coach accessories
coach purses married
Fix for de las ghd alturas
de las ghd alturas
Code
more
User login
Log in using OpenID:
What is OpenID?
Username:
*
Password:
*
Log in using OpenID
Cancel OpenID login
Create new account
Request new password
Tags
CCK
drupal
fapi
jquery
menu
module
php
simpletest
taxonomy
test
theme
views
more tags
Home
Fix for Code
View
Fix
July 8, 2010 - 8:45am — Anonymous
jQuery
(
document
)
.
ready
(
function
(
)
{
// image loader
//set variables
if
(
jQuery
(
"#slider_img"
)
.
length
)
{
var
$index
=
true
;
var
$load
=
'a.load_slider_img'
;
var
$delay_time
=
0
;
}
jQuery
(
this
)
.
delay
(
$delay_time
,
function
(
)
{
// id of the div containers
var
$imgContainerId
=
"div[class^='image_loader']"
;
// grab the images
var
$images
=
jQuery
(
$imgContainerId
+
' span img'
)
;
// image length
var
$max
=
$images.
length
;
// remove them from DOM to prevent normal load
jQuery
(
'.rm_img'
)
.
remove
(
)
;
// start loading
if
(
$max
>
0
)
{
LoadImage
(
0
,
$max
)
;
}
// loading function handler
function
LoadImage
(
index
,
$max
)
{
if
(
index
<
$max
)
{
// add list to div
jQuery
(
'<span id="img'
+
(
index
+
1
)
+
'"></span>'
)
.
each
(
function
(
)
{
jQuery
(
this
)
.
appendTo
(
jQuery
(
'.image_loader '
+
$load
)
.
eq
(
index
)
)
;
}
)
;
if
(
$max
>
1
)
{
jQuery
(
'<img style="margin-right:4px;" src="images/transparent.png" alt="" width="14" height="14" class="slider_preview_img" />'
)
.
each
(
function
(
)
{
jQuery
(
this
)
.
appendTo
(
'#slider_preview_img'
)
;
}
)
;
}
// end
// new image object
var
$img
=
new
Image
(
)
;
// current image
var
$curr
=
jQuery
(
"#img"
+
(
index
+
1
)
)
;
// load current image
jQuery
(
$img
)
.
load
(
function
(
)
{
// hide it first + .hide() failed in safari
jQuery
(
this
)
.
css
(
'display'
,
'none'
)
;
//add alt attr
jQuery
(
this
)
.
attr
(
{
alt
:
""
}
)
;
// add hover class
if
(
!
$index
)
{
jQuery
(
this
)
.
addClass
(
'hover_fade'
)
;
}
// insert the image into div
jQuery
(
$curr
)
.
append
(
this
)
;
// fade it in
jQuery
(
this
)
.
fadeIn
(
250
,
function
(
)
{
// remove loading div
if
(
!
$index
)
{
jQuery
(
'.img_pre_'
+
index
)
.
remove
(
)
;
}
if
(
index
==
(
$max
-
1
)
)
{
// remove loading div after all images loaded then start slider
if
(
$index
)
{
cycleStart
(
)
;
}
if
(
$max
==
1
)
{
if
(
$index
)
{
jQuery
(
".slider_content"
)
.
css
(
{
display
:
'block'
}
)
;
jQuery
(
".slider_content"
)
.
css
(
{
marginTop
:
"22px"
}
)
;
if
(
jQuery
(
'.image_loader'
)
.
hasClass
(
'slider_cropped'
)
)
{
jQuery
(
"#home_feature"
)
.
addClass
(
'staged'
)
;
jQuery
(
".slider_img_cropped"
)
.
css
(
{
marginTop
:
"20px"
}
)
;
}
}
}
// end if($max==1)
}
else
{
// loading next item
LoadImage
(
index
+
1
,
$max
)
;
}
}
)
;
//end fadeIn fonction
}
)
.
error
(
function
(
)
{
// if loading error remove div
jQuery
(
$curr
)
.
remove
(
)
;
// try to load next item
LoadImage
(
index
+
1
,
$max
)
;
}
)
.
attr
(
'src'
,
jQuery
(
$images
[
index
]
)
.
attr
(
'src'
)
)
;
}
// if(index<$max)
}
// end LoadImage
}
)
;
// end jQuery(this).delay
}
)
;
//end document ready
jquery
slider
Submit Fix
Summary:
Tags:
Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Show summary in full view
jQuery(document).ready(function() { // image loader //set variables if(jQuery("#slider_img").length){var $index=true; var $load='a.load_slider_img'; var $delay_time=0;} jQuery(this).delay($delay_time,function() { // id of the div containers var $imgContainerId = "div[class^='image_loader']"; // grab the images var $images = jQuery($imgContainerId+' span img'); // image length var $max = $images.length; // remove them from DOM to prevent normal load jQuery('.rm_img').remove(); // start loading if($max>0) { LoadImage(0,$max); } // loading function handler function LoadImage(index,$max) { if(index<$max) { // add list to div jQuery('<span id="img'+(index+1)+'"></span>').each(function() { jQuery(this).appendTo(jQuery('.image_loader '+$load).eq(index)); }); if($max>1) { jQuery('<img style="margin-right:4px;" src="images/transparent.png" alt="" width="14" height="14" class="slider_preview_img" />').each(function() { jQuery(this).appendTo('#slider_preview_img'); }); }// end // new image object var $img = new Image(); // current image var $curr = jQuery("#img"+(index+1)); // load current image jQuery($img).load(function () { // hide it first + .hide() failed in safari jQuery(this).css('display','none'); //add alt attr jQuery(this).attr({alt: ""}); // add hover class if(!$index) { jQuery(this).addClass('hover_fade'); } // insert the image into div jQuery($curr).append(this); // fade it in jQuery(this).fadeIn(250,function() { // remove loading div if(!$index) { jQuery('.img_pre_'+index).remove(); } if(index == ($max-1)) { // remove loading div after all images loaded then start slider if($index) { cycleStart(); } if($max==1){ if($index){ jQuery(".slider_content").css({display:'block'}); jQuery(".slider_content").css({marginTop:"22px"}); if(jQuery('.image_loader').hasClass('slider_cropped')){ jQuery("#home_feature").addClass('staged'); jQuery(".slider_img_cropped").css({marginTop:"20px"}); } } }// end if($max==1) }else{ // loading next item LoadImage(index+1,$max); } });//end fadeIn fonction }).error(function () { // if loading error remove div jQuery($curr).remove(); // try to load next item LoadImage(index+1,$max); }).attr('src', jQuery($images[index]).attr('src')); } // if(index<$max) } // end LoadImage });// end jQuery(this).delay });//end document ready
Syntax highlighting mode:
ActionScript
ColdFusion
Diff
Drupal 5
Drupal 6
HTML
INI
Javascript
MySQL
PHP
Python
robots.txt
SQL
Text
Select the syntax highlighting mode to use.
See Also:
Order
Title:
URL:
-1
0
1
Title:
URL:
-1
0
1
Any links you'd like to have associated with the post (Drupal.org issue, Wikipedia article, etc).
File attachments
Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.
Attach new file:
The maximum upload size is
1 MB
. Only files with the following extensions may be uploaded:
jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp phps
.