Make DC's windows draggable
当前为
// ==UserScript==
// @name draggable_DC
// @author Ladoria
// @version 0.12
// @description Make DC's windows draggable
// @match http://www.dreadcast.net/Main
// @copyright 2012+, Ladoria
// @namespace GTFO
// ==/UserScript==
// DEBUG Don't touch those damn things!
var global_debug = false;
// /DEBUG
$(document).ready( function() {
// initials values saving
zone_gauche_initiale_offset = $('#zone_gauche').offset();
zone_droite_initiale_offset = $('#zone_droite').offset();
zone_gauche_initiale_zIndex = $('#zone_gauche').zIndex();
zone_droite_initiale_zIndex = $('#zone_droite').zIndex();
zone_gauche_initial_bacgroundColor = $('#zone_gauche').css('backgroundColor');
zone_droite_initial_bacgroundColor = $('#zone_droite').css('backgroundColor');
zone_informations_lieu_initial_bacgroundColor = $('#zone_information').css('backgroundColor');
$('#zone_gauche').addClass("DC_draggable");
$('#zone_centre').addClass("DC_draggable");
$('#zone_droite').addClass("DC_draggable");
$('#zone_informations_lieu').addClass("DC_draggable");
/*$('#zone_gauche').draggable();
$('#zone_droite').draggable();
$('#zone_informations_lieu').draggable();
$('#zone_gauche').css('cursor','move');
$('#zone_droite').css('cursor','move');
$('#zone_informations_lieu').css('cursor','move');*/
// ugly selectors
$('#zone_gauche div').first().before('<div style="height:0px;width:0px;margin-right:-13px;z-index:999999;"><input type="checkbox" name="zone_gauche" class="DC_draggable"></div>');
$('#zone_droite div').first().before('<div style="height:0px;width:0px;margin-right:-13px;z-index:999999;"><input type="checkbox" name="zone_droite" class="DC_draggable"></div>');
$('#zone_informations_lieu div').first().before('<div style="top:-11px;left:-15px;height:0px;width:0px;margin-right:-13px;z-index:999999;"><input type="checkbox" name="zone_informations_lieu" class="DC_draggable"></div>');
});
var zIndex = 310000;
var dragging = false;
var isDraggable = [ ['zone_gauche', false],
['zone_droite', false],
['zone_centre', false], //desactivated
['zone_informations_lieu', false]];
var zone_droite_draggable = false;
var zone_informations_lieu_draggable = false;
function enableDrag(id) {
$('#' + id).draggable();
$('#' + id).css('cursor','move');
isDraggable[id] = true;
}
function disableDrag(id) {
$('#' + id).draggable("destroy");
$('#' + id).addClass("");
$('#' + id).css('cursor','auto');
isDraggable[id] = false;
}
$('input[type=checkbox].DC_draggable').click( function() {
if($(this).is(':checked'))
enableDrag($(this).attr('name'));
else
disableDrag($(this).attr('name'));
});
$('.DC_draggable:not(input[type=checkbox])').dblclick( function() {
if(isDraggable[$(this).attr('id')]) {
switch($(this).attr('id')) {
case 'zone_gauche' :
$('#' + $(this).attr('id')).offset(zone_gauche_initiale_offset);
break;
case 'zone_droite' :
$('#' + $(this).attr('id')).offset(zone_droite_initiale_offset);
break;
case 'zone_informations_lieu' :
$('#zone_informations_lieu').css('top','auto');
$('#zone_informations_lieu').css('bottom','10px');
$('#zone_informations_lieu').css('left','10px');
break;
}
}
});
$('.DC_draggable:not(input[type=checkbox])').mousedown( function() {
zIndex++;
$('#' + $(this).attr('id')).zIndex(zIndex);
});
$('.DC_draggable:not(input[type=checkbox])').mouseup( function() {
if(dragging) {
dragging = false;
switch($(this).attr('id')) {
case 'zone_gauche' :
$('#' + $(this).attr('id')).css('backgroundColor',zone_gauche_initial_bacgroundColor);
break;
case 'zone_droite' :
$('#' + $(this).attr('id')).css('backgroundColor',zone_droite_initial_bacgroundColor);
break;
case 'zone_informations_lieu' :
$('#' + $(this).attr('id')).css('backgroundColor',zone_informations_lieu_initial_bacgroundColor);
break;
}
}
});
$('.DC_draggable:not(input[type=checkbox])').bind('drag', function(event) {
dragging = true;
switch($(this).attr('id')) {
case 'zone_gauche' :
$('#' + $(this).attr('id')).css('backgroundColor','rgba(172, 0, 0, 0.6)');
break;
case 'zone_droite' :
$('#' + $(this).attr('id')).css('backgroundColor','rgba(172, 0, 0, 0.6)');
break;
case 'zone_informations_lieu' :
$('#' + $(this).attr('id')).css('backgroundColor','rgba(172, 0, 0, 0.6)');
$('#zone_informations_lieu').css('position','absolute');
$('#zone_informations_lieu').css('bottom','auto');
break;
}
});