| 1 |
$(document).ready(function() {
|
| 2 |
var mouseXcord_old = 0;
|
| 3 |
var mouseYcord_old = 0;
|
| 4 |
var activespan = '';
|
| 5 |
var whichspan = 0;
|
| 6 |
var testA, testAthis, testAreaLeftX, testAreaTopY, testAreaRightX, testAreaBottomY;
|
| 7 |
|
| 8 |
init();
|
| 9 |
|
| 10 |
function startDrag(e) {
|
| 11 |
testAreaLeftX = Drupal.absolutePosition(testAthis).x;
|
| 12 |
testAreaTopY = Drupal.absolutePosition(testAthis).y;
|
| 13 |
testAreaRightX = testAreaLeftX+testAthis.offsetWidth;
|
| 14 |
testAreaBottomY = testAreaTopY+testAthis.offsetHeight;
|
| 15 |
|
| 16 |
whichspan = 0;
|
| 17 |
activespan = $(this);
|
| 18 |
activespan.css('cursor', 'move');
|
| 19 |
$('#htmlbox-buttons-manager span.'+ activespan.attr('class')).bind('mouseup', addToBox);
|
| 20 |
activespan.unbind('mouseup', removeFromBox);
|
| 21 |
mouseXcord_old = e.pageX;
|
| 22 |
mouseYcord_old = e.pageY;
|
| 23 |
$(document).mousemove(performDrag);
|
| 24 |
|
| 25 |
if ($(this).parent().is('#htmlbox-droparea')) {
|
| 26 |
$(document).bind('mouseup', endDrag2);
|
| 27 |
activespan.bind('mouseup', removeFromBox).unbind('mouseup', addToBox);
|
| 28 |
}
|
| 29 |
else {
|
| 30 |
$(document).bind('mouseup', endDrag);
|
| 31 |
}
|
| 32 |
return false;
|
| 33 |
}
|
| 34 |
|
| 35 |
function performDrag(e) {
|
| 36 |
activespan.css({
|
| 37 |
left: (e.pageX-mouseXcord_old) +'px',
|
| 38 |
top: (e.pageY-mouseYcord_old) +'px'
|
| 39 |
}).unbind('mouseup', addToBox).unbind('mouseup', removeFromBox);
|
| 40 |
|
| 41 |
if (e.pageX < testAreaRightX && e.pageX > testAreaLeftX &&
|
| 42 |
e.pageY < testAreaBottomY && e.pageY > testAreaTopY) {
|
| 43 |
var distance;
|
| 44 |
var leftOrRight;
|
| 45 |
whichspan = 0;
|
| 46 |
|
| 47 |
$('.helper', testA).remove();
|
| 48 |
$('span', testA).each(function(){
|
| 49 |
if (activespan.css('left') != $(this).css('left') ) {
|
| 50 |
var marginTopBottom = (parseInt($(this).css('margin-left'), 10) +
|
| 51 |
parseInt($(this).css('margin-right'), 10))/2;
|
| 52 |
var spanLeftX = Drupal.absolutePosition(this).x;
|
| 53 |
var spanTopY = Drupal.absolutePosition(this).y-marginTopBottom;
|
| 54 |
var spanRightX = spanLeftX + this.offsetWidth;
|
| 55 |
var spanBottomY = spanTopY + this.offsetHeight+(marginTopBottom * 2);
|
| 56 |
var spanMiddlePoint = spanLeftX+this.offsetWidth/2;
|
| 57 |
|
| 58 |
if (e.pageY < spanBottomY && e.pageY > spanTopY ) {
|
| 59 |
if (distance > Math.abs(spanMiddlePoint-e.pageX) || distance == undefined) {
|
| 60 |
leftOrRight = spanMiddlePoint - e.pageX;
|
| 61 |
distance = Math.abs(leftOrRight);
|
| 62 |
whichspan = $(this);
|
| 63 |
}
|
| 64 |
}
|
| 65 |
}
|
| 66 |
});
|
| 67 |
|
| 68 |
var helper = '<span class="helper" style="height: '+
|
| 69 |
(parseInt(activespan.css('height'), 10) - 2) +'px; padding-left: '+
|
| 70 |
activespan.css('padding-left') +'; padding-right: '+
|
| 71 |
activespan.css('padding-right') +';"></span>';
|
| 72 |
|
| 73 |
if (whichspan) {
|
| 74 |
if (leftOrRight<0) {
|
| 75 |
whichspan.after(helper);
|
| 76 |
whichspan.poz = 'after';
|
| 77 |
}
|
| 78 |
else {
|
| 79 |
whichspan.before(helper);
|
| 80 |
}
|
| 81 |
}
|
| 82 |
else testA.append(helper);
|
| 83 |
}
|
| 84 |
else {
|
| 85 |
$('.helper', testA).remove();
|
| 86 |
}
|
| 87 |
|
| 88 |
return false;
|
| 89 |
}
|
| 90 |
|
| 91 |
function endDrag(e) {
|
| 92 |
$(document).unbind('mousemove', performDrag).unbind('mouseup', endDrag);
|
| 93 |
activespan.css('cursor', '');
|
| 94 |
backanimate(e);
|
| 95 |
updateOptions();
|
| 96 |
}
|
| 97 |
|
| 98 |
function endDrag2(e) {
|
| 99 |
$(document).unbind('mousemove', performDrag).unbind('mouseup', endDrag2);
|
| 100 |
activespan.css('cursor', '');
|
| 101 |
backanimate2(e);
|
| 102 |
updateOptions();
|
| 103 |
}
|
| 104 |
|
| 105 |
function addToBox() {
|
| 106 |
$('.helper', testA).remove();
|
| 107 |
if (!activespan.is('.htmlbox-separator_basic') && !activespan.is('.htmlbox-separator_dots')) activespan.css({cursor: ''}).hide();
|
| 108 |
$(document).unbind('mousemove', performDrag).unbind('mouseup', endDrag);
|
| 109 |
|
| 110 |
var clonespan = activespan.clone().css('display', 'block').bind('mousedown', startDrag);
|
| 111 |
|
| 112 |
if (whichspan) {
|
| 113 |
if (whichspan.poz == 'after') {
|
| 114 |
whichspan.after(clonespan);
|
| 115 |
}
|
| 116 |
else {
|
| 117 |
whichspan.before(clonespan);
|
| 118 |
}
|
| 119 |
}
|
| 120 |
else {
|
| 121 |
testA.append(clonespan);
|
| 122 |
}
|
| 123 |
}
|
| 124 |
|
| 125 |
function removeFromBox() {
|
| 126 |
activespan.remove();
|
| 127 |
$(document).unbind('mousemove', performDrag).unbind('mouseup', endDrag2);
|
| 128 |
$('#htmlbox-buttons-manager span.'+ activespan.attr('class')).show().bind('mousedown', startDrag);
|
| 129 |
}
|
| 130 |
|
| 131 |
function updateOptions() {
|
| 132 |
var options = [];
|
| 133 |
testA.find('span[@class]').each(function () {
|
| 134 |
options.push($(this).attr('class').replace(/^htmlbox-/, ''));
|
| 135 |
}).end();
|
| 136 |
$('#edit-htmlbox-buttons-order').val(options.join(', '));
|
| 137 |
}
|
| 138 |
|
| 139 |
|
| 140 |
function backanimate(e) {
|
| 141 |
activespan.css({left: '', top: ''});
|
| 142 |
if (e.pageX < testAreaRightX && e.pageX > testAreaLeftX && e.pageY < testAreaBottomY && e.pageY > testAreaTopY ) {
|
| 143 |
addToBox();
|
| 144 |
}
|
| 145 |
else {
|
| 146 |
activespan.bind('mouseup', addToBox);
|
| 147 |
}
|
| 148 |
}
|
| 149 |
|
| 150 |
function backanimate2(e) {
|
| 151 |
$('.helper', testA).remove();
|
| 152 |
|
| 153 |
if (e.pageX > testAreaRightX || e.pageX < testAreaLeftX || e.pageY > testAreaBottomY || e.pageY < testAreaTopY ) {
|
| 154 |
activespan.remove();
|
| 155 |
$('#htmlbox-buttons-manager span.'+ activespan.attr('class')).css('display', 'block').bind('mousedown', startDrag);
|
| 156 |
}
|
| 157 |
else {
|
| 158 |
var clonespan = $('#htmlbox-buttons-manager span.'+ activespan.attr('class')).clone(false).css('display', 'block').unbind('mouseup', addToBox).bind('mousedown', startDrag);
|
| 159 |
|
| 160 |
if (whichspan) {
|
| 161 |
if (whichspan.poz == 'after') {
|
| 162 |
whichspan.after(clonespan);
|
| 163 |
}
|
| 164 |
else {
|
| 165 |
whichspan.before(clonespan);
|
| 166 |
}
|
| 167 |
}
|
| 168 |
else {
|
| 169 |
testA.append(clonespan);
|
| 170 |
}
|
| 171 |
activespan.remove();
|
| 172 |
}
|
| 173 |
}
|
| 174 |
|
| 175 |
function init() {
|
| 176 |
$('div.htmlbox-buttons').before('<div class="htmlbox-buttons htmlbox-buttons-js"><div id="htmlbox-droparea"></div><div id="htmlbox-buttons-manager"></div></div>').find('span').each(function () {
|
| 177 |
$('#htmlbox-buttons-manager').append(this);
|
| 178 |
}).end().remove();
|
| 179 |
testA = $('#htmlbox-droparea');
|
| 180 |
testAthis = testA[0];
|
| 181 |
|
| 182 |
$.each($('#edit-htmlbox-buttons-order').val().split(','), function() {
|
| 183 |
var elem = $('#htmlbox-buttons-manager').find('span.htmlbox-'+ $.trim(this));
|
| 184 |
if (!elem.is('.htmlbox-separator_basic') && !elem.is('.htmlbox-separator_dots')) {
|
| 185 |
elem.hide();
|
| 186 |
}
|
| 187 |
testA.append(elem.clone(false).show());
|
| 188 |
});
|
| 189 |
window.setTimeout("$('#edit-htmlbox-buttons-order').parents('div.form-item:first').children().not('label').not('.description').hide()", 10);
|
| 190 |
|
| 191 |
var textNode = $('.htmlbox-buttons').find('span').bind('mousedown', startDrag).end().get(0).previousSibling;
|
| 192 |
if (textNode.nodeType == 3) {
|
| 193 |
textNode.nodeValue = Drupal.settings.htmlbox.order_description;
|
| 194 |
}
|
| 195 |
}
|
| 196 |
});
|