Перейти к содержанию

MediaWiki:Gadget-ImageStack.js: различия между версиями

нет описания правки
(Новая страница: «// Written by User:Hellerhoff, 2011 →‎* Script for Template:Imagestack: →‎jshint curly:false, jquery:true: var launch = function($c) { 'use strict'; var $imageStacks = $('div.ImageStack', $c); if (0 === $imageStacks.length) return; $('.ImageStack_JS_required').hide(); if (document.URL.match(/printable/g)) return; var scrollobject = false; // flag for scroll-dragging var mouse_y = 0; $(document).on('mouseup', function(event) { var did_scro...»)
 
Нет описания правки
 
Строка 1: Строка 1:
// Written by User:Hellerhoff, 2011
jQuery( document ).ready(function() {
/** Script for Template:Imagestack */


/*jshint curly:false, jquery:true */
$(".ImageStack_JS_required").hide();
var launch = function($c) {
'use strict';


var $imageStacks = $('div.ImageStack', $c);
if (document.URL.match(/printable/g)) return;
if (0 === $imageStacks.length) return;


$('.ImageStack_JS_required').hide();
var scrollobject = false;    // flag for scroll-dragging
var mouse_y = 0;


if (document.URL.match(/printable/g)) return;
$(document).on('mouseup', function(event) {
  var did_scroll = !scrollobject;
  scrollobject = false;    // unset flag
  return did_scroll;
}); // bind mouseup


var scrollobject = false; // flag for scroll-dragging
var mouse_y = 0;


$(document).on('mouseup', function(event) {
var did_scroll = !scrollobject;
scrollobject = false; // unset flag
return did_scroll;
}); // bind mouseup


$imageStacks.each(function() {
$("div.ImageStack").each( function () {
var currentImage = 0,
  var currentImage = 0, length, loop,
length, loop,
    $images, $t, $counter, $leftLink,  
$images, $t, $counter, $leftLink,
$rightLink, $currentCount;
$rightLink, $currentCount;


$t = $(this);
    $t = $( this );
loop = $t.find('.ImageStack_loop').length ? true : false;
    loop = $t.find('.ImageStack_loop').length ? true : false;
//Use when 1.17 final is in use
    //Use when 1.17 final is in use
//loop = $t.attr('data-loop') == 'true' ? true : false; //Get loop prop
    //loop = $t.attr('data-loop') == 'true' ? true : false; //Get loop prop
$images = $t.find('.ImageStackUnits div.center');
$images = $t.find('.ImageStackUnits > *');
length = $images.length;
length = $images.length;
if (!length) return true;
if ( !length ) return true;
   
$counter = $('<div class="ImageStackCounter">');
$leftLink  = $('<a>', { href: '#', text : '< ' }).click( function() {
toggleImage ( -1, loop );
return false;
});
$rightLink = $('<a>', { href: '#', text : ' >' }).click( function() {
toggleImage ( 1, loop );
return false;
});


$counter = $('<div class="ImageStackCounter">');
$currentCount = $('<span>', {'class' : 'ImageStackCounterCurrent', text: '0' });
$leftLink = $('<a>', {
$counter.append($leftLink, '(' , $currentCount, '/', length, ')', $rightLink);
href: '#',
$counter.addClass('center');
text: '< '
$t.prepend( $counter );
}).click(function() {
$leftLink.add( $rightLink ).css({ fontSize : "110%", fontweight : "bold" });
toggleImage(-1, loop);
$images.on('mousewheel', function( event, delta ) {
        console.log(delta, Math.floor( delta ))
delta =  Math.floor( delta );
if ( delta != 0 ) toggleImage( -delta, loop );
return false;
});
$images.on('mousedown', function( event ) { // prepare scroll by drag
mouse_y = event.screenY; // remember mouse-position
scrollobject = true; // set flag
return false;
return false;
});
});
$rightLink = $('<a>', {
$images.on('mousemove', function( event ) {
href: '#',
if ( scrollobject && Math.abs( mouse_y - event.screenY ) > 10 ) {
text: ' >'
var offset = (mouse_y < event.screenY) ? 1 : -1;
}).click(function() {
mouse_y = event.screenY; //  remember mouse-position for next event
toggleImage(1, loop);
toggleImage ( offset, loop );
return false;
}
});
return false;
 
});
$currentCount = $('<span>', {
'class': 'ImageStackCounterCurrent',
    var toggleImage = function( offset, loop ) {
text: '0'
        console.log(currentImage, offset, loop)
});
currentImage += offset; //add offset
$counter.append($leftLink, '(', $currentCount, '/', length, ')', $rightLink);
$leftLink.show();
$counter.addClass('center');
$rightLink.show();
$t.prepend($counter);
if ( !loop ) {
$leftLink.add($rightLink).css({
if ( currentImage <= 0 ) {
fontSize: "110%",
currentImage = 0;
fontweight: "bold"
$leftLink.hide();
});
} else if ( currentImage >= $images.length -1 ) {
 
currentImage = $images.length - 1;
$images.on('mousewheel', function(event, delta) {
$rightLink.hide();
delta = Math.floor(delta);
if (delta !== 0) toggleImage(-delta, loop);
return false;
});
$images.on('mousedown', function(event) { // prepare scroll by drag
mouse_y = event.screenY; // remember mouse-position
scrollobject = true; // set flag
return false;
});
$images.on('mousemove', function(event) {
if (scrollobject && Math.abs(mouse_y - event.screenY) > 10) {
var offset = (mouse_y < event.screenY) ? 1 : -1;
mouse_y = event.screenY; //  remember mouse-position for next event
toggleImage(offset, loop);
}
}
return false;
} else {
});
if ( currentImage < 0 ) currentImage = $images.length - 1;
 
if ( currentImage >= $images.length ) currentImage = 0;
var toggleImage = function(offset, loop) {
}
currentImage += offset; //add offset
$images.hide(); //Hide all
$leftLink.show();
$images.eq( currentImage ).show();
$rightLink.show();
$currentCount.text( currentImage + 1 );
if (!loop) {
};
if (currentImage <= 0) {
toggleImage ( 0, loop );
currentImage = 0;
});
$leftLink.hide();
});
} else if (currentImage >= $images.length - 1) {
currentImage = $images.length - 1;
$rightLink.hide();
}
} else {
if (currentImage < 0) currentImage = $images.length - 1;
if (currentImage >= $images.length) currentImage = 0;
}
$images.hide(); //Hide all
$images.eq(currentImage).show();
$currentCount.text(currentImage + 1);
};
toggleImage(0, loop);
});
};


mw.hook( 'wikipage.content' ).add( launch );
mw.hook( 'wikipage.content' ).add( launch );