/* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ var svgns = "http://www.w3.org/2000/svg"; var xlinkns = "http://www.w3.org/1999/xlink"; function Pile(board, x, y, w, h, dx, dy, pdx, pdy) { this.board = board; this.doc = board.doc; this.index = board.thePiles.length; board.thePiles.push(this); this.g = this.doc.createElementNS(svgns, "g"); this.g.setAttribute("id", "pile-"+this.index); this.g.addEventListener("mousedown", new PileMouseDownHandler(this), false); this.g.addEventListener("click", new PileClickHandler(this), false); this.base = this.doc.createElementNS(svgns, "rect"); this.base.setAttribute("x", ""+x); this.base.setAttribute("y", ""+y); this.base.setAttribute("width", ""+w); this.base.setAttribute("height", ""+h); this.base.setAttribute("style", "visibility:hidden; pointer-events:fill"); this.g.appendChild(this.base); board.boardGroup.appendChild(this.g); this.x = x; this.y = y; this.width = w; this.height = h; this.dx = dx; this.dy = dy; this.pdx = pdx; this.pdy = pdy; this.cards = new Array(); var me = this; } Pile.prototype.addCard = function(card) { if (card.pile) { card.pile.removeCard(card); } var len = this.cards.length; if ((this.pdx != 0) || (this.pdy !=0)) { for (var i=0; i=0; i--) { var c = this.cards[i]; if (c == card) { this.cards.splice(i, 1); len = this.cards.length; for (var j=i; j 9) { this.clickX = evt.clientX; this.clickY = evt.clientY; this.clickCnt = 1; if (this.pile.click) this.pile.click(this.pile, evt); return; } this.clickX = evt.clientX; this.clickY = evt.clientY; this.clickCnt++; if (this.clickCnt > 2) { this.clickCnt = 1; if (this.pile.click) this.pile.click(this.pile, evt); return; } if (this.pile.doubleClick) { this.pile.doubleClick(this.pile, evt); } }; function PileMouseDownHandler(pile) { this.pile = pile; } PileMouseDownHandler.prototype.handleEvent = function(evt) { if (!this.pile.dragCheck) return; var tgt = evt.target; var e = tgt; var p = e.parentNode; while (p && (p != this.pile.g)) { e = p; p = e.parentNode; } if (!p) return; var c, i; var num = this.pile.cards.length; for (i=num-1; i>=0; i--) { c = this.pile.cards[i]; if (e == c.elem) break; c = null; } if (!c) return; var g = this.pile.dragCheck(this.pile, c, i); if (!g) return; var cards = this.pile.cards.splice(i, num-i); new CardMoveManager(g, this.pile, cards, evt.clientX, evt.clientY); } /** * Finds the pile associated with elem, if any. * returns null if elem is not associated with a pile. * otherwise it returns the associated Pile object. */ function findPile(board, elem) { var root = document.getRootElement(); var tgt = elem var destPile = null; while (tgt != root) { var id; try { id = tgt.getAttribute("id"); } catch (x) { break; } if (id && id.substring(0, 5) == "pile-") { var idx = parseFloat(id.substring(5)); destPile = board.thePiles[idx]; break; } tgt = tgt.parentNode; } return destPile; } function CardMoveManager(group, pile, cards, x, y) { this.pile = pile; this.board = pile.board; this.cards = cards; this.group = group; this.parent = group.parentNode; this.root = this.group.getOwnerDocument().getRootElement(); this.startPt = localPt(this.parent, x, y); this.fmm = new ForwardMouseMove(this); this.fmu = new ForwardMouseUp(this); this.root.addEventListener("mousemove", this.fmm, false); this.root.addEventListener("mouseup", this.fmu, false); this.moved = false; }; CardMoveManager.prototype.mousemove = function(evt) { var pt = localPt(this.parent, evt.clientX, evt.clientY); var dx = pt.x-this.startPt.x; var dy = pt.y-this.startPt.y; if (!this.moved && ((dx*dx+dy*dy) < 4)) return; if (!this.moved) { this.moved = true; // Now move cards for (var i=0; i