JS code style

hinted-selects
Vitaliy Filippov 2014-10-13 20:33:51 +04:00
parent cfd8911bdc
commit 00b9c3a608
12 changed files with 638 additions and 575 deletions

View File

@ -153,17 +153,16 @@ function DataFieldHandler()
}
}
function clearAttachmentFields() {
function clearAttachmentFields()
{
var element;
document.getElementById('data').value = '';
DataFieldHandler();
if ((element = document.getElementById('bigfile')))
element.checked = '';
document.getElementById('description').value = '';
/* Fire onchange so that the disabled state of the content-type
* radio buttons are also reset
*/
* radio buttons are also reset */
element = document.getElementById('ispatch');
element.checked = '';
bz_fireEvent(element, 'change');
@ -173,12 +172,16 @@ function clearAttachmentFields() {
/* Functions used when viewing patches in Diff mode. */
function collapse_all() {
function collapse_all()
{
var elem = document.checkboxform.firstChild;
while (elem != null) {
if (elem.firstChild != null) {
while (elem != null)
{
if (elem.firstChild != null)
{
var tbody = elem.firstChild.nextSibling;
if (tbody.className == 'file') {
if (tbody.className == 'file')
{
tbody.className = 'file_collapse';
twisty = get_twisty_from_tbody(tbody);
twisty.firstChild.nodeValue = '(+)';
@ -190,12 +193,16 @@ function collapse_all() {
return false;
}
function expand_all() {
function expand_all()
{
var elem = document.checkboxform.firstChild;
while (elem != null) {
if (elem.firstChild != null) {
while (elem != null)
{
if (elem.firstChild != null)
{
var tbody = elem.firstChild.nextSibling;
if (tbody.className == 'file_collapse') {
if (tbody.className == 'file_collapse')
{
tbody.className = 'file';
twisty = get_twisty_from_tbody(tbody);
twisty.firstChild.nodeValue = '(-)';
@ -209,53 +216,71 @@ function expand_all() {
var current_restore_elem;
function restore_all() {
function restore_all()
{
current_restore_elem = null;
incremental_restore();
}
function incremental_restore() {
if (!document.checkboxform.restore_indicator.checked) {
function incremental_restore()
{
if (!document.checkboxform.restore_indicator.checked)
{
return;
}
var next_restore_elem;
if (current_restore_elem) {
if (current_restore_elem)
{
next_restore_elem = current_restore_elem.nextSibling;
} else {
}
else
{
next_restore_elem = document.checkboxform.firstChild;
}
while (next_restore_elem != null) {
while (next_restore_elem != null)
{
current_restore_elem = next_restore_elem;
if (current_restore_elem.firstChild != null) {
if (current_restore_elem.firstChild != null)
{
restore_elem(current_restore_elem.firstChild.nextSibling);
}
next_restore_elem = current_restore_elem.nextSibling;
}
}
function restore_elem(elem, alertme) {
if (elem.className == 'file_collapse') {
function restore_elem(elem, alertme)
{
if (elem.className == 'file_collapse')
{
twisty = get_twisty_from_tbody(elem);
if (twisty.nextSibling.checked) {
if (twisty.nextSibling.checked)
{
elem.className = 'file';
twisty.firstChild.nodeValue = '(-)';
}
} else if (elem.className == 'file') {
}
else if (elem.className == 'file')
{
twisty = get_twisty_from_tbody(elem);
if (!twisty.nextSibling.checked) {
if (!twisty.nextSibling.checked)
{
elem.className = 'file_collapse';
twisty.firstChild.nodeValue = '(+)';
}
}
}
function twisty_click(twisty) {
function twisty_click(twisty)
{
tbody = get_tbody_from_twisty(twisty);
if (tbody.className == 'file') {
if (tbody.className == 'file')
{
tbody.className = 'file_collapse';
twisty.firstChild.nodeValue = '(+)';
twisty.nextSibling.checked = false;
} else {
}
else
{
tbody.className = 'file';
twisty.firstChild.nodeValue = '(-)';
twisty.nextSibling.checked = true;
@ -263,10 +288,12 @@ function twisty_click(twisty) {
return false;
}
function get_tbody_from_twisty(twisty) {
function get_tbody_from_twisty(twisty)
{
return twisty.parentNode.parentNode.parentNode.nextSibling;
}
function get_twisty_from_tbody(tbody) {
function get_twisty_from_tbody(tbody)
{
return tbody.previousSibling.firstChild.nextSibling.firstChild.firstChild;
}
@ -291,12 +318,11 @@ function redoEditAsComment(patchviewerinstalled)
function viewDiff(attachment_id, patchviewerinstalled)
{
switchToMode('diff', patchviewerinstalled);
// If we have not viewed as diff before, set the view diff frame URL
if (!has_viewed_as_diff) {
if (!has_viewed_as_diff)
{
var viewDiffFrame = document.getElementById('viewDiffFrame');
viewDiffFrame.src =
'attachment.cgi?id=' + attachment_id + '&action=diff&headers=0';
viewDiffFrame.src = 'attachment.cgi?id=' + attachment_id + '&action=diff&headers=0';
has_viewed_as_diff = 1;
}
}
@ -315,38 +341,46 @@ function switchToMode(mode, patchviewerinstalled)
}
// Switch out of current mode
if (current_mode == 'edit') {
if (current_mode == 'edit')
{
hideElementById('editFrame');
hideElementById('undoEditButton');
} else if (current_mode == 'raw') {
}
else if (current_mode == 'raw')
{
hideElementById('viewFrame');
if (patchviewerinstalled)
hideElementById('viewDiffButton');
hideElementById('viewDiffButton');
hideElementById(has_edited ? 'redoEditButton' : 'editButton');
hideElementById('smallCommentFrame');
} else if (current_mode == 'diff') {
}
else if (current_mode == 'diff')
{
if (patchviewerinstalled)
hideElementById('viewDiffFrame');
hideElementById('viewDiffFrame');
hideElementById('viewRawButton');
hideElementById(has_edited ? 'redoEditButton' : 'editButton');
hideElementById('smallCommentFrame');
}
// Switch into new mode
if (mode == 'edit') {
if (mode == 'edit')
{
showElementById('editFrame');
showElementById('undoEditButton');
} else if (mode == 'raw') {
}
else if (mode == 'raw')
{
showElementById('viewFrame');
if (patchviewerinstalled)
showElementById('viewDiffButton');
if (patchviewerinstalled)
showElementById('viewDiffButton');
showElementById(has_edited ? 'redoEditButton' : 'editButton');
showElementById('smallCommentFrame');
} else if (mode == 'diff') {
if (patchviewerinstalled)
}
else if (mode == 'diff')
{
if (patchviewerinstalled)
showElementById('viewDiffFrame');
showElementById('viewRawButton');
showElementById(has_edited ? 'redoEditButton' : 'editButton');
showElementById('smallCommentFrame');
@ -359,16 +393,17 @@ function switchToMode(mode, patchviewerinstalled)
function hideElementById(id)
{
var elm = document.getElementById(id);
if (elm) {
if (elm)
elm.style.display = 'none';
}
}
function showElementById(id, val)
{
var elm = document.getElementById(id);
if (elm) {
if (!val) val = 'inline';
if (elm)
{
if (!val)
val = 'inline';
elm.style.display = val;
}
}
@ -377,14 +412,13 @@ function normalizeComments()
{
// Remove the unused comment field from the document so its contents
// do not get transmitted back to the server.
var small = document.getElementById('smallCommentFrame');
var big = document.getElementById('editFrame');
if ( (small) && (small.style.display == 'none') )
if (small && small.style.display == 'none')
{
small.parentNode.removeChild(small);
}
if ( (big) && (big.style.display == 'none') )
if (big && big.style.display == 'none')
{
big.parentNode.removeChild(big);
}

View File

@ -4,64 +4,64 @@
function onChangeType()
{
var type_field = document.getElementById('type');
var value_field = document.getElementById('value_field_id');
if (type_field.value == constants.FIELD_TYPE_SINGLE_SELECT ||
type_field.value == constants.FIELD_TYPE_MULTI_SELECT)
{
value_field.disabled = false;
document.getElementById('value_field_row').style.display = '';
if (document.getElementById('action').value == 'new')
var type_field = document.getElementById('type');
var value_field = document.getElementById('value_field_id');
if (type_field.value == constants.FIELD_TYPE_SINGLE_SELECT ||
type_field.value == constants.FIELD_TYPE_MULTI_SELECT)
{
document.getElementById('default_value_row').style.display = 'none';
value_field.disabled = false;
document.getElementById('value_field_row').style.display = '';
if (document.getElementById('action').value == 'new')
{
document.getElementById('default_value_row').style.display = 'none';
}
}
}
else
{
value_field.disabled = true;
document.getElementById('value_field_row').style.display = 'none';
document.getElementById('default_value_row').style.display = '';
}
var rev_value_field = document.getElementById('bug_id_rev_value_field_id');
if (type_field.value == constants.FIELD_TYPE_BUG_ID_REV)
{
rev_value_field.name = 'value_field_id';
value_field.name = '';
document.getElementById('bug_id_rev_row').style.display = '';
}
else
{
rev_value_field.name = '';
value_field.name = 'value_field_id';
document.getElementById('bug_id_rev_row').style.display = 'none';
}
document.getElementById('add_to_deps_row').style.display
= type_field.value == constants.FIELD_TYPE_BUG_ID ? '' : 'none';
var u = document.getElementById('nullable');
u.disabled = type_field.value != constants.FIELD_TYPE_SINGLE_SELECT;
if (u.disabled)
u.checked = false;
u = type_field.value == constants.FIELD_TYPE_EXTURL;
document.getElementById('url_row').style.display = u ? '' : 'none';
onChangeNullable();
else
{
value_field.disabled = true;
document.getElementById('value_field_row').style.display = 'none';
document.getElementById('default_value_row').style.display = '';
}
var rev_value_field = document.getElementById('bug_id_rev_value_field_id');
if (type_field.value == constants.FIELD_TYPE_BUG_ID_REV)
{
rev_value_field.name = 'value_field_id';
value_field.name = '';
document.getElementById('bug_id_rev_row').style.display = '';
}
else
{
rev_value_field.name = '';
value_field.name = 'value_field_id';
document.getElementById('bug_id_rev_row').style.display = 'none';
}
document.getElementById('add_to_deps_row').style.display
= type_field.value == constants.FIELD_TYPE_BUG_ID ? '' : 'none';
var u = document.getElementById('nullable');
u.disabled = type_field.value != constants.FIELD_TYPE_SINGLE_SELECT;
if (u.disabled)
u.checked = false;
u = type_field.value == constants.FIELD_TYPE_EXTURL;
document.getElementById('url_row').style.display = u ? '' : 'none';
onChangeNullable();
}
function onChangeNullable()
{
var u = document.getElementById('nullable');
var n = document.getElementById('allow_null_in_row');
var c = document.getElementById('null_field_id_row');
c.style.display = u.checked ? '' : 'none';
if (n)
n.style.display = c.style.display;
var u = document.getElementById('nullable');
var n = document.getElementById('allow_null_in_row');
var c = document.getElementById('null_field_id_row');
c.style.display = u.checked ? '' : 'none';
if (n)
n.style.display = c.style.display;
}
function onChangeCloned()
{
var u = document.getElementById('clone_bug');
var n = document.getElementById('allow_clone_in_row');
var c = document.getElementById('clone_field_id_row');
c.style.display = u.checked ? '' : 'none';
if (n)
n.style.display = c.style.display;
var u = document.getElementById('clone_bug');
var n = document.getElementById('allow_clone_in_row');
var c = document.getElementById('clone_field_id_row');
c.style.display = u.checked ? '' : 'none';
if (n)
n.style.display = c.style.display;
}

View File

@ -20,32 +20,36 @@
* André Batosti <batosti@async.com.br>
*/
if (!Node) {
if (!Node)
{
// MSIE doesn't define Node, so provide a compatibility object
var Node = { TEXT_NODE: 3 }
}
if (!highlighted) {
if (!highlighted)
{
var highlighted = 0;
var highlightedclass = "";
var highlightedover = 0;
}
function doToggle(node, event) {
function doToggle(node, event)
{
var deep = event.altKey || event.ctrlKey;
if (node.nodeType == Node.TEXT_NODE)
node = node.parentNode;
var toggle = node.nextSibling;
while (toggle && toggle.tagName != "UL")
toggle = toggle.nextSibling;
if (toggle) {
if (deep) {
if (toggle)
{
if (deep)
{
var direction = toggleDisplay(toggle, node);
changeChildren(toggle, direction);
} else {
}
else
{
toggleDisplay(toggle, node);
}
}
@ -56,9 +60,11 @@ function doToggle(node, event) {
return false;
}
function changeChildren(node, direction) {
function changeChildren(node, direction)
{
var item = node.firstChild;
while (item) {
while (item)
{
/* find the LI inside the UL I got */
while (item && item.tagName != "LI")
item = item.nextSibling;
@ -69,38 +75,40 @@ function changeChildren(node, direction) {
var child = item.firstChild;
while (child && child.tagName != "A")
child = child.nextSibling;
if (!child) {
if (!child)
return
}
var bullet = child;
/* and check if it has its own sublist */
var sublist = item.firstChild;
while (sublist && sublist.tagName != "UL")
sublist = sublist.nextSibling;
if (sublist) {
if (direction && isClosed(sublist)) {
if (sublist)
{
if (direction && isClosed(sublist))
openNode(sublist, bullet);
} else if (!direction && !isClosed(sublist)) {
else if (!direction && !isClosed(sublist))
closeNode(sublist, bullet);
}
changeChildren(sublist, direction)
}
item = item.nextSibling;
}
}
function openNode(node, bullet) {
function openNode(node, bullet)
{
node.style.display = "block";
bullet.className = "b b_open";
}
function closeNode(node, bullet) {
function closeNode(node, bullet)
{
node.style.display = "none";
bullet.className = "b b_closed";
}
function isClosed(node) {
function isClosed(node)
{
/* XXX we should in fact check our *computed* style, not the display
* attribute of the current node, which may be inherited and not
* set. However, this really only matters when changing the default
@ -108,25 +116,27 @@ function isClosed(node) {
return node.style.display == "none";
}
function toggleDisplay(node, bullet) {
if (isClosed(node)) {
function toggleDisplay(node, bullet)
{
if (isClosed(node))
{
openNode(node, bullet);
return true;
}
closeNode(node, bullet);
return false;
}
function duplicated(element) {
var allsumm= document.getElementsByTagName("span");
if (highlighted) {
for (i = 0;i < allsumm.length; i++) {
if (allsumm.item(i).id == highlighted) {
function duplicated(element)
{
var allsumm = document.getElementsByTagName("span");
if (highlighted)
{
for (var i = 0; i < allsumm.length; i++)
if (allsumm.item(i).id == highlighted)
allsumm.item(i).className = highlightedclass;
}
}
if (highlighted == element) {
if (highlighted == element)
{
highlighted = 0;
return;
}
@ -134,24 +144,25 @@ function duplicated(element) {
highlighted = element;
var elem = document.getElementById(element);
highlightedclass = elem.className;
for (var i = 0;i < allsumm.length; i++) {
if (allsumm.item(i).id == element) {
for (var i = 0;i < allsumm.length; i++)
if (allsumm.item(i).id == element)
allsumm.item(i).className = "summ_h";
}
}
}
function duplicatedover(element) {
if (!highlighted) {
function duplicatedover(element)
{
if (!highlighted)
{
highlightedover = 1;
duplicated(element);
}
}
function duplicatedout(element) {
if (highlighted == element && highlightedover) {
function duplicatedout(element)
{
if (highlighted == element && highlightedover)
{
highlightedover = 0;
duplicated(element);
}
}

View File

@ -78,25 +78,25 @@ function showEditableField(e, ContainerInputArray)
* var ContainerInputArray[3]: the original value from the page loading.
*
*/
function checkForChangedFieldValues(e, ContainerInputArray ) {
function checkForChangedFieldValues(e, ContainerInputArray)
{
var el = document.getElementById(ContainerInputArray[2]);
var unhide = false;
if ( el ) {
if ( el.value != ContainerInputArray[3] ||
( el.value == "" && el.id != "alias") ) {
if (el)
{
if (el.value != ContainerInputArray[3] ||
el.value == "" && el.id != "alias")
{
unhide = true;
}
else {
var set_default = document.getElementById("set_default_" +
ContainerInputArray[2]);
if ( set_default ) {
if(set_default.checked){
unhide = true;
}
}
else
{
var set_default = document.getElementById("set_default_" + ContainerInputArray[2]);
if (set_default && set_default.checked)
unhide = true;
}
}
if(unhide)
if (unhide)
{
addClass(ContainerInputArray[0], 'bz_default_hidden');
removeClass(ContainerInputArray[1], 'bz_default_hidden');
@ -243,7 +243,8 @@ function setResolutionToDuplicate(duplicate_or_move_bug_status)
bz_fireEvent(status, 'change');
resolution.value = "DUPLICATE";
bz_fireEvent(resolution, 'change');
if (e.preventDefault) e.preventDefault();
if (e.preventDefault)
e.preventDefault();
return false;
}

View File

@ -17,7 +17,7 @@
var mini_login_constants;
function show_mini_login_form( suffix )
function show_mini_login_form(suffix)
{
var login_link = document.getElementById('login_link' + suffix);
var login_form = document.getElementById('mini_login' + suffix);
@ -29,7 +29,7 @@ function show_mini_login_form( suffix )
return false;
}
function hide_mini_login_form( suffix )
function hide_mini_login_form(suffix)
{
var login_link = document.getElementById('login_link' + suffix);
var login_form = document.getElementById('mini_login' + suffix);
@ -40,7 +40,7 @@ function hide_mini_login_form( suffix )
return false;
}
function show_forgot_form( suffix )
function show_forgot_form(suffix)
{
var forgot_link = document.getElementById('forgot_link' + suffix);
var forgot_form = document.getElementById('forgot_form' + suffix);
@ -51,7 +51,7 @@ function show_forgot_form( suffix )
return false;
}
function hide_forgot_form( suffix )
function hide_forgot_form(suffix)
{
var forgot_link = document.getElementById('forgot_link' + suffix);
var forgot_form = document.getElementById('forgot_form' + suffix);
@ -62,7 +62,7 @@ function hide_forgot_form( suffix )
return false;
}
function init_mini_login_form( suffix )
function init_mini_login_form(suffix)
{
var mini_login = document.getElementById('Bugzilla_login' + suffix );
var mini_password = document.getElementById('Bugzilla_password' + suffix );

View File

@ -41,8 +41,7 @@ function generateHelp()
// Create help controls (a div to hold help text and an iframe
// to mask any and all controls under the popup)
document.write('<div id="helpDiv" style="display: none;"><\/div>');
document.write('<iframe id="helpIframe" src="about:blank"');
document.write(' frameborder="0" scrolling="no"><\/iframe>');
document.write('<iframe id="helpIframe" src="about:blank" frameborder="0" scrolling="no"><\/iframe>');
return true;
}
@ -61,13 +60,10 @@ function enableHelp()
// MS decided to add fieldsets to the elements array; and
// Mozilla decided to copy this brokenness. Grr.
for (var i = 0; i < document.forms.length; i++) {
for (var j = 0; j < document.forms[i].elements.length; j++) {
if (document.forms[i].elements[j].tagName != 'FIELDSET') {
for (var i = 0; i < document.forms.length; i++)
for (var j = 0; j < document.forms[i].elements.length; j++)
if (document.forms[i].elements[j].tagName != 'FIELDSET')
document.forms[i].elements[j].onmouseover = showHelp;
}
}
}
document.body.onclick = hideHelp;
return true;
@ -76,7 +72,8 @@ function enableHelp()
/**
* Show the help popup for a form element.
*/
function showHelp() {
function showHelp()
{
if (!g_helpIframe || !g_helpDiv || !g_helpTexts[this.name])
return;
@ -101,9 +98,9 @@ function showHelp() {
/**
* Hide the help popup.
*/
function hideHelp() {
function hideHelp()
{
if (!g_helpIframe || !g_helpDiv)
return;
g_helpIframe.style.display = g_helpDiv.style.display = 'none';
}

View File

@ -17,7 +17,8 @@
* Contributor(s): Marc Schumann <wurblzap@gmail.com>
*/
function sortedList_moveItem(paramName, direction, separator) {
function sortedList_moveItem(paramName, direction, separator)
{
var select = document.getElementById('select_' + paramName);
var inputField = document.getElementById('input_' + paramName);
var currentIndex = select.selectedIndex;
@ -26,11 +27,14 @@ function sortedList_moveItem(paramName, direction, separator) {
var optionNewIndex;
/* Return if no selection */
if (currentIndex < 0) return;
if (currentIndex < 0)
return;
/* Return if trying to move upward out of list */
if (newIndex < 0) return;
if (newIndex < 0)
return;
/* Return if trying to move downward out of list */
if (newIndex >= select.length) return;
if (newIndex >= select.length)
return;
/* Move selection */
optionNewIndex = select.options[newIndex];
@ -44,17 +48,16 @@ function sortedList_moveItem(paramName, direction, separator) {
populateInputField(select, inputField, separator);
}
function populateInputField(select, inputField, separator) {
function populateInputField(select, inputField, separator)
{
var i;
var stringRepresentation = '';
for (i = 0; i < select.length; i++) {
if (select.options[i].value == separator) {
for (i = 0; i < select.length; i++)
{
if (select.options[i].value == separator)
break;
}
if (stringRepresentation != '') {
if (stringRepresentation != '')
stringRepresentation += ',';
}
stringRepresentation += select.options[i].value;
}
inputField.value = stringRepresentation;

View File

@ -50,7 +50,8 @@
* @global last_sel Array that contains last list of products so we know what
* has changed, and optimize for additions.
*/
function selectProduct(product, component, version, milestone, anyval) {
function selectProduct(product, component, version, milestone, anyval)
{
// This is to avoid handling events that occur before the form
// itself is ready, which could happen in buggy browsers.
if (!product)
@ -63,7 +64,8 @@ function selectProduct(product, component, version, milestone, anyval) {
// If this is the first load and nothing is selected, no need to
// merge and sort all lists; they are created sorted.
if ((first_load) && (product.selectedIndex == -1)) {
if (first_load && product.selectedIndex == -1)
{
first_load = false;
return;
}
@ -87,27 +89,27 @@ function selectProduct(product, component, version, milestone, anyval) {
// If nothing is selected, or the special "Any" option is selected
// which represents all products, then pick all products so we show
// all components.
var findall = (product.selectedIndex == -1
|| (anyval != null && product.options[0].selected));
var findall = (product.selectedIndex == -1 || (anyval != null && product.options[0].selected));
if (useclassification) {
if (useclassification)
{
// Update index based on the complete product array.
sel = get_selection(product, findall, true, anyval);
for (var i=0; i<sel.length; i++)
for (var i = 0; i < sel.length; i++)
sel[i] = prods[sel[i]];
}
else {
else
sel = get_selection(product, findall, false, anyval);
}
if (!findall) {
if (!findall)
{
// Save sel for the next invocation of selectProduct().
var tmp = sel;
// This is an optimization: if we have just added products to an
// existing selection, no need to clear the form controls and add
// everybody again; just merge the new ones with the existing
// options.
if ((last_sel.length > 0) && (last_sel.length < sel.length)) {
if (last_sel.length > 0 && last_sel.length < sel.length)
{
sel = fake_diff_array(sel, last_sel);
merging = true;
}
@ -115,19 +117,22 @@ function selectProduct(product, component, version, milestone, anyval) {
}
// Do the actual fill/update.
if (component) {
if (component)
{
var saved_cpts = get_selection(component, false, true, null);
updateSelect(cpts, sel, component, merging, anyval);
restoreSelection(component, saved_cpts);
}
if (version) {
if (version)
{
var saved_vers = get_selection(version, false, true, null);
updateSelect(vers, sel, version, merging, anyval);
restoreSelection(version, saved_vers);
}
if (milestone) {
if (milestone)
{
var saved_tms = get_selection(milestone, false, true, null);
updateSelect(tms, sel, milestone, merging, anyval);
restoreSelection(milestone, saved_tms);
@ -160,16 +165,19 @@ function selectProduct(product, component, version, milestone, anyval) {
*
* This would clear compsel and add 'ComponentC' and 'ComponentD' to it.
*/
function updateSelect(array, sel, target, merging, anyval) {
function updateSelect(array, sel, target, merging, anyval)
{
var i, item;
// If we have no versions/components/milestones.
if (array.length < 1) {
if (array.length < 1)
{
target.options.length = 0;
return false;
}
if (merging) {
if (merging)
{
// Array merging/sorting in the case of multiple selections
// merge in the current options with the first selection.
item = merge_arrays(array[sel[0]], target.options, 1);
@ -178,7 +186,8 @@ function updateSelect(array, sel, target, merging, anyval) {
for (i = 1 ; i < sel.length ; i++)
item = merge_arrays(array[sel[i]], item, 0);
}
else if (sel.length > 1) {
else if (sel.length > 1)
{
// Here we micro-optimize for two arrays to avoid merging with a
// null array.
item = merge_arrays(array[sel[0]],array[sel[1]], 0);
@ -187,7 +196,8 @@ function updateSelect(array, sel, target, merging, anyval) {
for (i = 2; i < sel.length; i++)
item = merge_arrays(item, array[sel[i]], 0);
}
else {
else
{
// Single item in selection, just get me the list.
item = array[sel[0]];
}
@ -212,7 +222,8 @@ function updateSelect(array, sel, target, merging, anyval) {
* @param control Select element of which selected options are to be restored.
* @param selnames Array of option names to select.
*/
function restoreSelection(control, selnames) {
function restoreSelection(control, selnames)
{
// Right. This sucks but I see no way to avoid going through the
// list and comparing to the contents of the control.
for (var j = 0; j < selnames.length; j++)
@ -229,19 +240,19 @@ function restoreSelection(control, selnames) {
* @param b Second array to compare.
* @return Array of elements in a but not in b.
*/
function fake_diff_array(a, b) {
function fake_diff_array(a, b)
{
var newsel = new Array();
var found = false;
// Do a boring array diff to see who's new.
for (var ia in a) {
for (var ia in a)
{
for (var ib in b)
if (a[ia] == b[ib])
found = true;
if (!found)
newsel[newsel.length] = a[ia];
found = false;
}
@ -259,7 +270,8 @@ function fake_diff_array(a, b) {
* an array.
* @return Merged and sorted array.
*/
function merge_arrays(a, b, b_is_select) {
function merge_arrays(a, b, b_is_select)
{
var pos_a = 0;
var pos_b = 0;
var ret = new Array();
@ -268,25 +280,29 @@ function merge_arrays(a, b, b_is_select) {
// Iterate through both arrays and add the larger item to the return
// list. Remove dupes, too. Use toLowerCase to provide
// case-insensitivity.
while ((pos_a < a.length) && (pos_b < b.length)) {
while (pos_a < a.length && pos_b < b.length)
{
aitem = a[pos_a];
if (b_is_select)
bitem = b[pos_b].value;
else
bitem = b[pos_b];
// Smaller item in list a.
if (aitem.toLowerCase() < bitem.toLowerCase()) {
if (aitem.toLowerCase() < bitem.toLowerCase())
{
ret[ret.length] = aitem;
pos_a++;
}
else {
else
{
// Smaller item in list b.
if (aitem.toLowerCase() > bitem.toLowerCase()) {
if (aitem.toLowerCase() > bitem.toLowerCase())
{
ret[ret.length] = bitem;
pos_b++;
}
else {
else
{
// List contents are equal, include both counters.
ret[ret.length] = aitem;
pos_a++;
@ -297,11 +313,13 @@ function merge_arrays(a, b, b_is_select) {
// Catch leftovers here. These sections are ugly code-copying.
if (pos_a < a.length)
for (; pos_a < a.length ; pos_a++)
for (; pos_a < a.length; pos_a++)
ret[ret.length] = a[pos_a];
if (pos_b < b.length) {
for (; pos_b < b.length; pos_b++) {
if (pos_b < b.length)
{
for (; pos_b < b.length; pos_b++)
{
if (b_is_select)
bitem = b[pos_b].value;
else
@ -325,15 +343,13 @@ function merge_arrays(a, b, b_is_select) {
* be null if not used.
* @return Array of all or selected indexes or values.
*/
function get_selection(control, findall, want_values, anyval) {
function get_selection(control, findall, want_values, anyval)
{
var ret = new Array();
if ((!findall) && (control.selectedIndex == -1))
if (!findall && control.selectedIndex == -1)
return ret;
for (var i = (anyval != null ? 1 : 0); i < control.length; i++)
if (findall || control.options[i].selected)
ret[ret.length] = want_values ? control.options[i].value : i;
return ret;
}

View File

@ -5,57 +5,57 @@
// Requires global vars: queryform, checkwidths, userAutocomplete
onDomReady(function()
{
document.forms[queryform].content.focus();
if (document.getElementById('deadlinefrom'))
{
Calendar.set('deadlinefrom');
Calendar.set('deadlineto');
}
new SimpleAutocomplete("email1", userAutocomplete, { emptyText: 'No users found' });
new SimpleAutocomplete("email2", userAutocomplete, { emptyText: 'No users found' });
Calendar.set('chfieldfrom');
Calendar.set('chfieldto');
new SimpleAutocomplete("chfieldwho", userAutocomplete, { emptyText: 'No users found' });
addKeywordsAutocomplete();
var lim = 250;
function checkw(e)
{
var s = document.getElementById(e);
s.style.minWidth = '100%';
// Expand select fields on hover to maximum available screen width
if (s && s.offsetWidth > lim)
document.forms[queryform].content.focus();
if (document.getElementById('deadlinefrom'))
{
s.style.minWidth = lim+'px';
s.style.width = lim+'px';
addListener(s, 'mouseover', function(e)
{
e = e || window.event;
var f = e.relatedTarget || e.fromElement;
if (f == s || f.parentNode == s || !s.style.width && s.offsetWidth <= lim)
return;
var c = s;
while (c && c.nodeName != 'TABLE')
c = c.parentNode;
var w = (lim+c.parentNode.offsetWidth-c.offsetWidth);
if (w > lim+10)
{
s.style.width = 'auto';
s.style.maxWidth = w + 'px';
}
});
addListener(s, 'mouseout', function(e) {
e = e || window.event;
var t = e.relatedTarget || e.toElement;
if (t == s || t.parentNode == s)
return;
s.style.width = lim+'px';
s.style.maxWidth = '';
});
Calendar.set('deadlinefrom');
Calendar.set('deadlineto');
}
new SimpleAutocomplete("email1", userAutocomplete, { emptyText: 'No users found' });
new SimpleAutocomplete("email2", userAutocomplete, { emptyText: 'No users found' });
Calendar.set('chfieldfrom');
Calendar.set('chfieldto');
new SimpleAutocomplete("chfieldwho", userAutocomplete, { emptyText: 'No users found' });
addKeywordsAutocomplete();
var lim = 250;
function checkw(e)
{
var s = document.getElementById(e);
s.style.minWidth = '100%';
// Expand select fields on hover to maximum available screen width
if (s && s.offsetWidth > lim)
{
s.style.minWidth = lim+'px';
s.style.width = lim+'px';
addListener(s, 'mouseover', function(e)
{
e = e || window.event;
var f = e.relatedTarget || e.fromElement;
if (f == s || f.parentNode == s || !s.style.width && s.offsetWidth <= lim)
return;
var c = s;
while (c && c.nodeName != 'TABLE')
c = c.parentNode;
var w = (lim+c.parentNode.offsetWidth-c.offsetWidth);
if (w > lim+10)
{
s.style.width = 'auto';
s.style.maxWidth = w + 'px';
}
});
addListener(s, 'mouseout', function(e) {
e = e || window.event;
var t = e.relatedTarget || e.toElement;
if (t == s || t.parentNode == s)
return;
s.style.width = lim+'px';
s.style.maxWidth = '';
});
}
}
for (var i in checkwidths)
{
checkw(checkwidths[i]);
}
}
for (var i in checkwidths)
{
checkw(checkwidths[i]);
}
});

View File

@ -11,17 +11,17 @@
resizeParentIframe = function()
{
if ((/resize/.exec(window.location.hash) ||
/[&\?]_resize=1/.exec(window.location.href)) && 'postMessage' in parent)
{
var w = document.body.scrollWidth;
var h = document.body.scrollHeight;
parent.postMessage('resize(w='+w+';h='+h+')', '*');
}
return true;
if ((/resize/.exec(window.location.hash) ||
/[&\?]_resize=1/.exec(window.location.href)) && 'postMessage' in parent)
{
var w = document.body.scrollWidth;
var h = document.body.scrollHeight;
parent.postMessage('resize(w='+w+';h='+h+')', '*');
}
return true;
};
if (window.addEventListener)
window.addEventListener('load', resizeParentIframe, false);
window.addEventListener('load', resizeParentIframe, false);
else if (window.attachEvent)
window.attachEvent('onload', resizeParentIframe);
window.attachEvent('onload', resizeParentIframe);

View File

@ -13,335 +13,335 @@ var cuttedids = [];
// Добавить карточки для багов с ID'шниками из поля addbugs
function addNewCards()
{
for (var i = idlist.length-1; i >= 0; i--)
{
if (idlist[i] === '')
idlist.pop();
else
break;
}
var val = document.getElementById('addbugs').value;
var re = /(\d+)/g;
var m;
while (m = re.exec(val))
idlist.push(m[1]);
document.getElementById('idlist_value').value = idlist.join(',');
document.getElementById('scrumform').submit();
for (var i = idlist.length-1; i >= 0; i--)
{
if (idlist[i] === '')
idlist.pop();
else
break;
}
var val = document.getElementById('addbugs').value;
var re = /(\d+)/g;
var m;
while (m = re.exec(val))
idlist.push(m[1]);
document.getElementById('idlist_value').value = idlist.join(',');
document.getElementById('scrumform').submit();
}
// Добавить пустую страницу
function addEmptyPage()
{
for (var i = 0; i < nr*nc; i++)
idlist.push('');
document.getElementById('idlist_value').value = idlist.join(',');
document.getElementById('scrumform').submit();
for (var i = 0; i < nr*nc; i++)
idlist.push('');
document.getElementById('idlist_value').value = idlist.join(',');
document.getElementById('scrumform').submit();
}
// Обработчик нажатия Enter на поле addbugs
function addNewIfEnter(ev)
{
if (ev.keyCode == 10 || ev.keyCode == 13)
{
addNewCards();
return true;
}
return false;
if (ev.keyCode == 10 || ev.keyCode == 13)
{
addNewCards();
return true;
}
return false;
}
// Удалить все карточки
function deleteAllCards()
{
idlist = [];
document.getElementById('idlist_value').value = idlist.join(',');
document.getElementById('pages').innerHTML = '';
document.getElementById('scrumform').submit();
idlist = [];
document.getElementById('idlist_value').value = idlist.join(',');
document.getElementById('pages').innerHTML = '';
document.getElementById('scrumform').submit();
}
// Сбросить состояние кнопок, выделение карточек, режим вставки
function resetAll()
{
if (pressedButton)
{
buttonHandler(null, pressedButton);
pressedButton = null;
}
deselectAll();
stopPaste();
return true;
if (pressedButton)
{
buttonHandler(null, pressedButton);
pressedButton = null;
}
deselectAll();
stopPaste();
return true;
}
// Снять выделение
function deselectAll()
{
for (var i in selectedcards)
{
var e = document.getElementById('cardtd_'+i);
e.className = 'cardtd';
}
selectedcards = {};
for (var i in selectedcards)
{
var e = document.getElementById('cardtd_'+i);
e.className = 'cardtd';
}
selectedcards = {};
}
// Обработчик, пытающийся по иерархии найти кнопку (id=btn_*),
// и вызвать на ней buttonHandler
function guessButton(ev)
{
ev = DragMaster.fixEvent(ev);
var t;
if (t = searchButtonTarget(ev))
return buttonHandler(ev, t);
return true;
ev = DragMaster.fixEvent(ev);
var t;
if (t = searchButtonTarget(ev))
return buttonHandler(ev, t);
return true;
}
// Обработчик mousedown и mouseup на кнопках (id=btn_*)
function buttonHandler(ev, target)
{
if (!pressedButton)
{
pressedButton = target;
target.style.borderStyle = 'inset';
target.style.padding = '4px 2px 2px 4px';
}
else if (pressedButton == target)
{
target.style.borderStyle = 'outset';
target.style.padding = '3px';
pressedButton = null;
if (target.id == 'btn_cut')
deleteSelectedCards(true);
else if (target.id == 'btn_delete')
deleteSelectedCards(false);
else if (target.id == 'btn_paste')
pasteCards();
else if (target.id == 'btn_paste_beg')
doPasteCards(0);
return true;
}
return false;
if (!pressedButton)
{
pressedButton = target;
target.style.borderStyle = 'inset';
target.style.padding = '4px 2px 2px 4px';
}
else if (pressedButton == target)
{
target.style.borderStyle = 'outset';
target.style.padding = '3px';
pressedButton = null;
if (target.id == 'btn_cut')
deleteSelectedCards(true);
else if (target.id == 'btn_delete')
deleteSelectedCards(false);
else if (target.id == 'btn_paste')
pasteCards();
else if (target.id == 'btn_paste_beg')
doPasteCards(0);
return true;
}
return false;
}
// Обработчик клика-выделения по карточке
function selectCard(ev, target)
{
var empty = isEmptyHash(selectedcards, target.id.substr(7));
if (pasteMode)
{
doPasteCards(id_to_coord(target.id)+1);
return true;
}
else if (ctrl || !selectedcards[target.id.substr(7)])
{
if (!ctrl)
deselectAll();
var issel = target.className == 'cardtd selected';
target.className = issel ? 'cardtd' : 'cardtd selected';
if (issel)
delete selectedcards[target.id.substr(7)];
else
selectedcards[target.id.substr(7)] = true;
return true;
}
return false;
var empty = isEmptyHash(selectedcards, target.id.substr(7));
if (pasteMode)
{
doPasteCards(id_to_coord(target.id)+1);
return true;
}
else if (ctrl || !selectedcards[target.id.substr(7)])
{
if (!ctrl)
deselectAll();
var issel = target.className == 'cardtd selected';
target.className = issel ? 'cardtd' : 'cardtd selected';
if (issel)
delete selectedcards[target.id.substr(7)];
else
selectedcards[target.id.substr(7)] = true;
return true;
}
return false;
}
// Подсветка карточки в режиме вставки
function highlightCard(ev)
{
if (pasteMode)
{
ev = DragMaster.fixEvent(ev);
var t = searchCardTarget(ev);
t.className = 'cardtd highlight';
highlitCard = t;
}
if (pasteMode)
{
ev = DragMaster.fixEvent(ev);
var t = searchCardTarget(ev);
t.className = 'cardtd highlight';
highlitCard = t;
}
}
// Снятие подсветки карточки в режиме вставки
function unlightCard(ev)
{
if (pasteMode)
{
ev = DragMaster.fixEvent(ev);
var t = searchCardTarget(ev);
t.className = 'cardtd';
}
if (pasteMode)
{
ev = DragMaster.fixEvent(ev);
var t = searchCardTarget(ev);
t.className = 'cardtd';
}
}
// Преобразование номера в координаты [лист, строка, столбец]
function to_coord(i)
{
var to_k = Math.floor(i / nr / nc);
var to_i = Math.floor((i / nc) % nr);
var to_j = Math.floor(i % nc);
return [to_k, to_i, to_j];
var to_k = Math.floor(i / nr / nc);
var to_i = Math.floor((i / nc) % nr);
var to_j = Math.floor(i % nc);
return [to_k, to_i, to_j];
}
// Преобразование номера в строку с координатами лист_строка_столбец
function to_coord_id(i)
{
return to_coord(i).join('_');
return to_coord(i).join('_');
}
// Преобразование id элемента (.*лист_строка_столбец.*) в номер
function id_to_coord(id)
{
var m = /(\d+)_(\d+)_(\d+)/.exec(id.substr(7));
return (parseInt(m[1])*nr+parseInt(m[2]))*nc+parseInt(m[3]);
var m = /(\d+)_(\d+)_(\d+)/.exec(id.substr(7));
return (parseInt(m[1])*nr+parseInt(m[2]))*nc+parseInt(m[3]);
}
// Удалить(cut=0)/вырезать(cut=1) выделенные карточки
function deleteSelectedCards(cut)
{
var shift = 0;
var coord = 0;
var n = nr * nc * np;
if (cut)
{
cuttedcards = [];
cuttedids = [];
}
for (var k = 0; k < np; k++)
{
for (var i = 0; i < nr; i++)
var shift = 0;
var coord = 0;
var n = nr * nc * np;
if (cut)
{
for (var j = 0; j < nc; j++, coord++)
{
var s = selectedcards[k+'_'+i+'_'+j];
var e = document.getElementById('cardtd_'+k+'_'+i+'_'+j);
if (!e)
continue;
if (s)
{
if (cut)
{
cuttedcards.push(e.innerHTML);
cuttedids.push(idlist[coord]);
}
shift++;
}
else if (shift > 0)
{
var to = to_coord_id(coord-shift);
document.getElementById('cardtd_'+to).innerHTML = e.innerHTML;
idlist[coord-shift] = idlist[coord];
}
else if (coord + shift < n)
continue;
// во всех трёх случаях - если выделена для
// удаления, если перемещена в другую, или
// если находится в конце - очищаем
e.innerHTML = emptycell;
idlist[coord] = '';
}
cuttedcards = [];
cuttedids = [];
}
}
if (cut && cuttedids.length)
document.getElementById('cut_status').innerHTML = 'Вырезано '+cuttedids.length+' карточек.';
deselectAll();
document.getElementById('idlist_value').value = idlist.join(',');
for (var k = 0; k < np; k++)
{
for (var i = 0; i < nr; i++)
{
for (var j = 0; j < nc; j++, coord++)
{
var s = selectedcards[k+'_'+i+'_'+j];
var e = document.getElementById('cardtd_'+k+'_'+i+'_'+j);
if (!e)
continue;
if (s)
{
if (cut)
{
cuttedcards.push(e.innerHTML);
cuttedids.push(idlist[coord]);
}
shift++;
}
else if (shift > 0)
{
var to = to_coord_id(coord-shift);
document.getElementById('cardtd_'+to).innerHTML = e.innerHTML;
idlist[coord-shift] = idlist[coord];
}
else if (coord + shift < n)
continue;
// во всех трёх случаях - если выделена для
// удаления, если перемещена в другую, или
// если находится в конце - очищаем
e.innerHTML = emptycell;
idlist[coord] = '';
}
}
}
if (cut && cuttedids.length)
document.getElementById('cut_status').innerHTML = 'Вырезано '+cuttedids.length+' карточек.';
deselectAll();
document.getElementById('idlist_value').value = idlist.join(',');
}
// Перейти в режим выбора места вставки вырезанных карточек
function pasteCards()
{
if (!pasteMode)
{
if (!cuttedids.length)
if (!pasteMode)
{
alert('Сначала выделите и вырежьте какие-нибудь карточки!');
return;
if (!cuttedids.length)
{
alert('Сначала выделите и вырежьте какие-нибудь карточки!');
return;
}
alert('Кликните на карточку, после которой нужно вставить вырезанное, либо на кнопку "В начало".');
deselectAll();
pasteMode = true;
document.getElementById('btn_paste_beg').style.display = '';
}
alert('Кликните на карточку, после которой нужно вставить вырезанное, либо на кнопку "В начало".');
deselectAll();
pasteMode = true;
document.getElementById('btn_paste_beg').style.display = '';
}
}
// Вставить вырезанные карточки в позицию coord
function doPasteCards(coord)
{
stopPaste();
var nx = cuttedids.length;
if (nx <= 0)
return;
if (!document.getElementById('cardtd_'+to_coord_id(coord)))
{
alert('Некуда вставлять');
return;
}
var n = nr * nc * np;
var from, to;
for (var i = n-nx-1; i >= coord; i--)
{
from = to_coord_id(i);
to = to_coord_id(i+nx);
if (document.getElementById('cardtd_'+from) &&
document.getElementById('cardtd_'+to))
stopPaste();
var nx = cuttedids.length;
if (nx <= 0)
return;
if (!document.getElementById('cardtd_'+to_coord_id(coord)))
{
document.getElementById('cardtd_'+to).innerHTML =
document.getElementById('cardtd_'+from).innerHTML;
idlist[i+nx] = idlist[i];
alert('Некуда вставлять');
return;
}
}
for (var i = 0; i < nx; i++)
{
to = to_coord_id(i+coord);
document.getElementById('cardtd_'+to).innerHTML = cuttedcards[i];
document.getElementById('cardtd_'+to).className = 'cardtd selected';
idlist[i+coord] = cuttedids[i];
selectedcards[to] = true;
}
cuttedids = [];
cuttedcards = [];
document.getElementById('cut_status').innerHTML = '';
document.getElementById('idlist_value').value = idlist.join(',');
var n = nr * nc * np;
var from, to;
for (var i = n-nx-1; i >= coord; i--)
{
from = to_coord_id(i);
to = to_coord_id(i+nx);
if (document.getElementById('cardtd_'+from) &&
document.getElementById('cardtd_'+to))
{
document.getElementById('cardtd_'+to).innerHTML =
document.getElementById('cardtd_'+from).innerHTML;
idlist[i+nx] = idlist[i];
}
}
for (var i = 0; i < nx; i++)
{
to = to_coord_id(i+coord);
document.getElementById('cardtd_'+to).innerHTML = cuttedcards[i];
document.getElementById('cardtd_'+to).className = 'cardtd selected';
idlist[i+coord] = cuttedids[i];
selectedcards[to] = true;
}
cuttedids = [];
cuttedcards = [];
document.getElementById('cut_status').innerHTML = '';
document.getElementById('idlist_value').value = idlist.join(',');
}
// Выйти из режима вставки
function stopPaste()
{
if (highlitCard)
highlitCard.className = 'cardtd';
document.getElementById('btn_paste_beg').style.display = 'none';
pasteMode = false;
if (highlitCard)
highlitCard.className = 'cardtd';
document.getElementById('btn_paste_beg').style.display = 'none';
pasteMode = false;
}
// Обработчик keydown/keyup, записывает состояние ctrl
function ctrlDown(ev)
{
if (ev.keyCode == 17)
{
ctrl = ev.type == 'keydown';
return true;
}
return false;
if (ev.keyCode == 17)
{
ctrl = ev.type == 'keydown';
return true;
}
return false;
}
// Попробовать найти по иерархии карточку (id=cardtd_*)
function searchCardTarget(e)
{
var nt = e._target, i;
while (nt && (!nt.attributes ||
!(i = nt.attributes.getNamedItem('id')) ||
i.value.substr(0, 7) != 'cardtd_'))
nt = nt.parentNode;
return nt;
var nt = e._target, i;
while (nt && (!nt.attributes ||
!(i = nt.attributes.getNamedItem('id')) ||
i.value.substr(0, 7) != 'cardtd_'))
nt = nt.parentNode;
return nt;
}
// Попробовать найти по иерархии кнопку (id=btn_*)
function searchButtonTarget(e)
{
var nt = e._target, i;
while (nt && (!nt.attributes ||
!(i = nt.attributes.getNamedItem('id')) ||
i.value.substr(0, 4) != 'btn_'))
nt = nt.parentNode;
return nt;
var nt = e._target, i;
while (nt && (!nt.attributes ||
!(i = nt.attributes.getNamedItem('id')) ||
i.value.substr(0, 4) != 'btn_'))
nt = nt.parentNode;
return nt;
}
// Попробовать найти по иерархии что-нибудь кроме карточек и кнопок,
// по сути это только <input> и <textarea>, клик по чему не сбрасывает всё нахрен
function searchNonResetTarget(e)
{
var nt = e._target, i;
while (nt && (!(i = nt.nodeName.toLowerCase()) ||
!(i == 'input' || i == 'textarea')))
nt = nt.parentNode;
return nt;
var nt = e._target, i;
while (nt && (!(i = nt.nodeName.toLowerCase()) ||
!(i == 'input' || i == 'textarea')))
nt = nt.parentNode;
return nt;
}
// Глобальный обработчик события mouseup
function mouseUpHandler(e)
{
e = DragMaster.fixEvent(e);
var t;
if (searchNonResetTarget(e)) {}
else if (t = searchCardTarget(e))
selectCard(e, t);
else if (t = searchButtonTarget(e))
buttonHandler(e, t);
else
resetAll();
return true;
e = DragMaster.fixEvent(e);
var t;
if (searchNonResetTarget(e)) {}
else if (t = searchCardTarget(e))
selectCard(e, t);
else if (t = searchButtonTarget(e))
buttonHandler(e, t);
else
resetAll();
return true;
}
// Класс "Перетаскиваемая карточка", унаследованный от "Перетаскиваемого объекта"
// Логика - при начале перетаскивания удаляется из родительского элемента,
@ -350,97 +350,97 @@ function mouseUpHandler(e)
// обработчики вырезания и вставки карточек.
var CardDragObject = function(e)
{
DragObject.call(this, e);
this.n = id_to_coord(e.id);
DragObject.call(this, e);
this.n = id_to_coord(e.id);
};
CardDragObject.prototype = new DragObject();
CardDragObject.prototype.onDragStart = function() {
this.tmp = document.createElement('td');
this.element.style.opacity = 0.5;
this.element.parentNode.insertBefore(this.tmp, this.element);
this.element.parentNode.parentNode.parentNode.appendChild(this.element);
this.tmp = document.createElement('td');
this.element.style.opacity = 0.5;
this.element.parentNode.insertBefore(this.tmp, this.element);
this.element.parentNode.parentNode.parentNode.appendChild(this.element);
};
CardDragObject.prototype.onDragSuccess = function(target, pos) {
this.tmp.parentNode.insertBefore(this.element, this.tmp);
this.tmp.parentNode.removeChild(this.tmp);
if (!selectedcards[this.element.id.substr(7)])
{
deselectAll();
selectedcards[this.element.id.substr(7)] = true;
}
var to = id_to_coord(target.element.id)+1;
var w = target.element.scrollWidth;
if (pos.x < w/2)
to--;
var decr = 0;
for (var i = 0; i < to; i++)
if (selectedcards[to_coord_id(i)])
decr++;
to -= decr;
deleteSelectedCards(true);
doPasteCards(to);
this.tmp.parentNode.insertBefore(this.element, this.tmp);
this.tmp.parentNode.removeChild(this.tmp);
if (!selectedcards[this.element.id.substr(7)])
{
deselectAll();
selectedcards[this.element.id.substr(7)] = true;
}
var to = id_to_coord(target.element.id)+1;
var w = target.element.scrollWidth;
if (pos.x < w/2)
to--;
var decr = 0;
for (var i = 0; i < to; i++)
if (selectedcards[to_coord_id(i)])
decr++;
to -= decr;
deleteSelectedCards(true);
doPasteCards(to);
};
CardDragObject.prototype.onDragFail = function() {
this.tmp.parentNode.insertBefore(this.element, this.tmp);
this.tmp.parentNode.removeChild(this.tmp);
this.tmp.parentNode.insertBefore(this.element, this.tmp);
this.tmp.parentNode.removeChild(this.tmp);
};
// Каждая карточка также является целью перетаскивания
// Тут вся логика - подсветить левый/правый край в зависимости
// от положения мышки
var CardDropTarget = function(e)
{
DropTarget.call(this, e);
this.n = id_to_coord(e.id);
DropTarget.call(this, e);
this.n = id_to_coord(e.id);
};
CardDropTarget.prototype = new DropTarget();
CardDropTarget.prototype.onLeave = function()
{
this.element.style.border = '1px dashed black';
this.element.style.border = '1px dashed black';
};
CardDropTarget.prototype.onMove = function(pos)
{
var w = this.element.scrollWidth;
this.element.style.border = '1px dashed black';
if (pos.x < w/2)
this.element.style.borderLeft = '5px solid red';
else
this.element.style.borderRight = '5px solid red';
var w = this.element.scrollWidth;
this.element.style.border = '1px dashed black';
if (pos.x < w/2)
this.element.style.borderLeft = '5px solid red';
else
this.element.style.borderRight = '5px solid red';
};
// 2 если hash пуст
// 1 если в нём один ключ key
// 0 если в нём есть ключ, не равный key
function isEmptyHash(hash, key)
{
var empty = 2;
for (var i in hash)
{
if (key !== undefined && i == key)
empty = 1;
else
var empty = 2;
for (var i in hash)
{
empty = 0;
break;
if (key !== undefined && i == key)
empty = 1;
else
{
empty = 0;
break;
}
}
}
return empty;
return empty;
}
// Установка обработчиков событий:
for (var k = 0; k < np; k++)
{
for (var i = 0; i < nr; i++)
{
for (var j = 0; j < nc; j++)
for (var i = 0; i < nr; i++)
{
var e = document.getElementById('cardtd_'+k+'_'+i+'_'+j);
if (e)
{
addListener(e, 'mouseover', highlightCard);
addListener(e, 'mouseout', unlightCard);
new CardDragObject(e);
new CardDropTarget(e);
}
for (var j = 0; j < nc; j++)
{
var e = document.getElementById('cardtd_'+k+'_'+i+'_'+j);
if (e)
{
addListener(e, 'mouseover', highlightCard);
addListener(e, 'mouseout', unlightCard);
new CardDragObject(e);
new CardDropTarget(e);
}
}
}
}
}
addListener(document, "mousedown", guessButton);
addListener(document, "mouseup", mouseUpHandler);

View File

@ -190,7 +190,8 @@ function ctrlEnter(event, formElem)
return true;
}
if (typeof Node == 'undefined') {
if (typeof Node == 'undefined')
{
/* MSIE doesn't define Node, so provide a compatibility object */
window.Node = {
TEXT_NODE: 3,