├── .dockerignore ├── .gitignore ├── Dockerfile ├── README.md ├── lib ├── Game.js └── GameStore.js ├── package-lock.json ├── package.json ├── public ├── css │ ├── bootstrap.min.css │ └── styles.css ├── img │ ├── board-corners.png │ ├── board-edges.png │ └── favicon.ico └── js │ ├── bootstrap.min.js │ ├── client.js │ ├── fastclick.js │ └── jquery.min.js ├── routes ├── http.js └── socket.js ├── server.js └── views ├── game.jade ├── home.jade └── layout.jade /.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:4 2 | 3 | USER node 4 | 5 | RUN mkdir /home/node/app 6 | 7 | WORKDIR /home/node/app 8 | 9 | COPY package.json package-lock.json ./ 10 | 11 | RUN npm install 12 | 13 | COPY . . 14 | 15 | EXPOSE 3000 16 | 17 | CMD [ "npm", "start" ] 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project has been abandoned. See [issue #15](https://github.com/thebinarypenguin/socket.io-chess/issues/15). 2 | 3 | # Description 4 | 5 | A real-time multi-player chess app using [node](https://github.com/joyent/node), [express](https://github.com/visionmedia/express), and of course [socket.io](https://github.com/LearnBoost/socket.io). 6 | 7 | A demo can currently be found at [chess.thebinarypenguin.com](http://chess.thebinarypenguin.com). 8 | 9 | # Other Projects 10 | 11 | This project is just a little something I threw together for personal education and isn't particularly polished. However the following projects are and should be checked out 12 | 13 | * [Chess.js](https://github.com/jhlywa/chess.js) A javascript chess engine 14 | * [Chess Hub](http://chesshub-benas.rhcloud.com/) A chess webapp based on [benas](https://github.com/benas)'s [gamehub.io](https://github.com/benas/gamehub.io) project 15 | 16 | # Getting Started 17 | 18 | 1. Download 19 | ``` 20 | git clone https://github.com/thebinarypenguin/socket.io-chess.git 21 | ``` 22 | 23 | 2. Install 24 | ``` 25 | cd socket.io-chess 26 | npm install 27 | ``` 28 | 29 | 3. Run 30 | ``` 31 | node server.js 32 | ``` 33 | 34 | # License 35 | 36 | Licensed under the [MIT License](http://www.opensource.org/licenses/MIT) 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /lib/Game.js: -------------------------------------------------------------------------------- 1 | var _ = require('underscore'); 2 | 3 | /* 4 | * The Game object 5 | */ 6 | 7 | /** 8 | * Create new game and initialize 9 | */ 10 | function Game(params) { 11 | 12 | // pending/ongoing/checkmate/stalemate/forfeit 13 | this.status = 'pending'; 14 | 15 | this.activePlayer = null; 16 | 17 | this.players = [ 18 | {color: null, name: null, joined: false, inCheck: false, forfeited: false}, 19 | {color: null, name: null, joined: false, inCheck: false, forfeited: false} 20 | ]; 21 | 22 | this.board = { 23 | a8: 'bR_', b8: 'bN_', c8: 'bB_', d8: 'bQ_', e8: 'bK_', f8: 'bB_', g8: 'bN_', h8: 'bR_', 24 | a7: 'bP_', b7: 'bP_', c7: 'bP_', d7: 'bP_', e7: 'bP_', f7: 'bP_', g7: 'bP_', h7: 'bP_', 25 | a6: null, b6: null, c6: null, d6: null, e6: null, f6: null, g6: null, h6: null, 26 | a5: null, b5: null, c5: null, d5: null, e5: null, f5: null, g5: null, h5: null, 27 | a4: null, b4: null, c4: null, d4: null, e4: null, f4: null, g4: null, h4: null, 28 | a3: null, b3: null, c3: null, d3: null, e3: null, f3: null, g3: null, h3: null, 29 | a2: 'wP_', b2: 'wP_', c2: 'wP_', d2: 'wP_', e2: 'wP_', f2: 'wP_', g2: 'wP_', h2: 'wP_', 30 | a1: 'wR_', b1: 'wN_', c1: 'wB_', d1: 'wQ_', e1: 'wK_', f1: 'wB_', g1: 'wN_', h1: 'wR_' 31 | }; 32 | 33 | this.capturedPieces = []; 34 | 35 | this.validMoves = [ 36 | { type: 'move', pieceCode: 'wP', startSquare: 'a2', endSquare: 'a3' }, 37 | { type: 'move', pieceCode: 'wP', startSquare: 'a2', endSquare: 'a4' }, 38 | { type: 'move', pieceCode: 'wP', startSquare: 'b2', endSquare: 'b3' }, 39 | { type: 'move', pieceCode: 'wP', startSquare: 'b2', endSquare: 'b4' }, 40 | { type: 'move', pieceCode: 'wP', startSquare: 'c2', endSquare: 'c3' }, 41 | { type: 'move', pieceCode: 'wP', startSquare: 'c2', endSquare: 'c4' }, 42 | { type: 'move', pieceCode: 'wP', startSquare: 'd2', endSquare: 'd3' }, 43 | { type: 'move', pieceCode: 'wP', startSquare: 'd2', endSquare: 'd4' }, 44 | { type: 'move', pieceCode: 'wP', startSquare: 'e2', endSquare: 'e3' }, 45 | { type: 'move', pieceCode: 'wP', startSquare: 'e2', endSquare: 'e4' }, 46 | { type: 'move', pieceCode: 'wP', startSquare: 'f2', endSquare: 'f3' }, 47 | { type: 'move', pieceCode: 'wP', startSquare: 'f2', endSquare: 'f4' }, 48 | { type: 'move', pieceCode: 'wP', startSquare: 'g2', endSquare: 'g3' }, 49 | { type: 'move', pieceCode: 'wP', startSquare: 'g2', endSquare: 'g4' }, 50 | { type: 'move', pieceCode: 'wP', startSquare: 'h2', endSquare: 'h3' }, 51 | { type: 'move', pieceCode: 'wP', startSquare: 'h2', endSquare: 'h4' }, 52 | { type: 'move', pieceCode: 'wN', startSquare: 'b1', endSquare: 'a3' }, 53 | { type: 'move', pieceCode: 'wN', startSquare: 'b1', endSquare: 'c3' }, 54 | { type: 'move', pieceCode: 'wN', startSquare: 'g1', endSquare: 'f3' }, 55 | { type: 'move', pieceCode: 'wN', startSquare: 'g1', endSquare: 'h3' } 56 | ]; 57 | 58 | this.lastMove = null; 59 | 60 | this.modifiedOn = Date.now(); 61 | 62 | // Set player colors 63 | // params.playerColor is the color of the player who created the game 64 | if (params.playerColor === 'white') { 65 | this.players[0].color = 'white'; 66 | this.players[1].color = 'black'; 67 | } 68 | else if (params.playerColor === 'black') { 69 | this.players[0].color = 'black'; 70 | this.players[1].color = 'white'; 71 | } 72 | } 73 | 74 | /** 75 | * Add player to game, and after both players have joined activate the game. 76 | * Returns true on success and false on failure. 77 | */ 78 | Game.prototype.addPlayer = function(playerData) { 79 | 80 | // Check for an open spot 81 | var p = _.findWhere(this.players, {color: playerData.playerColor, joined: false}); 82 | if (!p) { return false; } 83 | 84 | // Set player info 85 | p.name = playerData.playerName; 86 | p.joined = true; 87 | 88 | // If both players have joined, start the game 89 | if (this.players[0].joined && this.players[1].joined && this.status === 'pending') { 90 | this.activePlayer = _.findWhere(this.players, {color: 'white'}); 91 | this.status = 'ongoing'; 92 | } 93 | 94 | this.modifiedOn = Date.now(); 95 | 96 | return true; 97 | }; 98 | 99 | /** 100 | * Remove player from game, this does not end the game, players may come and go as they please. 101 | * Returns true on success and false on failure. 102 | */ 103 | Game.prototype.removePlayer = function(playerData) { 104 | 105 | // Find player in question 106 | var p = _.findWhere(this.players, {color: playerData.playerColor}); 107 | if (!p) { return false; } 108 | 109 | // Set player info 110 | p.joined = false; 111 | 112 | this.modifiedOn = Date.now(); 113 | 114 | return true; 115 | }; 116 | 117 | /** 118 | * Apply move and regenerate game state. 119 | * Returns true on success and false on failure. 120 | */ 121 | Game.prototype.move = function(moveString) { 122 | 123 | // Test if move is valid 124 | var validMove = _.findWhere(this.validMoves, parseMoveString(moveString)); 125 | if (!validMove) { return false; } 126 | 127 | // Check for a pawn promotion suffix 128 | var whitePawnPromotion = new RegExp('(w)P..[-x].8p([RNBQ])'); 129 | var blackPawnPromotion = new RegExp('(b)P..[-x].1p([RNBQ])'); 130 | var promotionMatches, promotionPiece = null; 131 | 132 | if (whitePawnPromotion.test(moveString)) { 133 | promotionMatches = whitePawnPromotion.exec(moveString); 134 | promotionPiece = promotionMatches[1]+promotionMatches[2]; 135 | } 136 | 137 | if (blackPawnPromotion.test(moveString)) { 138 | promotionMatches = blackPawnPromotion.exec(moveString); 139 | promotionPiece = promotionMatches[1]+promotionMatches[2]; 140 | } 141 | 142 | // Apply move 143 | switch (validMove.type) { 144 | case 'move' : 145 | this.board[validMove.endSquare] = promotionPiece || validMove.pieceCode; 146 | this.board[validMove.startSquare] = null; 147 | break; 148 | 149 | case 'capture' : 150 | this.capturedPieces.push(this.board[validMove.captureSquare]); 151 | this.board[validMove.captureSquare] = null; 152 | 153 | this.board[validMove.endSquare] = promotionPiece || validMove.pieceCode; 154 | this.board[validMove.startSquare] = null; 155 | break; 156 | 157 | case 'castle' : 158 | if (validMove.pieceCode === 'wK' && validMove.boardSide === 'queen') { 159 | this.board.c1 = validMove.pieceCode 160 | this.board.e1 = null; 161 | 162 | this.board.d1 = 'wR' 163 | this.board.a1 = null; 164 | } 165 | if (validMove.pieceCode === 'wK' && validMove.boardSide === 'king') { 166 | this.board.g1 = validMove.pieceCode 167 | this.board.e1 = null; 168 | 169 | this.board.f1 = 'wR' 170 | this.board.h1 = null; 171 | } 172 | if (validMove.pieceCode === 'bK' && validMove.boardSide === 'queen') { 173 | this.board.c8 = validMove.pieceCode 174 | this.board.e8 = null; 175 | 176 | this.board.d8 = 'bR' 177 | this.board.a8 = null; 178 | } 179 | if (validMove.pieceCode === 'bK' && validMove.boardSide === 'king') { 180 | this.board.g8 = validMove.pieceCode 181 | this.board.e8 = null; 182 | 183 | this.board.f8 = 'bR' 184 | this.board.h8 = null; 185 | } 186 | break; 187 | 188 | default : break; 189 | }; 190 | 191 | // Set this move as last move 192 | this.lastMove = validMove; 193 | 194 | // Get inactive player 195 | var inactivePlayer = _.find(this.players, function(p) { 196 | return (p === this.activePlayer) ? false : true; 197 | }, this); 198 | 199 | // Regenerate valid moves 200 | this.validMoves = getMovesForPlayer(inactivePlayer.color, this.board, this.lastMove); 201 | 202 | // Set check status for both players 203 | _.each(this.players, function(p) { 204 | p.inCheck = isPlayerInCheck(p.color, this.board); 205 | }, this); 206 | 207 | // Test for checkmate or stalemate 208 | if (this.validMoves.length === 0) { 209 | this.status = (inactivePlayer.inCheck) ? 'checkmate' : 'stalemate' ; 210 | } 211 | 212 | // Toggle active player 213 | if (this.status === 'ongoing') { this.activePlayer = inactivePlayer; } 214 | 215 | this.modifiedOn = Date.now(); 216 | 217 | return true; 218 | }; 219 | 220 | /** 221 | * Apply a player's forfeit to the game. 222 | * Returns true on success and false on failure. 223 | */ 224 | Game.prototype.forfeit = function(playerData) { 225 | 226 | // Find player in question 227 | var p = _.findWhere(this.players, {color: playerData.playerColor}); 228 | if (!p) { return false; } 229 | 230 | // Set player info 231 | p.forfeited = true; 232 | 233 | // Set game status 234 | this.status = 'forfeit'; 235 | 236 | this.modifiedOn = Date.now(); 237 | 238 | return true; 239 | }; 240 | 241 | /* 242 | * Private Utility Functions 243 | */ 244 | 245 | /** 246 | * Get all the valid/safe moves a player can make. 247 | * Returns an array of move objects on success or an empty array on failure. 248 | */ 249 | var getMovesForPlayer = function(playerColor, board, lastMove) { 250 | var moves = []; 251 | var piece, square = null; 252 | 253 | // Loop board 254 | for (square in board) { 255 | piece = board[square]; 256 | 257 | // Skip empty squares and opponent's pieces 258 | if (piece === null) { continue; } 259 | if (piece[0] !== playerColor[0]) { continue; } 260 | 261 | // Collect all moves for all of player's pieces 262 | switch (piece[1]) { 263 | case 'P': moves.push.apply(moves, getMovesForPawn(piece, square, board, lastMove)); break; 264 | case 'R': moves.push.apply(moves, getMovesForRook(piece, square, board)); break; 265 | case 'N': moves.push.apply(moves, getMovesForKnight(piece, square, board)); break; 266 | case 'B': moves.push.apply(moves, getMovesForBishop(piece, square, board)); break; 267 | case 'Q': moves.push.apply(moves, getMovesForQueen(piece, square, board)); break; 268 | case 'K': moves.push.apply(moves, getMovesForKing(piece, square, board)); break; 269 | } 270 | } 271 | 272 | return moves; 273 | }; 274 | 275 | /** 276 | * Get all the moves a pawn can make. 277 | * If includeUnsafe is true then moves that put the player's own king in check will be included. 278 | * Returns an array of move objects on success or an empty array on failure. 279 | */ 280 | var getMovesForPawn = function(piece, square, board, lastMove, includeUnsafe) { 281 | var moves = []; 282 | 283 | var moveTransforms, captureTransforms = []; 284 | 285 | if (piece[0] === 'w') { 286 | moveTransforms = (piece[2] === '_') ? [{x:+0, y:+1}, {x:+0, y:+2}] : [{x:+0, y:+1}]; 287 | captureTransforms = [{x:+1, y:+1}, {x:-1, y:+1}]; 288 | } 289 | 290 | if (piece[0] === 'b') { 291 | moveTransforms = (piece[2] === '_') ? [{x:+0, y:-1}, {x:+0, y:-2}] : [{x:+0, y:-1}]; 292 | captureTransforms = [{x:+1, y:-1}, {x:-1, y:-1}]; 293 | } 294 | 295 | var destination, move, capture = null; 296 | 297 | // Loop moves 298 | for (var i=0; i 8) { return false; } 918 | if (destRank < 1 || destRank > 8) { return false; } 919 | 920 | // Return new square 921 | return num2alpha(destFile) + destRank; 922 | }; 923 | 924 | /** 925 | * Parse a move string and convert it to an object. 926 | * Returns the move object on success or null on failure. 927 | */ 928 | var parseMoveString = function(moveString) { 929 | 930 | // Castles 931 | if (moveString === 'wK0-0') { return {type: 'castle', pieceCode: 'wK', boardSide: 'king'}; } 932 | if (moveString === 'bK0-0') { return {type: 'castle', pieceCode: 'bK', boardSide: 'king'}; } 933 | if (moveString === 'wK0-0-0') { return {type: 'castle', pieceCode: 'wK', boardSide: 'queen'}; } 934 | if (moveString === 'bK0-0-0') { return {type: 'castle', pieceCode: 'bK', boardSide: 'queen'}; } 935 | 936 | // En Passant Captures 937 | if (moveString[1] === 'P' && moveString[4] === 'x' && moveString.slice(-2) === 'ep') { 938 | return { 939 | type : 'capture', 940 | pieceCode : moveString.substring(0, 2), 941 | startSquare : moveString.substring(2, 4), 942 | endSquare : moveString.substring(5, 7), 943 | captureSquare : moveString[5] + moveString[3] 944 | } 945 | } 946 | 947 | // Moves 948 | if (moveString[4] === '-') { 949 | return { 950 | type : 'move', 951 | pieceCode : moveString.substring(0, 2), 952 | startSquare : moveString.substring(2, 4), 953 | endSquare : moveString.substring(5, 7) 954 | } 955 | } 956 | // Captures 957 | else if (moveString[4] === 'x') { 958 | return { 959 | type : 'capture', 960 | pieceCode : moveString.substring(0, 2), 961 | startSquare : moveString.substring(2, 4), 962 | endSquare : moveString.substring(5, 7), 963 | captureSquare : moveString.substring(5, 7) 964 | } 965 | } else { 966 | return null; 967 | } 968 | }; 969 | 970 | // Export the game object 971 | module.exports = Game; -------------------------------------------------------------------------------- /lib/GameStore.js: -------------------------------------------------------------------------------- 1 | var Game = require('./Game'); 2 | 3 | function GameStore() { 4 | this.games = {}; 5 | 6 | // Periodically check for inactive games, and delete them 7 | setInterval(function(games) { 8 | for (key in games) { 9 | if (Date.now() - games[key].modifiedOn > (12 * 60 * 60 * 1000)) { 10 | console.log("Deleting game " + key + ". No activity for atleast 12 hours."); 11 | delete games[key]; 12 | } 13 | } 14 | }, (1 * 60 * 60 * 1000), this.games); 15 | }; 16 | 17 | GameStore.prototype.add = function(gameParams) { 18 | var key = ''; 19 | var keyLength = 7; 20 | var chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; 21 | 22 | // Generate a key until we get a unique one 23 | do { 24 | for (var i=0; ithis.$items.length-1||0>b?void 0:this.sliding?this.$element.one("slid",function(){c.to(b)}):d==b?this.pause().cycle():this.slide(b>d?"next":"prev",a(this.$items[b]))},b.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition.end&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},b.prototype.next=function(){return this.sliding?void 0:this.slide("next")},b.prototype.prev=function(){return this.sliding?void 0:this.slide("prev")},b.prototype.slide=function(b,c){var d=this.$element.find(".item.active"),e=c||d[b](),f=this.interval,g="next"==b?"left":"right",h="next"==b?"first":"last",i=this;if(!e.length){if(!this.options.wrap)return;e=this.$element.find(".item")[h]()}this.sliding=!0,f&&this.pause();var j=a.Event("slide.bs.carousel",{relatedTarget:e[0],direction:g});if(!e.hasClass("active")){if(this.$indicators.length&&(this.$indicators.find(".active").removeClass("active"),this.$element.one("slid",function(){var b=a(i.$indicators.children()[i.getActiveIndex()]);b&&b.addClass("active")})),a.support.transition&&this.$element.hasClass("slide")){if(this.$element.trigger(j),j.isDefaultPrevented())return;e.addClass(b),e[0].offsetWidth,d.addClass(g),e.addClass(g),d.one(a.support.transition.end,function(){e.removeClass([b,g].join(" ")).addClass("active"),d.removeClass(["active",g].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger("slid")},0)}).emulateTransitionEnd(600)}else{if(this.$element.trigger(j),j.isDefaultPrevented())return;d.removeClass("active"),e.addClass("active"),this.sliding=!1,this.$element.trigger("slid")}return f&&this.cycle(),this}};var c=a.fn.carousel;a.fn.carousel=function(c){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c),g="string"==typeof c?c:f.slide;e||d.data("bs.carousel",e=new b(this,f)),"number"==typeof c?e.to(c):g?e[g]():f.interval&&e.pause().cycle()})},a.fn.carousel.Constructor=b,a.fn.carousel.noConflict=function(){return a.fn.carousel=c,this},a(document).on("click.bs.carousel.data-api","[data-slide], [data-slide-to]",function(b){var c,d=a(this),e=a(d.attr("data-target")||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"")),f=a.extend({},e.data(),d.data()),g=d.attr("data-slide-to");g&&(f.interval=!1),e.carousel(f),(g=d.attr("data-slide-to"))&&e.data("bs.carousel").to(g),b.preventDefault()}),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var b=a(this);b.carousel(b.data())})})}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d),this.transitioning=null,this.options.parent&&(this.$parent=a(this.options.parent)),this.options.toggle&&this.toggle()};b.DEFAULTS={toggle:!0},b.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},b.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b=a.Event("show.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.$parent&&this.$parent.find("> .panel > .in");if(c&&c.length){var d=c.data("bs.collapse");if(d&&d.transitioning)return;c.collapse("hide"),d||c.data("bs.collapse",null)}var e=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[e](0),this.transitioning=1;var f=function(){this.$element.removeClass("collapsing").addClass("in")[e]("auto"),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return f.call(this);var g=a.camelCase(["scroll",e].join("-"));this.$element.one(a.support.transition.end,a.proxy(f,this)).emulateTransitionEnd(350)[e](this.$element[0][g])}}},b.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse").removeClass("in"),this.transitioning=1;var d=function(){this.transitioning=0,this.$element.trigger("hidden.bs.collapse").removeClass("collapsing").addClass("collapse")};return a.support.transition?(this.$element[c](0).one(a.support.transition.end,a.proxy(d,this)).emulateTransitionEnd(350),void 0):d.call(this)}}},b.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()};var c=a.fn.collapse;a.fn.collapse=function(c){return this.each(function(){var d=a(this),e=d.data("bs.collapse"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c);e||d.data("bs.collapse",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.collapse.Constructor=b,a.fn.collapse.noConflict=function(){return a.fn.collapse=c,this},a(document).on("click.bs.collapse.data-api","[data-toggle=collapse]",function(b){var c,d=a(this),e=d.attr("data-target")||b.preventDefault()||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,""),f=a(e),g=f.data("bs.collapse"),h=g?"toggle":d.data(),i=d.attr("data-parent"),j=i&&a(i);g&&g.transitioning||(j&&j.find('[data-toggle=collapse][data-parent="'+i+'"]').not(d).addClass("collapsed"),d[f.hasClass("in")?"addClass":"removeClass"]("collapsed")),f.collapse(h)})}(window.jQuery),+function(a){"use strict";function b(){a(d).remove(),a(e).each(function(b){var d=c(a(this));d.hasClass("open")&&(d.trigger(b=a.Event("hide.bs.dropdown")),b.isDefaultPrevented()||d.removeClass("open").trigger("hidden.bs.dropdown"))})}function c(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}var d=".dropdown-backdrop",e="[data-toggle=dropdown]",f=function(b){a(b).on("click.bs.dropdown",this.toggle)};f.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=c(e),g=f.hasClass("open");if(b(),!g){if("ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(''}),b.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),b.prototype.constructor=b,b.prototype.getDefaults=function(){return b.DEFAULTS},b.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content")[this.options.html?"html":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},b.prototype.hasContent=function(){return this.getTitle()||this.getContent()},b.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},b.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")},b.prototype.tip=function(){return this.$tip||(this.$tip=a(this.options.template)),this.$tip};var c=a.fn.popover;a.fn.popover=function(c){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof c&&c;e||d.data("bs.popover",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.popover.Constructor=b,a.fn.popover.noConflict=function(){return a.fn.popover=c,this}}(window.jQuery),+function(a){"use strict";function b(c,d){var e,f=a.proxy(this.process,this);this.$element=a(c).is("body")?a(window):a(c),this.$body=a("body"),this.$scrollElement=this.$element.on("scroll.bs.scroll-spy.data-api",f),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||(e=a(c).attr("href"))&&e.replace(/.*(?=#[^\s]+$)/,"")||"")+" .nav li > a",this.offsets=a([]),this.targets=a([]),this.activeTarget=null,this.refresh(),this.process()}b.DEFAULTS={offset:10},b.prototype.refresh=function(){var b=this.$element[0]==window?"offset":"position";this.offsets=a([]),this.targets=a([]);var c=this;this.$body.find(this.selector).map(function(){var d=a(this),e=d.data("target")||d.attr("href"),f=/^#\w/.test(e)&&a(e);return f&&f.length&&[[f[b]().top+(!a.isWindow(c.$scrollElement.get(0))&&c.$scrollElement.scrollTop()),e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){c.offsets.push(this[0]),c.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.$scrollElement[0].scrollHeight||this.$body[0].scrollHeight,d=c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(b>=d)return g!=(a=f.last()[0])&&this.activate(a);for(a=e.length;a--;)g!=f[a]&&b>=e[a]&&(!e[a+1]||b<=e[a+1])&&this.activate(f[a])},b.prototype.activate=function(b){this.activeTarget=b,a(this.selector).parents(".active").removeClass("active");var c=this.selector+'[data-target="'+b+'"],'+this.selector+'[href="'+b+'"]',d=a(c).parents("li").addClass("active");d.parent(".dropdown-menu").length&&(d=d.closest("li.dropdown").addClass("active")),d.trigger("activate")};var c=a.fn.scrollspy;a.fn.scrollspy=function(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.scrollspy.Constructor=b,a.fn.scrollspy.noConflict=function(){return a.fn.scrollspy=c,this},a(window).on("load",function(){a('[data-spy="scroll"]').each(function(){var b=a(this);b.scrollspy(b.data())})})}(window.jQuery),+function(a){"use strict";var b=function(b){this.element=a(b)};b.prototype.show=function(){var b=this.element,c=b.closest("ul:not(.dropdown-menu)"),d=b.attr("data-target");if(d||(d=b.attr("href"),d=d&&d.replace(/.*(?=#[^\s]*$)/,"")),!b.parent("li").hasClass("active")){var e=c.find(".active:last a")[0],f=a.Event("show.bs.tab",{relatedTarget:e});if(b.trigger(f),!f.isDefaultPrevented()){var g=a(d);this.activate(b.parent("li"),c),this.activate(g,g.parent(),function(){b.trigger({type:"shown.bs.tab",relatedTarget:e})})}}},b.prototype.activate=function(b,c,d){function e(){f.removeClass("active").find("> .dropdown-menu > .active").removeClass("active"),b.addClass("active"),g?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu")&&b.closest("li.dropdown").addClass("active"),d&&d()}var f=c.find("> .active"),g=d&&a.support.transition&&f.hasClass("fade");g?f.one(a.support.transition.end,e).emulateTransitionEnd(150):e(),f.removeClass("in")};var c=a.fn.tab;a.fn.tab=function(c){return this.each(function(){var d=a(this),e=d.data("bs.tab");e||d.data("bs.tab",e=new b(this)),"string"==typeof c&&e[c]()})},a.fn.tab.Constructor=b,a.fn.tab.noConflict=function(){return a.fn.tab=c,this},a(document).on("click.bs.tab.data-api",'[data-toggle="tab"], [data-toggle="pill"]',function(b){b.preventDefault(),a(this).tab("show")})}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.options=a.extend({},b.DEFAULTS,d),this.$window=a(window).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(c),this.affixed=this.unpin=null,this.checkPosition()};b.RESET="affix affix-top affix-bottom",b.DEFAULTS={offset:0},b.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},b.prototype.checkPosition=function(){if(this.$element.is(":visible")){var c=a(document).height(),d=this.$window.scrollTop(),e=this.$element.offset(),f=this.options.offset,g=f.top,h=f.bottom;"object"!=typeof f&&(h=g=f),"function"==typeof g&&(g=f.top()),"function"==typeof h&&(h=f.bottom());var i=null!=this.unpin&&d+this.unpin<=e.top?!1:null!=h&&e.top+this.$element.height()>=c-h?"bottom":null!=g&&g>=d?"top":!1;this.affixed!==i&&(this.unpin&&this.$element.css("top",""),this.affixed=i,this.unpin="bottom"==i?e.top-d:null,this.$element.removeClass(b.RESET).addClass("affix"+(i?"-"+i:"")),"bottom"==i&&this.$element.offset({top:document.body.offsetHeight-h-this.$element.height()}))}};var c=a.fn.affix;a.fn.affix=function(c){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof c&&c;e||d.data("bs.affix",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.affix.Constructor=b,a.fn.affix.noConflict=function(){return a.fn.affix=c,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var b=a(this),c=b.data();c.offset=c.offset||{},c.offsetBottom&&(c.offset.bottom=c.offsetBottom),c.offsetTop&&(c.offset.top=c.offsetTop),b.affix(c)})})}(window.jQuery); -------------------------------------------------------------------------------- /public/js/client.js: -------------------------------------------------------------------------------- 1 | var Client = (function(window) { 2 | 3 | var socket = null; 4 | var gameState = null; 5 | 6 | var gameID = null; 7 | var playerColor = null; 8 | var playerName = null; 9 | 10 | var container = null; 11 | var messages = null; 12 | var board = null; 13 | var squares = null; 14 | 15 | var gameClasses = null; 16 | 17 | var selection = null; 18 | 19 | var gameOverMessage = null; 20 | var pawnPromotionPrompt = null; 21 | var forfeitPrompt = null; 22 | 23 | 24 | /** 25 | * Initialize the UI 26 | */ 27 | var init = function(config) { 28 | gameID = config.gameID; 29 | playerColor = config.playerColor; 30 | playerName = config.playerName; 31 | 32 | container = $('#game'); 33 | messages = $('#messages'); 34 | board = $('#board'); 35 | squares = board.find('.square'); 36 | 37 | gameOverMessage = $('#game-over'); 38 | pawnPromotionPrompt = $('#pawn-promotion'); 39 | forfeitPrompt = $('#forfeit-game'); 40 | 41 | gameClasses = "white black pawn rook knight bishop queen king not-moved empty selected " + 42 | "valid-move valid-capture valid-en-passant-capture valid-castle last-move"; 43 | 44 | // Create socket connection 45 | socket = io.connect(); 46 | 47 | // Define board based on player's perspective 48 | assignSquares(); 49 | 50 | // Attach event handlers 51 | attachDOMEventHandlers(); 52 | attachSocketEventHandlers(); 53 | 54 | // Initialize modal popup windows 55 | gameOverMessage.modal({show: false, keyboard: false, backdrop: 'static'}); 56 | pawnPromotionPrompt.modal({show: false, keyboard: false, backdrop: 'static'}); 57 | forfeitPrompt.modal({show: false, keyboard: false, backdrop: 'static'}); 58 | 59 | // Join game 60 | socket.emit('join', gameID); 61 | }; 62 | 63 | /** 64 | * Assign square IDs and labels based on player's perspective 65 | */ 66 | var assignSquares = function() { 67 | var fileLabels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']; 68 | var rankLabels = [8, 7, 6, 5, 4, 3, 2, 1]; 69 | var squareIDs = [ 70 | 'a8', 'b8', 'c8', 'd8', 'e8', 'f8', 'g8', 'h8', 71 | 'a7', 'b7', 'c7', 'd7', 'e7', 'f7', 'g7', 'h7', 72 | 'a6', 'b6', 'c6', 'd6', 'e6', 'f6', 'g6', 'h6', 73 | 'a5', 'b5', 'c5', 'd5', 'e5', 'f5', 'g5', 'h5', 74 | 'a4', 'b4', 'c4', 'd4', 'e4', 'f4', 'g4', 'h4', 75 | 'a3', 'b3', 'c3', 'd3', 'e3', 'f3', 'g3', 'h3', 76 | 'a2', 'b2', 'c2', 'd2', 'e2', 'f2', 'g2', 'h2', 77 | 'a1', 'b1', 'c1', 'd1', 'e1', 'f1', 'g1', 'h1' 78 | ]; 79 | 80 | if (playerColor === 'black') { 81 | fileLabels.reverse(); 82 | rankLabels.reverse(); 83 | squareIDs.reverse(); 84 | } 85 | 86 | // Set file and rank labels 87 | $('.top-edge').each(function(i) { $(this).text(fileLabels[i]); }); 88 | $('.right-edge').each(function(i) { $(this).text(rankLabels[i]); }); 89 | $('.bottom-edge').each(function(i) { $(this).text(fileLabels[i]); }); 90 | $('.left-edge').each(function(i) { $(this).text(rankLabels[i]); }); 91 | 92 | // Set square IDs 93 | squares.each(function(i) { $(this).attr('id', squareIDs[i]); }); 94 | }; 95 | 96 | /** 97 | * Attach DOM event handlers 98 | */ 99 | var attachDOMEventHandlers = function() { 100 | 101 | // Highlight valid moves for white pieces 102 | if (playerColor === 'white') { 103 | container.on('click', '.white.pawn', function(ev) { 104 | if (gameState.activePlayer && gameState.activePlayer.color === playerColor) { 105 | highlightValidMoves('wP', ev.target); 106 | } 107 | }); 108 | container.on('click', '.white.rook', function(ev) { 109 | if (gameState.activePlayer && gameState.activePlayer.color === playerColor) { 110 | highlightValidMoves('wR', ev.target); 111 | } 112 | }); 113 | container.on('click', '.white.knight', function(ev) { 114 | if (gameState.activePlayer && gameState.activePlayer.color === playerColor) { 115 | highlightValidMoves('wN', ev.target); 116 | } 117 | }); 118 | container.on('click', '.white.bishop', function(ev) { 119 | if (gameState.activePlayer && gameState.activePlayer.color === playerColor) { 120 | highlightValidMoves('wB', ev.target); 121 | } 122 | }); 123 | container.on('click', '.white.queen', function(ev) { 124 | if (gameState.activePlayer && gameState.activePlayer.color === playerColor) { 125 | highlightValidMoves('wQ', ev.target); 126 | } 127 | }); 128 | container.on('click', '.white.king', function(ev) { 129 | if (gameState.activePlayer && gameState.activePlayer.color === playerColor) { 130 | highlightValidMoves('wK', ev.target); 131 | } 132 | }); 133 | } 134 | 135 | // Highlight valid moves for black pieces 136 | if (playerColor === 'black') { 137 | container.on('click', '.black.pawn', function(ev) { 138 | if (gameState.activePlayer && gameState.activePlayer.color === playerColor) { 139 | highlightValidMoves('bP', ev.target); 140 | } 141 | }); 142 | container.on('click', '.black.rook', function(ev) { 143 | if (gameState.activePlayer && gameState.activePlayer.color === playerColor) { 144 | highlightValidMoves('bR', ev.target); 145 | } 146 | }); 147 | container.on('click', '.black.knight', function(ev) { 148 | if (gameState.activePlayer && gameState.activePlayer.color === playerColor) { 149 | highlightValidMoves('bN', ev.target); 150 | } 151 | }); 152 | container.on('click', '.black.bishop', function(ev) { 153 | if (gameState.activePlayer && gameState.activePlayer.color === playerColor) { 154 | highlightValidMoves('bB', ev.target); 155 | } 156 | }); 157 | container.on('click', '.black.queen', function(ev) { 158 | if (gameState.activePlayer && gameState.activePlayer.color === playerColor) { 159 | highlightValidMoves('bQ', ev.target); 160 | } 161 | }); 162 | container.on('click', '.black.king', function(ev) { 163 | if (gameState.activePlayer && gameState.activePlayer.color === playerColor) { 164 | highlightValidMoves('bK', ev.target); 165 | } 166 | }); 167 | } 168 | 169 | // Clear all move highlights 170 | container.on('click', '.empty', function(ev) { 171 | clearHighlights(); 172 | }); 173 | 174 | // Perform a regular move 175 | container.on('click', '.valid-move', function(ev) { 176 | var m = move(ev.target); 177 | 178 | // Test for pawn promotion 179 | if (/wP....8/.test(m) || /bP....1/.test(m)) { 180 | showPawnPromotionPrompt(function(p) { 181 | // replace piece 182 | messages.empty(); 183 | socket.emit('move', {gameID: gameID, move: m+p}); 184 | }); 185 | } else { 186 | messages.empty(); 187 | socket.emit('move', {gameID: gameID, move: m}); 188 | } 189 | }); 190 | 191 | // Perform a regular capture 192 | container.on('click', '.valid-capture', function(ev) { 193 | var m = capture(ev.target); 194 | 195 | // Test for pawn promotion 196 | if (/wP....8/.test(m) || /bP....1/.test(m)) { 197 | showPawnPromotionPrompt(function(p) { 198 | // replace piece 199 | messages.empty(); 200 | socket.emit('move', {gameID: gameID, move: m+p}); 201 | }); 202 | } else { 203 | messages.empty(); 204 | socket.emit('move', {gameID: gameID, move: m}); 205 | } 206 | }); 207 | 208 | // Perform an en passant capture 209 | container.on('click', '.valid-en-passant-capture', function(ev) { 210 | var m = capture(ev.target); 211 | messages.empty(); 212 | socket.emit('move', {gameID: gameID, move: m+'ep'}); 213 | }); 214 | 215 | // Perform a castle 216 | container.on('click', '.valid-castle', function(ev) { 217 | var m = castle(ev.target); 218 | messages.empty(); 219 | socket.emit('move', {gameID: gameID, move: m}); 220 | }); 221 | 222 | // Forfeit game 223 | container.on('click', '#forfeit', function(ev) { 224 | showForfeitPrompt(function(confirmed) { 225 | if (confirmed) { 226 | messages.empty(); 227 | socket.emit('forfeit', gameID); 228 | } 229 | }); 230 | }); 231 | }; 232 | 233 | /** 234 | * Attach Socket.IO event handlers 235 | */ 236 | var attachSocketEventHandlers = function() { 237 | 238 | // Update UI with new game state 239 | socket.on('update', function(data) { 240 | console.log(data); 241 | gameState = data; 242 | update(); 243 | }); 244 | 245 | // Display an error 246 | socket.on('error', function(data) { 247 | console.log(data); 248 | showErrorMessage(data); 249 | }); 250 | }; 251 | 252 | /** 253 | * Highlight valid moves for the selected piece 254 | */ 255 | var highlightValidMoves = function(piece, selectedSquare) { 256 | var square = $(selectedSquare); 257 | var move = null; 258 | 259 | // Set selection object 260 | selection = { 261 | color: piece[0], 262 | piece: piece[1], 263 | file: square.attr('id')[0], 264 | rank: square.attr('id')[1] 265 | }; 266 | 267 | // Highlight the selected square 268 | squares.removeClass('selected'); 269 | square.addClass('selected'); 270 | 271 | // Highlight any valid moves 272 | squares.removeClass('valid-move valid-capture valid-en-passant-capture valid-castle'); 273 | for (var i=0; i'); 455 | } 456 | } 457 | } 458 | 459 | // Update board 460 | for (var sq in gameState.board) { 461 | $('#'+sq).removeClass(gameClasses).addClass(getPieceClasses(gameState.board[sq])); 462 | } 463 | 464 | // Highlight last move 465 | if (gameState.lastMove) { 466 | if (gameState.lastMove.type === 'move' || gameState.lastMove.type === 'capture') { 467 | $('#'+gameState.lastMove.startSquare).addClass('last-move'); 468 | $('#'+gameState.lastMove.endSquare).addClass('last-move'); 469 | } 470 | else if (gameState.lastMove.type === 'castle') { 471 | if (gameState.lastMove.pieceCode === 'wK' && gameState.lastMove.boardSide === 'queen') { 472 | $('#e1').addClass('last-move'); 473 | $('#c1').addClass('last-move'); 474 | } 475 | if (gameState.lastMove.pieceCode === 'wK' && gameState.lastMove.boardSide === 'king') { 476 | $('#e1').addClass('last-move'); 477 | $('#g1').addClass('last-move'); 478 | } 479 | if (gameState.lastMove.pieceCode === 'bK' && gameState.lastMove.boardSide === 'queen') { 480 | $('#e8').addClass('last-move'); 481 | $('#c8').addClass('last-move'); 482 | } 483 | if (gameState.lastMove.pieceCode === 'bK' && gameState.lastMove.boardSide === 'king') { 484 | $('#e8').addClass('last-move'); 485 | $('#g8').addClass('last-move'); 486 | } 487 | } 488 | } 489 | 490 | // Test for checkmate 491 | if (gameState.status === 'checkmate') { 492 | if (opponent.inCheck) { showGameOverMessage('checkmate-win'); } 493 | if (you.inCheck) { showGameOverMessage('checkmate-lose'); } 494 | } 495 | 496 | // Test for stalemate 497 | if (gameState.status === 'stalemate') { showGameOverMessage('stalemate'); } 498 | 499 | // Test for forfeit 500 | if (gameState.status === 'forfeit') { 501 | if (opponent.forfeited) { showGameOverMessage('forfeit-win'); } 502 | if (you.forfeited) { showGameOverMessage('forfeit-lose'); } 503 | } 504 | }; 505 | 506 | /** 507 | * Display an error message on the page 508 | */ 509 | var showErrorMessage = function(data) { 510 | var msg, html = ''; 511 | 512 | if (data == 'handshake unauthorized') { 513 | msg = 'Client connection failed'; 514 | } else { 515 | msg = data.message; 516 | } 517 | 518 | html = '
'+msg+'
'; 519 | messages.append(html); 520 | }; 521 | 522 | /** 523 | * Display the "Game Over" window 524 | */ 525 | var showGameOverMessage = function(type) { 526 | var header = gameOverMessage.find('h2'); 527 | 528 | // Set the header's content and CSS classes 529 | header.removeClass('alert-success alert-danger alert-warning'); 530 | switch (type) { 531 | case 'checkmate-win' : header.addClass('alert-success').text('Checkmate'); break; 532 | case 'checkmate-lose' : header.addClass('alert-danger').text('Checkmate'); break; 533 | case 'forfeit-win' : header.addClass('alert-success').text('Your opponent has forfeited the game'); break; 534 | case 'forfeit-lose' : header.addClass('alert-danger').text('You have forfeited the game'); break; 535 | case 'stalemate' : header.addClass('alert-warning').text('Stalemate'); break; 536 | } 537 | 538 | gameOverMessage.modal('show'); 539 | }; 540 | 541 | /** 542 | * Display the "Pawn Promotion" prompt 543 | */ 544 | var showPawnPromotionPrompt = function(callback) { 545 | 546 | // Set the pieces' color to match the player's color 547 | pawnPromotionPrompt.find('label').removeClass('black white').addClass(playerColor); 548 | 549 | // Temporarily attach click handler for the Promote button, note the use of .one() 550 | pawnPromotionPrompt.one('click', 'button', function(ev) { 551 | var selection = pawnPromotionPrompt.find("input[type='radio'][name='promotion']:checked").val(); 552 | callback('p'+selection); 553 | pawnPromotionPrompt.modal('hide'); 554 | }); 555 | 556 | pawnPromotionPrompt.modal('show'); 557 | }; 558 | 559 | /** 560 | * Display the "Forfeit Game" confirmation prompt 561 | */ 562 | var showForfeitPrompt = function(callback) { 563 | 564 | // Temporarily attach click handler for the Cancel button, note the use of .one() 565 | forfeitPrompt.one('click', '#cancel-forfeit', function(ev) { 566 | callback(false); 567 | forfeitPrompt.modal('hide'); 568 | }); 569 | 570 | // Temporarily attach click handler for the Confirm button, note the use of .one() 571 | forfeitPrompt.one('click', '#confirm-forfeit', function(ev) { 572 | callback(true); 573 | forfeitPrompt.modal('hide'); 574 | }); 575 | 576 | forfeitPrompt.modal('show'); 577 | }; 578 | 579 | /** 580 | * Get the corresponding CSS classes for a given piece 581 | */ 582 | var getPieceClasses = function(piece) { 583 | switch (piece) { 584 | case 'bP' : return 'black pawn'; 585 | case 'bP_' : return 'black pawn not-moved'; 586 | case 'bR' : return 'black rook'; 587 | case 'bR_' : return 'black rook not-moved'; 588 | case 'bN' : return 'black knight'; 589 | case 'bN_' : return 'black knight not-moved'; 590 | case 'bB' : return 'black bishop'; 591 | case 'bB_' : return 'black bishop not-moved'; 592 | case 'bQ' : return 'black queen'; 593 | case 'bQ_' : return 'black queen not-moved'; 594 | case 'bK' : return 'black king'; 595 | case 'bK_' : return 'black king not-moved'; 596 | case 'wP' : return 'white pawn'; 597 | case 'wP_' : return 'white pawn not-moved'; 598 | case 'wR' : return 'white rook'; 599 | case 'wR_' : return 'white rook not-moved'; 600 | case 'wN' : return 'white knight'; 601 | case 'wN_' : return 'white knight not-moved'; 602 | case 'wB' : return 'white bishop'; 603 | case 'wB_' : return 'white bishop not-moved'; 604 | case 'wQ' : return 'white queen'; 605 | case 'wQ_' : return 'white queen not-moved'; 606 | case 'wK' : return 'white king'; 607 | case 'wK_' : return 'white king not-moved'; 608 | default : return 'empty'; 609 | } 610 | }; 611 | 612 | return init; 613 | 614 | }(window)); -------------------------------------------------------------------------------- /public/js/fastclick.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve FastClick: polyfill to remove click delays on browsers with touch UIs. 3 | * 4 | * @version 0.6.9 5 | * @codingstandard ftlabs-jsv2 6 | * @copyright The Financial Times Limited [All Rights Reserved] 7 | * @license MIT License (see LICENSE.txt) 8 | */ 9 | 10 | /*jslint browser:true, node:true*/ 11 | /*global define, Event, Node*/ 12 | 13 | 14 | /** 15 | * Instantiate fast-clicking listeners on the specificed layer. 16 | * 17 | * @constructor 18 | * @param {Element} layer The layer to listen on 19 | */ 20 | function FastClick(layer) { 21 | 'use strict'; 22 | var oldOnClick, self = this; 23 | 24 | 25 | /** 26 | * Whether a click is currently being tracked. 27 | * 28 | * @type boolean 29 | */ 30 | this.trackingClick = false; 31 | 32 | 33 | /** 34 | * Timestamp for when when click tracking started. 35 | * 36 | * @type number 37 | */ 38 | this.trackingClickStart = 0; 39 | 40 | 41 | /** 42 | * The element being tracked for a click. 43 | * 44 | * @type EventTarget 45 | */ 46 | this.targetElement = null; 47 | 48 | 49 | /** 50 | * X-coordinate of touch start event. 51 | * 52 | * @type number 53 | */ 54 | this.touchStartX = 0; 55 | 56 | 57 | /** 58 | * Y-coordinate of touch start event. 59 | * 60 | * @type number 61 | */ 62 | this.touchStartY = 0; 63 | 64 | 65 | /** 66 | * ID of the last touch, retrieved from Touch.identifier. 67 | * 68 | * @type number 69 | */ 70 | this.lastTouchIdentifier = 0; 71 | 72 | 73 | /** 74 | * Touchmove boundary, beyond which a click will be cancelled. 75 | * 76 | * @type number 77 | */ 78 | this.touchBoundary = 10; 79 | 80 | 81 | /** 82 | * The FastClick layer. 83 | * 84 | * @type Element 85 | */ 86 | this.layer = layer; 87 | 88 | if (!layer || !layer.nodeType) { 89 | throw new TypeError('Layer must be a document node'); 90 | } 91 | 92 | /** @type function() */ 93 | this.onClick = function() { return FastClick.prototype.onClick.apply(self, arguments); }; 94 | 95 | /** @type function() */ 96 | this.onMouse = function() { return FastClick.prototype.onMouse.apply(self, arguments); }; 97 | 98 | /** @type function() */ 99 | this.onTouchStart = function() { return FastClick.prototype.onTouchStart.apply(self, arguments); }; 100 | 101 | /** @type function() */ 102 | this.onTouchEnd = function() { return FastClick.prototype.onTouchEnd.apply(self, arguments); }; 103 | 104 | /** @type function() */ 105 | this.onTouchCancel = function() { return FastClick.prototype.onTouchCancel.apply(self, arguments); }; 106 | 107 | if (FastClick.notNeeded(layer)) { 108 | return; 109 | } 110 | 111 | // Set up event handlers as required 112 | if (this.deviceIsAndroid) { 113 | layer.addEventListener('mouseover', this.onMouse, true); 114 | layer.addEventListener('mousedown', this.onMouse, true); 115 | layer.addEventListener('mouseup', this.onMouse, true); 116 | } 117 | 118 | layer.addEventListener('click', this.onClick, true); 119 | layer.addEventListener('touchstart', this.onTouchStart, false); 120 | layer.addEventListener('touchend', this.onTouchEnd, false); 121 | layer.addEventListener('touchcancel', this.onTouchCancel, false); 122 | 123 | // Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2) 124 | // which is how FastClick normally stops click events bubbling to callbacks registered on the FastClick 125 | // layer when they are cancelled. 126 | if (!Event.prototype.stopImmediatePropagation) { 127 | layer.removeEventListener = function(type, callback, capture) { 128 | var rmv = Node.prototype.removeEventListener; 129 | if (type === 'click') { 130 | rmv.call(layer, type, callback.hijacked || callback, capture); 131 | } else { 132 | rmv.call(layer, type, callback, capture); 133 | } 134 | }; 135 | 136 | layer.addEventListener = function(type, callback, capture) { 137 | var adv = Node.prototype.addEventListener; 138 | if (type === 'click') { 139 | adv.call(layer, type, callback.hijacked || (callback.hijacked = function(event) { 140 | if (!event.propagationStopped) { 141 | callback(event); 142 | } 143 | }), capture); 144 | } else { 145 | adv.call(layer, type, callback, capture); 146 | } 147 | }; 148 | } 149 | 150 | // If a handler is already declared in the element's onclick attribute, it will be fired before 151 | // FastClick's onClick handler. Fix this by pulling out the user-defined handler function and 152 | // adding it as listener. 153 | if (typeof layer.onclick === 'function') { 154 | 155 | // Android browser on at least 3.2 requires a new reference to the function in layer.onclick 156 | // - the old one won't work if passed to addEventListener directly. 157 | oldOnClick = layer.onclick; 158 | layer.addEventListener('click', function(event) { 159 | oldOnClick(event); 160 | }, false); 161 | layer.onclick = null; 162 | } 163 | } 164 | 165 | 166 | /** 167 | * Android requires exceptions. 168 | * 169 | * @type boolean 170 | */ 171 | FastClick.prototype.deviceIsAndroid = navigator.userAgent.indexOf('Android') > 0; 172 | 173 | 174 | /** 175 | * iOS requires exceptions. 176 | * 177 | * @type boolean 178 | */ 179 | FastClick.prototype.deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent); 180 | 181 | 182 | /** 183 | * iOS 4 requires an exception for select elements. 184 | * 185 | * @type boolean 186 | */ 187 | FastClick.prototype.deviceIsIOS4 = FastClick.prototype.deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent); 188 | 189 | 190 | /** 191 | * iOS 6.0(+?) requires the target element to be manually derived 192 | * 193 | * @type boolean 194 | */ 195 | FastClick.prototype.deviceIsIOSWithBadTarget = FastClick.prototype.deviceIsIOS && (/OS ([6-9]|\d{2})_\d/).test(navigator.userAgent); 196 | 197 | 198 | /** 199 | * Determine whether a given element requires a native click. 200 | * 201 | * @param {EventTarget|Element} target Target DOM element 202 | * @returns {boolean} Returns true if the element needs a native click 203 | */ 204 | FastClick.prototype.needsClick = function(target) { 205 | 'use strict'; 206 | switch (target.nodeName.toLowerCase()) { 207 | 208 | // Don't send a synthetic click to disabled inputs (issue #62) 209 | case 'button': 210 | case 'select': 211 | case 'textarea': 212 | if (target.disabled) { 213 | return true; 214 | } 215 | 216 | break; 217 | case 'input': 218 | 219 | // File inputs need real clicks on iOS 6 due to a browser bug (issue #68) 220 | if ((this.deviceIsIOS && target.type === 'file') || target.disabled) { 221 | return true; 222 | } 223 | 224 | break; 225 | case 'label': 226 | case 'video': 227 | return true; 228 | } 229 | 230 | return (/\bneedsclick\b/).test(target.className); 231 | }; 232 | 233 | 234 | /** 235 | * Determine whether a given element requires a call to focus to simulate click into element. 236 | * 237 | * @param {EventTarget|Element} target Target DOM element 238 | * @returns {boolean} Returns true if the element requires a call to focus to simulate native click. 239 | */ 240 | FastClick.prototype.needsFocus = function(target) { 241 | 'use strict'; 242 | switch (target.nodeName.toLowerCase()) { 243 | case 'textarea': 244 | case 'select': 245 | return true; 246 | case 'input': 247 | switch (target.type) { 248 | case 'button': 249 | case 'checkbox': 250 | case 'file': 251 | case 'image': 252 | case 'radio': 253 | case 'submit': 254 | return false; 255 | } 256 | 257 | // No point in attempting to focus disabled inputs 258 | return !target.disabled && !target.readOnly; 259 | default: 260 | return (/\bneedsfocus\b/).test(target.className); 261 | } 262 | }; 263 | 264 | 265 | /** 266 | * Send a click event to the specified element. 267 | * 268 | * @param {EventTarget|Element} targetElement 269 | * @param {Event} event 270 | */ 271 | FastClick.prototype.sendClick = function(targetElement, event) { 272 | 'use strict'; 273 | var clickEvent, touch; 274 | 275 | // On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect (#24) 276 | if (document.activeElement && document.activeElement !== targetElement) { 277 | document.activeElement.blur(); 278 | } 279 | 280 | touch = event.changedTouches[0]; 281 | 282 | // Synthesise a click event, with an extra attribute so it can be tracked 283 | clickEvent = document.createEvent('MouseEvents'); 284 | clickEvent.initMouseEvent('click', true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); 285 | clickEvent.forwardedTouchEvent = true; 286 | targetElement.dispatchEvent(clickEvent); 287 | }; 288 | 289 | 290 | /** 291 | * @param {EventTarget|Element} targetElement 292 | */ 293 | FastClick.prototype.focus = function(targetElement) { 294 | 'use strict'; 295 | var length; 296 | 297 | if (this.deviceIsIOS && targetElement.setSelectionRange) { 298 | length = targetElement.value.length; 299 | targetElement.setSelectionRange(length, length); 300 | } else { 301 | targetElement.focus(); 302 | } 303 | }; 304 | 305 | 306 | /** 307 | * Check whether the given target element is a child of a scrollable layer and if so, set a flag on it. 308 | * 309 | * @param {EventTarget|Element} targetElement 310 | */ 311 | FastClick.prototype.updateScrollParent = function(targetElement) { 312 | 'use strict'; 313 | var scrollParent, parentElement; 314 | 315 | scrollParent = targetElement.fastClickScrollParent; 316 | 317 | // Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the 318 | // target element was moved to another parent. 319 | if (!scrollParent || !scrollParent.contains(targetElement)) { 320 | parentElement = targetElement; 321 | do { 322 | if (parentElement.scrollHeight > parentElement.offsetHeight) { 323 | scrollParent = parentElement; 324 | targetElement.fastClickScrollParent = parentElement; 325 | break; 326 | } 327 | 328 | parentElement = parentElement.parentElement; 329 | } while (parentElement); 330 | } 331 | 332 | // Always update the scroll top tracker if possible. 333 | if (scrollParent) { 334 | scrollParent.fastClickLastScrollTop = scrollParent.scrollTop; 335 | } 336 | }; 337 | 338 | 339 | /** 340 | * @param {EventTarget} targetElement 341 | * @returns {Element|EventTarget} 342 | */ 343 | FastClick.prototype.getTargetElementFromEventTarget = function(eventTarget) { 344 | 'use strict'; 345 | 346 | // On some older browsers (notably Safari on iOS 4.1 - see issue #56) the event target may be a text node. 347 | if (eventTarget.nodeType === Node.TEXT_NODE) { 348 | return eventTarget.parentNode; 349 | } 350 | 351 | return eventTarget; 352 | }; 353 | 354 | 355 | /** 356 | * On touch start, record the position and scroll offset. 357 | * 358 | * @param {Event} event 359 | * @returns {boolean} 360 | */ 361 | FastClick.prototype.onTouchStart = function(event) { 362 | 'use strict'; 363 | var targetElement, touch, selection; 364 | 365 | // Ignore multiple touches, otherwise pinch-to-zoom is prevented if both fingers are on the FastClick element (issue #111). 366 | if (event.targetTouches.length > 1) { 367 | return true; 368 | } 369 | 370 | targetElement = this.getTargetElementFromEventTarget(event.target); 371 | touch = event.targetTouches[0]; 372 | 373 | if (this.deviceIsIOS) { 374 | 375 | // Only trusted events will deselect text on iOS (issue #49) 376 | selection = window.getSelection(); 377 | if (selection.rangeCount && !selection.isCollapsed) { 378 | return true; 379 | } 380 | 381 | if (!this.deviceIsIOS4) { 382 | 383 | // Weird things happen on iOS when an alert or confirm dialog is opened from a click event callback (issue #23): 384 | // when the user next taps anywhere else on the page, new touchstart and touchend events are dispatched 385 | // with the same identifier as the touch event that previously triggered the click that triggered the alert. 386 | // Sadly, there is an issue on iOS 4 that causes some normal touch events to have the same identifier as an 387 | // immediately preceeding touch event (issue #52), so this fix is unavailable on that platform. 388 | if (touch.identifier === this.lastTouchIdentifier) { 389 | event.preventDefault(); 390 | return false; 391 | } 392 | 393 | this.lastTouchIdentifier = touch.identifier; 394 | 395 | // If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and: 396 | // 1) the user does a fling scroll on the scrollable layer 397 | // 2) the user stops the fling scroll with another tap 398 | // then the event.target of the last 'touchend' event will be the element that was under the user's finger 399 | // when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check 400 | // is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42). 401 | this.updateScrollParent(targetElement); 402 | } 403 | } 404 | 405 | this.trackingClick = true; 406 | this.trackingClickStart = event.timeStamp; 407 | this.targetElement = targetElement; 408 | 409 | this.touchStartX = touch.pageX; 410 | this.touchStartY = touch.pageY; 411 | 412 | // Prevent phantom clicks on fast double-tap (issue #36) 413 | if ((event.timeStamp - this.lastClickTime) < 200) { 414 | event.preventDefault(); 415 | } 416 | 417 | return true; 418 | }; 419 | 420 | 421 | /** 422 | * Based on a touchmove event object, check whether the touch has moved past a boundary since it started. 423 | * 424 | * @param {Event} event 425 | * @returns {boolean} 426 | */ 427 | FastClick.prototype.touchHasMoved = function(event) { 428 | 'use strict'; 429 | var touch = event.changedTouches[0], boundary = this.touchBoundary; 430 | 431 | if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) { 432 | return true; 433 | } 434 | 435 | return false; 436 | }; 437 | 438 | 439 | /** 440 | * Attempt to find the labelled control for the given label element. 441 | * 442 | * @param {EventTarget|HTMLLabelElement} labelElement 443 | * @returns {Element|null} 444 | */ 445 | FastClick.prototype.findControl = function(labelElement) { 446 | 'use strict'; 447 | 448 | // Fast path for newer browsers supporting the HTML5 control attribute 449 | if (labelElement.control !== undefined) { 450 | return labelElement.control; 451 | } 452 | 453 | // All browsers under test that support touch events also support the HTML5 htmlFor attribute 454 | if (labelElement.htmlFor) { 455 | return document.getElementById(labelElement.htmlFor); 456 | } 457 | 458 | // If no for attribute exists, attempt to retrieve the first labellable descendant element 459 | // the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label 460 | return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea'); 461 | }; 462 | 463 | 464 | /** 465 | * On touch end, determine whether to send a click event at once. 466 | * 467 | * @param {Event} event 468 | * @returns {boolean} 469 | */ 470 | FastClick.prototype.onTouchEnd = function(event) { 471 | 'use strict'; 472 | var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement; 473 | 474 | // If the touch has moved, cancel the click tracking 475 | if (this.touchHasMoved(event)) { 476 | this.trackingClick = false; 477 | this.targetElement = null; 478 | } 479 | 480 | if (!this.trackingClick) { 481 | return true; 482 | } 483 | 484 | // Prevent phantom clicks on fast double-tap (issue #36) 485 | if ((event.timeStamp - this.lastClickTime) < 200) { 486 | this.cancelNextClick = true; 487 | return true; 488 | } 489 | 490 | this.lastClickTime = event.timeStamp; 491 | 492 | trackingClickStart = this.trackingClickStart; 493 | this.trackingClick = false; 494 | this.trackingClickStart = 0; 495 | 496 | // On some iOS devices, the targetElement supplied with the event is invalid if the layer 497 | // is performing a transition or scroll, and has to be re-detected manually. Note that 498 | // for this to function correctly, it must be called *after* the event target is checked! 499 | // See issue #57; also filed as rdar://13048589 . 500 | if (this.deviceIsIOSWithBadTarget) { 501 | touch = event.changedTouches[0]; 502 | 503 | // In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null 504 | targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement; 505 | targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent; 506 | } 507 | 508 | targetTagName = targetElement.tagName.toLowerCase(); 509 | if (targetTagName === 'label') { 510 | forElement = this.findControl(targetElement); 511 | if (forElement) { 512 | this.focus(targetElement); 513 | if (this.deviceIsAndroid) { 514 | return false; 515 | } 516 | 517 | targetElement = forElement; 518 | } 519 | } else if (this.needsFocus(targetElement)) { 520 | 521 | // Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through. 522 | // Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37). 523 | if ((event.timeStamp - trackingClickStart) > 100 || (this.deviceIsIOS && window.top !== window && targetTagName === 'input')) { 524 | this.targetElement = null; 525 | return false; 526 | } 527 | 528 | this.focus(targetElement); 529 | 530 | // Select elements need the event to go through on iOS 4, otherwise the selector menu won't open. 531 | if (!this.deviceIsIOS4 || targetTagName !== 'select') { 532 | this.targetElement = null; 533 | event.preventDefault(); 534 | } 535 | 536 | return false; 537 | } 538 | 539 | if (this.deviceIsIOS && !this.deviceIsIOS4) { 540 | 541 | // Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled 542 | // and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42). 543 | scrollParent = targetElement.fastClickScrollParent; 544 | if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) { 545 | return true; 546 | } 547 | } 548 | 549 | // Prevent the actual click from going though - unless the target node is marked as requiring 550 | // real clicks or if it is in the whitelist in which case only non-programmatic clicks are permitted. 551 | if (!this.needsClick(targetElement)) { 552 | event.preventDefault(); 553 | this.sendClick(targetElement, event); 554 | } 555 | 556 | return false; 557 | }; 558 | 559 | 560 | /** 561 | * On touch cancel, stop tracking the click. 562 | * 563 | * @returns {void} 564 | */ 565 | FastClick.prototype.onTouchCancel = function() { 566 | 'use strict'; 567 | this.trackingClick = false; 568 | this.targetElement = null; 569 | }; 570 | 571 | 572 | /** 573 | * Determine mouse events which should be permitted. 574 | * 575 | * @param {Event} event 576 | * @returns {boolean} 577 | */ 578 | FastClick.prototype.onMouse = function(event) { 579 | 'use strict'; 580 | 581 | // If a target element was never set (because a touch event was never fired) allow the event 582 | if (!this.targetElement) { 583 | return true; 584 | } 585 | 586 | if (event.forwardedTouchEvent) { 587 | return true; 588 | } 589 | 590 | // Programmatically generated events targeting a specific element should be permitted 591 | if (!event.cancelable) { 592 | return true; 593 | } 594 | 595 | // Derive and check the target element to see whether the mouse event needs to be permitted; 596 | // unless explicitly enabled, prevent non-touch click events from triggering actions, 597 | // to prevent ghost/doubleclicks. 598 | if (!this.needsClick(this.targetElement) || this.cancelNextClick) { 599 | 600 | // Prevent any user-added listeners declared on FastClick element from being fired. 601 | if (event.stopImmediatePropagation) { 602 | event.stopImmediatePropagation(); 603 | } else { 604 | 605 | // Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2) 606 | event.propagationStopped = true; 607 | } 608 | 609 | // Cancel the event 610 | event.stopPropagation(); 611 | event.preventDefault(); 612 | 613 | return false; 614 | } 615 | 616 | // If the mouse event is permitted, return true for the action to go through. 617 | return true; 618 | }; 619 | 620 | 621 | /** 622 | * On actual clicks, determine whether this is a touch-generated click, a click action occurring 623 | * naturally after a delay after a touch (which needs to be cancelled to avoid duplication), or 624 | * an actual click which should be permitted. 625 | * 626 | * @param {Event} event 627 | * @returns {boolean} 628 | */ 629 | FastClick.prototype.onClick = function(event) { 630 | 'use strict'; 631 | var permitted; 632 | 633 | // It's possible for another FastClick-like library delivered with third-party code to fire a click event before FastClick does (issue #44). In that case, set the click-tracking flag back to false and return early. This will cause onTouchEnd to return early. 634 | if (this.trackingClick) { 635 | this.targetElement = null; 636 | this.trackingClick = false; 637 | return true; 638 | } 639 | 640 | // Very odd behaviour on iOS (issue #18): if a submit element is present inside a form and the user hits enter in the iOS simulator or clicks the Go button on the pop-up OS keyboard the a kind of 'fake' click event will be triggered with the submit-type input element as the target. 641 | if (event.target.type === 'submit' && event.detail === 0) { 642 | return true; 643 | } 644 | 645 | permitted = this.onMouse(event); 646 | 647 | // Only unset targetElement if the click is not permitted. This will ensure that the check for !targetElement in onMouse fails and the browser's click doesn't go through. 648 | if (!permitted) { 649 | this.targetElement = null; 650 | } 651 | 652 | // If clicks are permitted, return true for the action to go through. 653 | return permitted; 654 | }; 655 | 656 | 657 | /** 658 | * Remove all FastClick's event listeners. 659 | * 660 | * @returns {void} 661 | */ 662 | FastClick.prototype.destroy = function() { 663 | 'use strict'; 664 | var layer = this.layer; 665 | 666 | if (this.deviceIsAndroid) { 667 | layer.removeEventListener('mouseover', this.onMouse, true); 668 | layer.removeEventListener('mousedown', this.onMouse, true); 669 | layer.removeEventListener('mouseup', this.onMouse, true); 670 | } 671 | 672 | layer.removeEventListener('click', this.onClick, true); 673 | layer.removeEventListener('touchstart', this.onTouchStart, false); 674 | layer.removeEventListener('touchend', this.onTouchEnd, false); 675 | layer.removeEventListener('touchcancel', this.onTouchCancel, false); 676 | }; 677 | 678 | 679 | /** 680 | * Check whether FastClick is needed. 681 | * 682 | * @param {Element} layer The layer to listen on 683 | */ 684 | FastClick.notNeeded = function(layer) { 685 | 'use strict'; 686 | var metaViewport; 687 | 688 | // Devices that don't support touch don't need FastClick 689 | if (typeof window.ontouchstart === 'undefined') { 690 | return true; 691 | } 692 | 693 | if ((/Chrome\/[0-9]+/).test(navigator.userAgent)) { 694 | 695 | // Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89) 696 | if (FastClick.prototype.deviceIsAndroid) { 697 | metaViewport = document.querySelector('meta[name=viewport]'); 698 | if (metaViewport && metaViewport.content.indexOf('user-scalable=no') !== -1) { 699 | return true; 700 | } 701 | 702 | // Chrome desktop doesn't need FastClick (issue #15) 703 | } else { 704 | return true; 705 | } 706 | } 707 | 708 | // IE10 with -ms-touch-action: none, which disables double-tap-to-zoom (issue #97) 709 | if (layer.style.msTouchAction === 'none') { 710 | return true; 711 | } 712 | 713 | return false; 714 | }; 715 | 716 | 717 | /** 718 | * Factory method for creating a FastClick object 719 | * 720 | * @param {Element} layer The layer to listen on 721 | */ 722 | FastClick.attach = function(layer) { 723 | 'use strict'; 724 | return new FastClick(layer); 725 | }; 726 | 727 | 728 | if (typeof define !== 'undefined' && define.amd) { 729 | 730 | // AMD. Register as an anonymous module. 731 | define(function() { 732 | 'use strict'; 733 | return FastClick; 734 | }); 735 | } else if (typeof module !== 'undefined' && module.exports) { 736 | module.exports = FastClick.attach; 737 | module.exports.FastClick = FastClick; 738 | } else { 739 | window.FastClick = FastClick; 740 | } 741 | -------------------------------------------------------------------------------- /public/js/jquery.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v2.0.3 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license 2 | //@ sourceMappingURL=jquery-2.0.3.min.map 3 | */ 4 | (function(e,undefined){var t,n,r=typeof undefined,i=e.location,o=e.document,s=o.documentElement,a=e.jQuery,u=e.$,l={},c=[],p="2.0.3",f=c.concat,h=c.push,d=c.slice,g=c.indexOf,m=l.toString,y=l.hasOwnProperty,v=p.trim,x=function(e,n){return new x.fn.init(e,n,t)},b=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,w=/\S+/g,T=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,C=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,k=/^-ms-/,N=/-([\da-z])/gi,E=function(e,t){return t.toUpperCase()},S=function(){o.removeEventListener("DOMContentLoaded",S,!1),e.removeEventListener("load",S,!1),x.ready()};x.fn=x.prototype={jquery:p,constructor:x,init:function(e,t,n){var r,i;if(!e)return this;if("string"==typeof e){if(r="<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3?[null,e,null]:T.exec(e),!r||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof x?t[0]:t,x.merge(this,x.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:o,!0)),C.test(r[1])&&x.isPlainObject(t))for(r in t)x.isFunction(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return i=o.getElementById(r[2]),i&&i.parentNode&&(this.length=1,this[0]=i),this.context=o,this.selector=e,this}return e.nodeType?(this.context=this[0]=e,this.length=1,this):x.isFunction(e)?n.ready(e):(e.selector!==undefined&&(this.selector=e.selector,this.context=e.context),x.makeArray(e,this))},selector:"",length:0,toArray:function(){return d.call(this)},get:function(e){return null==e?this.toArray():0>e?this[this.length+e]:this[e]},pushStack:function(e){var t=x.merge(this.constructor(),e);return t.prevObject=this,t.context=this.context,t},each:function(e,t){return x.each(this,e,t)},ready:function(e){return x.ready.promise().done(e),this},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(0>e?t:0);return this.pushStack(n>=0&&t>n?[this[n]]:[])},map:function(e){return this.pushStack(x.map(this,function(t,n){return e.call(t,n,t)}))},end:function(){return this.prevObject||this.constructor(null)},push:h,sort:[].sort,splice:[].splice},x.fn.init.prototype=x.fn,x.extend=x.fn.extend=function(){var e,t,n,r,i,o,s=arguments[0]||{},a=1,u=arguments.length,l=!1;for("boolean"==typeof s&&(l=s,s=arguments[1]||{},a=2),"object"==typeof s||x.isFunction(s)||(s={}),u===a&&(s=this,--a);u>a;a++)if(null!=(e=arguments[a]))for(t in e)n=s[t],r=e[t],s!==r&&(l&&r&&(x.isPlainObject(r)||(i=x.isArray(r)))?(i?(i=!1,o=n&&x.isArray(n)?n:[]):o=n&&x.isPlainObject(n)?n:{},s[t]=x.extend(l,o,r)):r!==undefined&&(s[t]=r));return s},x.extend({expando:"jQuery"+(p+Math.random()).replace(/\D/g,""),noConflict:function(t){return e.$===x&&(e.$=u),t&&e.jQuery===x&&(e.jQuery=a),x},isReady:!1,readyWait:1,holdReady:function(e){e?x.readyWait++:x.ready(!0)},ready:function(e){(e===!0?--x.readyWait:x.isReady)||(x.isReady=!0,e!==!0&&--x.readyWait>0||(n.resolveWith(o,[x]),x.fn.trigger&&x(o).trigger("ready").off("ready")))},isFunction:function(e){return"function"===x.type(e)},isArray:Array.isArray,isWindow:function(e){return null!=e&&e===e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?l[m.call(e)]||"object":typeof e},isPlainObject:function(e){if("object"!==x.type(e)||e.nodeType||x.isWindow(e))return!1;try{if(e.constructor&&!y.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(t){return!1}return!0},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},error:function(e){throw Error(e)},parseHTML:function(e,t,n){if(!e||"string"!=typeof e)return null;"boolean"==typeof t&&(n=t,t=!1),t=t||o;var r=C.exec(e),i=!n&&[];return r?[t.createElement(r[1])]:(r=x.buildFragment([e],t,i),i&&x(i).remove(),x.merge([],r.childNodes))},parseJSON:JSON.parse,parseXML:function(e){var t,n;if(!e||"string"!=typeof e)return null;try{n=new DOMParser,t=n.parseFromString(e,"text/xml")}catch(r){t=undefined}return(!t||t.getElementsByTagName("parsererror").length)&&x.error("Invalid XML: "+e),t},noop:function(){},globalEval:function(e){var t,n=eval;e=x.trim(e),e&&(1===e.indexOf("use strict")?(t=o.createElement("script"),t.text=e,o.head.appendChild(t).parentNode.removeChild(t)):n(e))},camelCase:function(e){return e.replace(k,"ms-").replace(N,E)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,t,n){var r,i=0,o=e.length,s=j(e);if(n){if(s){for(;o>i;i++)if(r=t.apply(e[i],n),r===!1)break}else for(i in e)if(r=t.apply(e[i],n),r===!1)break}else if(s){for(;o>i;i++)if(r=t.call(e[i],i,e[i]),r===!1)break}else for(i in e)if(r=t.call(e[i],i,e[i]),r===!1)break;return e},trim:function(e){return null==e?"":v.call(e)},makeArray:function(e,t){var n=t||[];return null!=e&&(j(Object(e))?x.merge(n,"string"==typeof e?[e]:e):h.call(n,e)),n},inArray:function(e,t,n){return null==t?-1:g.call(t,e,n)},merge:function(e,t){var n=t.length,r=e.length,i=0;if("number"==typeof n)for(;n>i;i++)e[r++]=t[i];else while(t[i]!==undefined)e[r++]=t[i++];return e.length=r,e},grep:function(e,t,n){var r,i=[],o=0,s=e.length;for(n=!!n;s>o;o++)r=!!t(e[o],o),n!==r&&i.push(e[o]);return i},map:function(e,t,n){var r,i=0,o=e.length,s=j(e),a=[];if(s)for(;o>i;i++)r=t(e[i],i,n),null!=r&&(a[a.length]=r);else for(i in e)r=t(e[i],i,n),null!=r&&(a[a.length]=r);return f.apply([],a)},guid:1,proxy:function(e,t){var n,r,i;return"string"==typeof t&&(n=e[t],t=e,e=n),x.isFunction(e)?(r=d.call(arguments,2),i=function(){return e.apply(t||this,r.concat(d.call(arguments)))},i.guid=e.guid=e.guid||x.guid++,i):undefined},access:function(e,t,n,r,i,o,s){var a=0,u=e.length,l=null==n;if("object"===x.type(n)){i=!0;for(a in n)x.access(e,t,a,n[a],!0,o,s)}else if(r!==undefined&&(i=!0,x.isFunction(r)||(s=!0),l&&(s?(t.call(e,r),t=null):(l=t,t=function(e,t,n){return l.call(x(e),n)})),t))for(;u>a;a++)t(e[a],n,s?r:r.call(e[a],a,t(e[a],n)));return i?e:l?t.call(e):u?t(e[0],n):o},now:Date.now,swap:function(e,t,n,r){var i,o,s={};for(o in t)s[o]=e.style[o],e.style[o]=t[o];i=n.apply(e,r||[]);for(o in t)e.style[o]=s[o];return i}}),x.ready.promise=function(t){return n||(n=x.Deferred(),"complete"===o.readyState?setTimeout(x.ready):(o.addEventListener("DOMContentLoaded",S,!1),e.addEventListener("load",S,!1))),n.promise(t)},x.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(e,t){l["[object "+t+"]"]=t.toLowerCase()});function j(e){var t=e.length,n=x.type(e);return x.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}t=x(o),function(e,undefined){var t,n,r,i,o,s,a,u,l,c,p,f,h,d,g,m,y,v="sizzle"+-new Date,b=e.document,w=0,T=0,C=st(),k=st(),N=st(),E=!1,S=function(e,t){return e===t?(E=!0,0):0},j=typeof undefined,D=1<<31,A={}.hasOwnProperty,L=[],q=L.pop,H=L.push,O=L.push,F=L.slice,P=L.indexOf||function(e){var t=0,n=this.length;for(;n>t;t++)if(this[t]===e)return t;return-1},R="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",W="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",$=W.replace("w","w#"),B="\\["+M+"*("+W+")"+M+"*(?:([*^$|!~]?=)"+M+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+$+")|)|)"+M+"*\\]",I=":("+W+")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|"+B.replace(3,8)+")*)|.*)\\)|)",z=RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),_=RegExp("^"+M+"*,"+M+"*"),X=RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=RegExp(M+"*[+~]"),Y=RegExp("="+M+"*([^\\]'\"]*)"+M+"*\\]","g"),V=RegExp(I),G=RegExp("^"+$+"$"),J={ID:RegExp("^#("+W+")"),CLASS:RegExp("^\\.("+W+")"),TAG:RegExp("^("+W.replace("w","w*")+")"),ATTR:RegExp("^"+B),PSEUDO:RegExp("^"+I),CHILD:RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:RegExp("^(?:"+R+")$","i"),needsContext:RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Q=/^[^{]+\{\s*\[native \w/,K=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,Z=/^(?:input|select|textarea|button)$/i,et=/^h\d$/i,tt=/'|\\/g,nt=RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),rt=function(e,t,n){var r="0x"+t-65536;return r!==r||n?t:0>r?String.fromCharCode(r+65536):String.fromCharCode(55296|r>>10,56320|1023&r)};try{O.apply(L=F.call(b.childNodes),b.childNodes),L[b.childNodes.length].nodeType}catch(it){O={apply:L.length?function(e,t){H.apply(e,F.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function ot(e,t,r,i){var o,s,a,u,l,f,g,m,x,w;if((t?t.ownerDocument||t:b)!==p&&c(t),t=t||p,r=r||[],!e||"string"!=typeof e)return r;if(1!==(u=t.nodeType)&&9!==u)return[];if(h&&!i){if(o=K.exec(e))if(a=o[1]){if(9===u){if(s=t.getElementById(a),!s||!s.parentNode)return r;if(s.id===a)return r.push(s),r}else if(t.ownerDocument&&(s=t.ownerDocument.getElementById(a))&&y(t,s)&&s.id===a)return r.push(s),r}else{if(o[2])return O.apply(r,t.getElementsByTagName(e)),r;if((a=o[3])&&n.getElementsByClassName&&t.getElementsByClassName)return O.apply(r,t.getElementsByClassName(a)),r}if(n.qsa&&(!d||!d.test(e))){if(m=g=v,x=t,w=9===u&&e,1===u&&"object"!==t.nodeName.toLowerCase()){f=gt(e),(g=t.getAttribute("id"))?m=g.replace(tt,"\\$&"):t.setAttribute("id",m),m="[id='"+m+"'] ",l=f.length;while(l--)f[l]=m+mt(f[l]);x=U.test(e)&&t.parentNode||t,w=f.join(",")}if(w)try{return O.apply(r,x.querySelectorAll(w)),r}catch(T){}finally{g||t.removeAttribute("id")}}}return kt(e.replace(z,"$1"),t,r,i)}function st(){var e=[];function t(n,r){return e.push(n+=" ")>i.cacheLength&&delete t[e.shift()],t[n]=r}return t}function at(e){return e[v]=!0,e}function ut(e){var t=p.createElement("div");try{return!!e(t)}catch(n){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function lt(e,t){var n=e.split("|"),r=e.length;while(r--)i.attrHandle[n[r]]=t}function ct(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&(~t.sourceIndex||D)-(~e.sourceIndex||D);if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function pt(e){return function(t){var n=t.nodeName.toLowerCase();return"input"===n&&t.type===e}}function ft(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function ht(e){return at(function(t){return t=+t,at(function(n,r){var i,o=e([],n.length,t),s=o.length;while(s--)n[i=o[s]]&&(n[i]=!(r[i]=n[i]))})})}s=ot.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?"HTML"!==t.nodeName:!1},n=ot.support={},c=ot.setDocument=function(e){var t=e?e.ownerDocument||e:b,r=t.defaultView;return t!==p&&9===t.nodeType&&t.documentElement?(p=t,f=t.documentElement,h=!s(t),r&&r.attachEvent&&r!==r.top&&r.attachEvent("onbeforeunload",function(){c()}),n.attributes=ut(function(e){return e.className="i",!e.getAttribute("className")}),n.getElementsByTagName=ut(function(e){return e.appendChild(t.createComment("")),!e.getElementsByTagName("*").length}),n.getElementsByClassName=ut(function(e){return e.innerHTML="
",e.firstChild.className="i",2===e.getElementsByClassName("i").length}),n.getById=ut(function(e){return f.appendChild(e).id=v,!t.getElementsByName||!t.getElementsByName(v).length}),n.getById?(i.find.ID=function(e,t){if(typeof t.getElementById!==j&&h){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},i.filter.ID=function(e){var t=e.replace(nt,rt);return function(e){return e.getAttribute("id")===t}}):(delete i.find.ID,i.filter.ID=function(e){var t=e.replace(nt,rt);return function(e){var n=typeof e.getAttributeNode!==j&&e.getAttributeNode("id");return n&&n.value===t}}),i.find.TAG=n.getElementsByTagName?function(e,t){return typeof t.getElementsByTagName!==j?t.getElementsByTagName(e):undefined}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},i.find.CLASS=n.getElementsByClassName&&function(e,t){return typeof t.getElementsByClassName!==j&&h?t.getElementsByClassName(e):undefined},g=[],d=[],(n.qsa=Q.test(t.querySelectorAll))&&(ut(function(e){e.innerHTML="",e.querySelectorAll("[selected]").length||d.push("\\["+M+"*(?:value|"+R+")"),e.querySelectorAll(":checked").length||d.push(":checked")}),ut(function(e){var n=t.createElement("input");n.setAttribute("type","hidden"),e.appendChild(n).setAttribute("t",""),e.querySelectorAll("[t^='']").length&&d.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll(":enabled").length||d.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),d.push(",.*:")})),(n.matchesSelector=Q.test(m=f.webkitMatchesSelector||f.mozMatchesSelector||f.oMatchesSelector||f.msMatchesSelector))&&ut(function(e){n.disconnectedMatch=m.call(e,"div"),m.call(e,"[s!='']:x"),g.push("!=",I)}),d=d.length&&RegExp(d.join("|")),g=g.length&&RegExp(g.join("|")),y=Q.test(f.contains)||f.compareDocumentPosition?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},S=f.compareDocumentPosition?function(e,r){if(e===r)return E=!0,0;var i=r.compareDocumentPosition&&e.compareDocumentPosition&&e.compareDocumentPosition(r);return i?1&i||!n.sortDetached&&r.compareDocumentPosition(e)===i?e===t||y(b,e)?-1:r===t||y(b,r)?1:l?P.call(l,e)-P.call(l,r):0:4&i?-1:1:e.compareDocumentPosition?-1:1}:function(e,n){var r,i=0,o=e.parentNode,s=n.parentNode,a=[e],u=[n];if(e===n)return E=!0,0;if(!o||!s)return e===t?-1:n===t?1:o?-1:s?1:l?P.call(l,e)-P.call(l,n):0;if(o===s)return ct(e,n);r=e;while(r=r.parentNode)a.unshift(r);r=n;while(r=r.parentNode)u.unshift(r);while(a[i]===u[i])i++;return i?ct(a[i],u[i]):a[i]===b?-1:u[i]===b?1:0},t):p},ot.matches=function(e,t){return ot(e,null,null,t)},ot.matchesSelector=function(e,t){if((e.ownerDocument||e)!==p&&c(e),t=t.replace(Y,"='$1']"),!(!n.matchesSelector||!h||g&&g.test(t)||d&&d.test(t)))try{var r=m.call(e,t);if(r||n.disconnectedMatch||e.document&&11!==e.document.nodeType)return r}catch(i){}return ot(t,p,null,[e]).length>0},ot.contains=function(e,t){return(e.ownerDocument||e)!==p&&c(e),y(e,t)},ot.attr=function(e,t){(e.ownerDocument||e)!==p&&c(e);var r=i.attrHandle[t.toLowerCase()],o=r&&A.call(i.attrHandle,t.toLowerCase())?r(e,t,!h):undefined;return o===undefined?n.attributes||!h?e.getAttribute(t):(o=e.getAttributeNode(t))&&o.specified?o.value:null:o},ot.error=function(e){throw Error("Syntax error, unrecognized expression: "+e)},ot.uniqueSort=function(e){var t,r=[],i=0,o=0;if(E=!n.detectDuplicates,l=!n.sortStable&&e.slice(0),e.sort(S),E){while(t=e[o++])t===e[o]&&(i=r.push(o));while(i--)e.splice(r[i],1)}return e},o=ot.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=o(e)}else if(3===i||4===i)return e.nodeValue}else for(;t=e[r];r++)n+=o(t);return n},i=ot.selectors={cacheLength:50,createPseudo:at,match:J,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(nt,rt),e[3]=(e[4]||e[5]||"").replace(nt,rt),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||ot.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&ot.error(e[0]),e},PSEUDO:function(e){var t,n=!e[5]&&e[2];return J.CHILD.test(e[0])?null:(e[3]&&e[4]!==undefined?e[2]=e[4]:n&&V.test(n)&&(t=gt(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(nt,rt).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=C[e+" "];return t||(t=RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&C(e,function(e){return t.test("string"==typeof e.className&&e.className||typeof e.getAttribute!==j&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=ot.attr(r,e);return null==i?"!="===t:t?(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i+" ").indexOf(n)>-1:"|="===t?i===n||i.slice(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),s="last"!==e.slice(-4),a="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,u){var l,c,p,f,h,d,g=o!==s?"nextSibling":"previousSibling",m=t.parentNode,y=a&&t.nodeName.toLowerCase(),x=!u&&!a;if(m){if(o){while(g){p=t;while(p=p[g])if(a?p.nodeName.toLowerCase()===y:1===p.nodeType)return!1;d=g="only"===e&&!d&&"nextSibling"}return!0}if(d=[s?m.firstChild:m.lastChild],s&&x){c=m[v]||(m[v]={}),l=c[e]||[],h=l[0]===w&&l[1],f=l[0]===w&&l[2],p=h&&m.childNodes[h];while(p=++h&&p&&p[g]||(f=h=0)||d.pop())if(1===p.nodeType&&++f&&p===t){c[e]=[w,h,f];break}}else if(x&&(l=(t[v]||(t[v]={}))[e])&&l[0]===w)f=l[1];else while(p=++h&&p&&p[g]||(f=h=0)||d.pop())if((a?p.nodeName.toLowerCase()===y:1===p.nodeType)&&++f&&(x&&((p[v]||(p[v]={}))[e]=[w,f]),p===t))break;return f-=i,f===r||0===f%r&&f/r>=0}}},PSEUDO:function(e,t){var n,r=i.pseudos[e]||i.setFilters[e.toLowerCase()]||ot.error("unsupported pseudo: "+e);return r[v]?r(t):r.length>1?(n=[e,e,"",t],i.setFilters.hasOwnProperty(e.toLowerCase())?at(function(e,n){var i,o=r(e,t),s=o.length;while(s--)i=P.call(e,o[s]),e[i]=!(n[i]=o[s])}):function(e){return r(e,0,n)}):r}},pseudos:{not:at(function(e){var t=[],n=[],r=a(e.replace(z,"$1"));return r[v]?at(function(e,t,n,i){var o,s=r(e,null,i,[]),a=e.length;while(a--)(o=s[a])&&(e[a]=!(t[a]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),!n.pop()}}),has:at(function(e){return function(t){return ot(e,t).length>0}}),contains:at(function(e){return function(t){return(t.textContent||t.innerText||o(t)).indexOf(e)>-1}}),lang:at(function(e){return G.test(e||"")||ot.error("unsupported lang: "+e),e=e.replace(nt,rt).toLowerCase(),function(t){var n;do if(n=h?t.lang:t.getAttribute("xml:lang")||t.getAttribute("lang"))return n=n.toLowerCase(),n===e||0===n.indexOf(e+"-");while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===f},focus:function(e){return e===p.activeElement&&(!p.hasFocus||p.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeName>"@"||3===e.nodeType||4===e.nodeType)return!1;return!0},parent:function(e){return!i.pseudos.empty(e)},header:function(e){return et.test(e.nodeName)},input:function(e){return Z.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||t.toLowerCase()===e.type)},first:ht(function(){return[0]}),last:ht(function(e,t){return[t-1]}),eq:ht(function(e,t,n){return[0>n?n+t:n]}),even:ht(function(e,t){var n=0;for(;t>n;n+=2)e.push(n);return e}),odd:ht(function(e,t){var n=1;for(;t>n;n+=2)e.push(n);return e}),lt:ht(function(e,t,n){var r=0>n?n+t:n;for(;--r>=0;)e.push(r);return e}),gt:ht(function(e,t,n){var r=0>n?n+t:n;for(;t>++r;)e.push(r);return e})}},i.pseudos.nth=i.pseudos.eq;for(t in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})i.pseudos[t]=pt(t);for(t in{submit:!0,reset:!0})i.pseudos[t]=ft(t);function dt(){}dt.prototype=i.filters=i.pseudos,i.setFilters=new dt;function gt(e,t){var n,r,o,s,a,u,l,c=k[e+" "];if(c)return t?0:c.slice(0);a=e,u=[],l=i.preFilter;while(a){(!n||(r=_.exec(a)))&&(r&&(a=a.slice(r[0].length)||a),u.push(o=[])),n=!1,(r=X.exec(a))&&(n=r.shift(),o.push({value:n,type:r[0].replace(z," ")}),a=a.slice(n.length));for(s in i.filter)!(r=J[s].exec(a))||l[s]&&!(r=l[s](r))||(n=r.shift(),o.push({value:n,type:s,matches:r}),a=a.slice(n.length));if(!n)break}return t?a.length:a?ot.error(e):k(e,u).slice(0)}function mt(e){var t=0,n=e.length,r="";for(;n>t;t++)r+=e[t].value;return r}function yt(e,t,n){var i=t.dir,o=n&&"parentNode"===i,s=T++;return t.first?function(t,n,r){while(t=t[i])if(1===t.nodeType||o)return e(t,n,r)}:function(t,n,a){var u,l,c,p=w+" "+s;if(a){while(t=t[i])if((1===t.nodeType||o)&&e(t,n,a))return!0}else while(t=t[i])if(1===t.nodeType||o)if(c=t[v]||(t[v]={}),(l=c[i])&&l[0]===p){if((u=l[1])===!0||u===r)return u===!0}else if(l=c[i]=[p],l[1]=e(t,n,a)||r,l[1]===!0)return!0}}function vt(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function xt(e,t,n,r,i){var o,s=[],a=0,u=e.length,l=null!=t;for(;u>a;a++)(o=e[a])&&(!n||n(o,r,i))&&(s.push(o),l&&t.push(a));return s}function bt(e,t,n,r,i,o){return r&&!r[v]&&(r=bt(r)),i&&!i[v]&&(i=bt(i,o)),at(function(o,s,a,u){var l,c,p,f=[],h=[],d=s.length,g=o||Ct(t||"*",a.nodeType?[a]:a,[]),m=!e||!o&&t?g:xt(g,f,e,a,u),y=n?i||(o?e:d||r)?[]:s:m;if(n&&n(m,y,a,u),r){l=xt(y,h),r(l,[],a,u),c=l.length;while(c--)(p=l[c])&&(y[h[c]]=!(m[h[c]]=p))}if(o){if(i||e){if(i){l=[],c=y.length;while(c--)(p=y[c])&&l.push(m[c]=p);i(null,y=[],l,u)}c=y.length;while(c--)(p=y[c])&&(l=i?P.call(o,p):f[c])>-1&&(o[l]=!(s[l]=p))}}else y=xt(y===s?y.splice(d,y.length):y),i?i(null,s,y,u):O.apply(s,y)})}function wt(e){var t,n,r,o=e.length,s=i.relative[e[0].type],a=s||i.relative[" "],l=s?1:0,c=yt(function(e){return e===t},a,!0),p=yt(function(e){return P.call(t,e)>-1},a,!0),f=[function(e,n,r){return!s&&(r||n!==u)||((t=n).nodeType?c(e,n,r):p(e,n,r))}];for(;o>l;l++)if(n=i.relative[e[l].type])f=[yt(vt(f),n)];else{if(n=i.filter[e[l].type].apply(null,e[l].matches),n[v]){for(r=++l;o>r;r++)if(i.relative[e[r].type])break;return bt(l>1&&vt(f),l>1&&mt(e.slice(0,l-1).concat({value:" "===e[l-2].type?"*":""})).replace(z,"$1"),n,r>l&&wt(e.slice(l,r)),o>r&&wt(e=e.slice(r)),o>r&&mt(e))}f.push(n)}return vt(f)}function Tt(e,t){var n=0,o=t.length>0,s=e.length>0,a=function(a,l,c,f,h){var d,g,m,y=[],v=0,x="0",b=a&&[],T=null!=h,C=u,k=a||s&&i.find.TAG("*",h&&l.parentNode||l),N=w+=null==C?1:Math.random()||.1;for(T&&(u=l!==p&&l,r=n);null!=(d=k[x]);x++){if(s&&d){g=0;while(m=e[g++])if(m(d,l,c)){f.push(d);break}T&&(w=N,r=++n)}o&&((d=!m&&d)&&v--,a&&b.push(d))}if(v+=x,o&&x!==v){g=0;while(m=t[g++])m(b,y,l,c);if(a){if(v>0)while(x--)b[x]||y[x]||(y[x]=q.call(f));y=xt(y)}O.apply(f,y),T&&!a&&y.length>0&&v+t.length>1&&ot.uniqueSort(f)}return T&&(w=N,u=C),b};return o?at(a):a}a=ot.compile=function(e,t){var n,r=[],i=[],o=N[e+" "];if(!o){t||(t=gt(e)),n=t.length;while(n--)o=wt(t[n]),o[v]?r.push(o):i.push(o);o=N(e,Tt(i,r))}return o};function Ct(e,t,n){var r=0,i=t.length;for(;i>r;r++)ot(e,t[r],n);return n}function kt(e,t,r,o){var s,u,l,c,p,f=gt(e);if(!o&&1===f.length){if(u=f[0]=f[0].slice(0),u.length>2&&"ID"===(l=u[0]).type&&n.getById&&9===t.nodeType&&h&&i.relative[u[1].type]){if(t=(i.find.ID(l.matches[0].replace(nt,rt),t)||[])[0],!t)return r;e=e.slice(u.shift().value.length)}s=J.needsContext.test(e)?0:u.length;while(s--){if(l=u[s],i.relative[c=l.type])break;if((p=i.find[c])&&(o=p(l.matches[0].replace(nt,rt),U.test(u[0].type)&&t.parentNode||t))){if(u.splice(s,1),e=o.length&&mt(u),!e)return O.apply(r,o),r;break}}}return a(e,f)(o,t,!h,r,U.test(e)),r}n.sortStable=v.split("").sort(S).join("")===v,n.detectDuplicates=E,c(),n.sortDetached=ut(function(e){return 1&e.compareDocumentPosition(p.createElement("div"))}),ut(function(e){return e.innerHTML="","#"===e.firstChild.getAttribute("href")})||lt("type|href|height|width",function(e,t,n){return n?undefined:e.getAttribute(t,"type"===t.toLowerCase()?1:2)}),n.attributes&&ut(function(e){return e.innerHTML="",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||lt("value",function(e,t,n){return n||"input"!==e.nodeName.toLowerCase()?undefined:e.defaultValue}),ut(function(e){return null==e.getAttribute("disabled")})||lt(R,function(e,t,n){var r;return n?undefined:(r=e.getAttributeNode(t))&&r.specified?r.value:e[t]===!0?t.toLowerCase():null}),x.find=ot,x.expr=ot.selectors,x.expr[":"]=x.expr.pseudos,x.unique=ot.uniqueSort,x.text=ot.getText,x.isXMLDoc=ot.isXML,x.contains=ot.contains}(e);var D={};function A(e){var t=D[e]={};return x.each(e.match(w)||[],function(e,n){t[n]=!0}),t}x.Callbacks=function(e){e="string"==typeof e?D[e]||A(e):x.extend({},e);var t,n,r,i,o,s,a=[],u=!e.once&&[],l=function(p){for(t=e.memory&&p,n=!0,s=i||0,i=0,o=a.length,r=!0;a&&o>s;s++)if(a[s].apply(p[0],p[1])===!1&&e.stopOnFalse){t=!1;break}r=!1,a&&(u?u.length&&l(u.shift()):t?a=[]:c.disable())},c={add:function(){if(a){var n=a.length;(function s(t){x.each(t,function(t,n){var r=x.type(n);"function"===r?e.unique&&c.has(n)||a.push(n):n&&n.length&&"string"!==r&&s(n)})})(arguments),r?o=a.length:t&&(i=n,l(t))}return this},remove:function(){return a&&x.each(arguments,function(e,t){var n;while((n=x.inArray(t,a,n))>-1)a.splice(n,1),r&&(o>=n&&o--,s>=n&&s--)}),this},has:function(e){return e?x.inArray(e,a)>-1:!(!a||!a.length)},empty:function(){return a=[],o=0,this},disable:function(){return a=u=t=undefined,this},disabled:function(){return!a},lock:function(){return u=undefined,t||c.disable(),this},locked:function(){return!u},fireWith:function(e,t){return!a||n&&!u||(t=t||[],t=[e,t.slice?t.slice():t],r?u.push(t):l(t)),this},fire:function(){return c.fireWith(this,arguments),this},fired:function(){return!!n}};return c},x.extend({Deferred:function(e){var t=[["resolve","done",x.Callbacks("once memory"),"resolved"],["reject","fail",x.Callbacks("once memory"),"rejected"],["notify","progress",x.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return x.Deferred(function(n){x.each(t,function(t,o){var s=o[0],a=x.isFunction(e[t])&&e[t];i[o[1]](function(){var e=a&&a.apply(this,arguments);e&&x.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[s+"With"](this===r?n.promise():this,a?[e]:arguments)})}),e=null}).promise()},promise:function(e){return null!=e?x.extend(e,r):r}},i={};return r.pipe=r.then,x.each(t,function(e,o){var s=o[2],a=o[3];r[o[1]]=s.add,a&&s.add(function(){n=a},t[1^e][2].disable,t[2][2].lock),i[o[0]]=function(){return i[o[0]+"With"](this===i?r:this,arguments),this},i[o[0]+"With"]=s.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t=0,n=d.call(arguments),r=n.length,i=1!==r||e&&x.isFunction(e.promise)?r:0,o=1===i?e:x.Deferred(),s=function(e,t,n){return function(r){t[e]=this,n[e]=arguments.length>1?d.call(arguments):r,n===a?o.notifyWith(t,n):--i||o.resolveWith(t,n)}},a,u,l;if(r>1)for(a=Array(r),u=Array(r),l=Array(r);r>t;t++)n[t]&&x.isFunction(n[t].promise)?n[t].promise().done(s(t,l,n)).fail(o.reject).progress(s(t,u,a)):--i;return i||o.resolveWith(l,n),o.promise()}}),x.support=function(t){var n=o.createElement("input"),r=o.createDocumentFragment(),i=o.createElement("div"),s=o.createElement("select"),a=s.appendChild(o.createElement("option"));return n.type?(n.type="checkbox",t.checkOn=""!==n.value,t.optSelected=a.selected,t.reliableMarginRight=!0,t.boxSizingReliable=!0,t.pixelPosition=!1,n.checked=!0,t.noCloneChecked=n.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!a.disabled,n=o.createElement("input"),n.value="t",n.type="radio",t.radioValue="t"===n.value,n.setAttribute("checked","t"),n.setAttribute("name","t"),r.appendChild(n),t.checkClone=r.cloneNode(!0).cloneNode(!0).lastChild.checked,t.focusinBubbles="onfocusin"in e,i.style.backgroundClip="content-box",i.cloneNode(!0).style.backgroundClip="",t.clearCloneStyle="content-box"===i.style.backgroundClip,x(function(){var n,r,s="padding:0;margin:0;border:0;display:block;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box",a=o.getElementsByTagName("body")[0];a&&(n=o.createElement("div"),n.style.cssText="border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px",a.appendChild(n).appendChild(i),i.innerHTML="",i.style.cssText="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%",x.swap(a,null!=a.style.zoom?{zoom:1}:{},function(){t.boxSizing=4===i.offsetWidth}),e.getComputedStyle&&(t.pixelPosition="1%"!==(e.getComputedStyle(i,null)||{}).top,t.boxSizingReliable="4px"===(e.getComputedStyle(i,null)||{width:"4px"}).width,r=i.appendChild(o.createElement("div")),r.style.cssText=i.style.cssText=s,r.style.marginRight=r.style.width="0",i.style.width="1px",t.reliableMarginRight=!parseFloat((e.getComputedStyle(r,null)||{}).marginRight)),a.removeChild(n))}),t):t}({});var L,q,H=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,O=/([A-Z])/g;function F(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=x.expando+Math.random()}F.uid=1,F.accepts=function(e){return e.nodeType?1===e.nodeType||9===e.nodeType:!0},F.prototype={key:function(e){if(!F.accepts(e))return 0;var t={},n=e[this.expando];if(!n){n=F.uid++;try{t[this.expando]={value:n},Object.defineProperties(e,t)}catch(r){t[this.expando]=n,x.extend(e,t)}}return this.cache[n]||(this.cache[n]={}),n},set:function(e,t,n){var r,i=this.key(e),o=this.cache[i];if("string"==typeof t)o[t]=n;else if(x.isEmptyObject(o))x.extend(this.cache[i],t);else for(r in t)o[r]=t[r];return o},get:function(e,t){var n=this.cache[this.key(e)];return t===undefined?n:n[t]},access:function(e,t,n){var r;return t===undefined||t&&"string"==typeof t&&n===undefined?(r=this.get(e,t),r!==undefined?r:this.get(e,x.camelCase(t))):(this.set(e,t,n),n!==undefined?n:t)},remove:function(e,t){var n,r,i,o=this.key(e),s=this.cache[o];if(t===undefined)this.cache[o]={};else{x.isArray(t)?r=t.concat(t.map(x.camelCase)):(i=x.camelCase(t),t in s?r=[t,i]:(r=i,r=r in s?[r]:r.match(w)||[])),n=r.length;while(n--)delete s[r[n]]}},hasData:function(e){return!x.isEmptyObject(this.cache[e[this.expando]]||{})},discard:function(e){e[this.expando]&&delete this.cache[e[this.expando]]}},L=new F,q=new F,x.extend({acceptData:F.accepts,hasData:function(e){return L.hasData(e)||q.hasData(e)},data:function(e,t,n){return L.access(e,t,n)},removeData:function(e,t){L.remove(e,t)},_data:function(e,t,n){return q.access(e,t,n)},_removeData:function(e,t){q.remove(e,t)}}),x.fn.extend({data:function(e,t){var n,r,i=this[0],o=0,s=null;if(e===undefined){if(this.length&&(s=L.get(i),1===i.nodeType&&!q.get(i,"hasDataAttrs"))){for(n=i.attributes;n.length>o;o++)r=n[o].name,0===r.indexOf("data-")&&(r=x.camelCase(r.slice(5)),P(i,r,s[r]));q.set(i,"hasDataAttrs",!0)}return s}return"object"==typeof e?this.each(function(){L.set(this,e)}):x.access(this,function(t){var n,r=x.camelCase(e);if(i&&t===undefined){if(n=L.get(i,e),n!==undefined)return n;if(n=L.get(i,r),n!==undefined)return n;if(n=P(i,r,undefined),n!==undefined)return n}else this.each(function(){var n=L.get(this,r);L.set(this,r,t),-1!==e.indexOf("-")&&n!==undefined&&L.set(this,e,t)})},null,t,arguments.length>1,null,!0)},removeData:function(e){return this.each(function(){L.remove(this,e)})}});function P(e,t,n){var r;if(n===undefined&&1===e.nodeType)if(r="data-"+t.replace(O,"-$1").toLowerCase(),n=e.getAttribute(r),"string"==typeof n){try{n="true"===n?!0:"false"===n?!1:"null"===n?null:+n+""===n?+n:H.test(n)?JSON.parse(n):n}catch(i){}L.set(e,t,n)}else n=undefined;return n}x.extend({queue:function(e,t,n){var r;return e?(t=(t||"fx")+"queue",r=q.get(e,t),n&&(!r||x.isArray(n)?r=q.access(e,t,x.makeArray(n)):r.push(n)),r||[]):undefined},dequeue:function(e,t){t=t||"fx";var n=x.queue(e,t),r=n.length,i=n.shift(),o=x._queueHooks(e,t),s=function(){x.dequeue(e,t) 5 | };"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,s,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return q.get(e,n)||q.access(e,n,{empty:x.Callbacks("once memory").add(function(){q.remove(e,[t+"queue",n])})})}}),x.fn.extend({queue:function(e,t){var n=2;return"string"!=typeof e&&(t=e,e="fx",n--),n>arguments.length?x.queue(this[0],e):t===undefined?this:this.each(function(){var n=x.queue(this,e,t);x._queueHooks(this,e),"fx"===e&&"inprogress"!==n[0]&&x.dequeue(this,e)})},dequeue:function(e){return this.each(function(){x.dequeue(this,e)})},delay:function(e,t){return e=x.fx?x.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,t){var n,r=1,i=x.Deferred(),o=this,s=this.length,a=function(){--r||i.resolveWith(o,[o])};"string"!=typeof e&&(t=e,e=undefined),e=e||"fx";while(s--)n=q.get(o[s],e+"queueHooks"),n&&n.empty&&(r++,n.empty.add(a));return a(),i.promise(t)}});var R,M,W=/[\t\r\n\f]/g,$=/\r/g,B=/^(?:input|select|textarea|button)$/i;x.fn.extend({attr:function(e,t){return x.access(this,x.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){x.removeAttr(this,e)})},prop:function(e,t){return x.access(this,x.prop,e,t,arguments.length>1)},removeProp:function(e){return this.each(function(){delete this[x.propFix[e]||e]})},addClass:function(e){var t,n,r,i,o,s=0,a=this.length,u="string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).addClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];a>s;s++)if(n=this[s],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(W," "):" ")){o=0;while(i=t[o++])0>r.indexOf(" "+i+" ")&&(r+=i+" ");n.className=x.trim(r)}return this},removeClass:function(e){var t,n,r,i,o,s=0,a=this.length,u=0===arguments.length||"string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).removeClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];a>s;s++)if(n=this[s],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(W," "):"")){o=0;while(i=t[o++])while(r.indexOf(" "+i+" ")>=0)r=r.replace(" "+i+" "," ");n.className=e?x.trim(r):""}return this},toggleClass:function(e,t){var n=typeof e;return"boolean"==typeof t&&"string"===n?t?this.addClass(e):this.removeClass(e):x.isFunction(e)?this.each(function(n){x(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if("string"===n){var t,i=0,o=x(this),s=e.match(w)||[];while(t=s[i++])o.hasClass(t)?o.removeClass(t):o.addClass(t)}else(n===r||"boolean"===n)&&(this.className&&q.set(this,"__className__",this.className),this.className=this.className||e===!1?"":q.get(this,"__className__")||"")})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;r>n;n++)if(1===this[n].nodeType&&(" "+this[n].className+" ").replace(W," ").indexOf(t)>=0)return!0;return!1},val:function(e){var t,n,r,i=this[0];{if(arguments.length)return r=x.isFunction(e),this.each(function(n){var i;1===this.nodeType&&(i=r?e.call(this,n,x(this).val()):e,null==i?i="":"number"==typeof i?i+="":x.isArray(i)&&(i=x.map(i,function(e){return null==e?"":e+""})),t=x.valHooks[this.type]||x.valHooks[this.nodeName.toLowerCase()],t&&"set"in t&&t.set(this,i,"value")!==undefined||(this.value=i))});if(i)return t=x.valHooks[i.type]||x.valHooks[i.nodeName.toLowerCase()],t&&"get"in t&&(n=t.get(i,"value"))!==undefined?n:(n=i.value,"string"==typeof n?n.replace($,""):null==n?"":n)}}}),x.extend({valHooks:{option:{get:function(e){var t=e.attributes.value;return!t||t.specified?e.value:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,o="select-one"===e.type||0>i,s=o?null:[],a=o?i+1:r.length,u=0>i?a:o?i:0;for(;a>u;u++)if(n=r[u],!(!n.selected&&u!==i||(x.support.optDisabled?n.disabled:null!==n.getAttribute("disabled"))||n.parentNode.disabled&&x.nodeName(n.parentNode,"optgroup"))){if(t=x(n).val(),o)return t;s.push(t)}return s},set:function(e,t){var n,r,i=e.options,o=x.makeArray(t),s=i.length;while(s--)r=i[s],(r.selected=x.inArray(x(r).val(),o)>=0)&&(n=!0);return n||(e.selectedIndex=-1),o}}},attr:function(e,t,n){var i,o,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return typeof e.getAttribute===r?x.prop(e,t,n):(1===s&&x.isXMLDoc(e)||(t=t.toLowerCase(),i=x.attrHooks[t]||(x.expr.match.bool.test(t)?M:R)),n===undefined?i&&"get"in i&&null!==(o=i.get(e,t))?o:(o=x.find.attr(e,t),null==o?undefined:o):null!==n?i&&"set"in i&&(o=i.set(e,n,t))!==undefined?o:(e.setAttribute(t,n+""),n):(x.removeAttr(e,t),undefined))},removeAttr:function(e,t){var n,r,i=0,o=t&&t.match(w);if(o&&1===e.nodeType)while(n=o[i++])r=x.propFix[n]||n,x.expr.match.bool.test(n)&&(e[r]=!1),e.removeAttribute(n)},attrHooks:{type:{set:function(e,t){if(!x.support.radioValue&&"radio"===t&&x.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},propFix:{"for":"htmlFor","class":"className"},prop:function(e,t,n){var r,i,o,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return o=1!==s||!x.isXMLDoc(e),o&&(t=x.propFix[t]||t,i=x.propHooks[t]),n!==undefined?i&&"set"in i&&(r=i.set(e,n,t))!==undefined?r:e[t]=n:i&&"get"in i&&null!==(r=i.get(e,t))?r:e[t]},propHooks:{tabIndex:{get:function(e){return e.hasAttribute("tabindex")||B.test(e.nodeName)||e.href?e.tabIndex:-1}}}}),M={set:function(e,t,n){return t===!1?x.removeAttr(e,n):e.setAttribute(n,n),n}},x.each(x.expr.match.bool.source.match(/\w+/g),function(e,t){var n=x.expr.attrHandle[t]||x.find.attr;x.expr.attrHandle[t]=function(e,t,r){var i=x.expr.attrHandle[t],o=r?undefined:(x.expr.attrHandle[t]=undefined)!=n(e,t,r)?t.toLowerCase():null;return x.expr.attrHandle[t]=i,o}}),x.support.optSelected||(x.propHooks.selected={get:function(e){var t=e.parentNode;return t&&t.parentNode&&t.parentNode.selectedIndex,null}}),x.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){x.propFix[this.toLowerCase()]=this}),x.each(["radio","checkbox"],function(){x.valHooks[this]={set:function(e,t){return x.isArray(t)?e.checked=x.inArray(x(e).val(),t)>=0:undefined}},x.support.checkOn||(x.valHooks[this].get=function(e){return null===e.getAttribute("value")?"on":e.value})});var I=/^key/,z=/^(?:mouse|contextmenu)|click/,_=/^(?:focusinfocus|focusoutblur)$/,X=/^([^.]*)(?:\.(.+)|)$/;function U(){return!0}function Y(){return!1}function V(){try{return o.activeElement}catch(e){}}x.event={global:{},add:function(e,t,n,i,o){var s,a,u,l,c,p,f,h,d,g,m,y=q.get(e);if(y){n.handler&&(s=n,n=s.handler,o=s.selector),n.guid||(n.guid=x.guid++),(l=y.events)||(l=y.events={}),(a=y.handle)||(a=y.handle=function(e){return typeof x===r||e&&x.event.triggered===e.type?undefined:x.event.dispatch.apply(a.elem,arguments)},a.elem=e),t=(t||"").match(w)||[""],c=t.length;while(c--)u=X.exec(t[c])||[],d=m=u[1],g=(u[2]||"").split(".").sort(),d&&(f=x.event.special[d]||{},d=(o?f.delegateType:f.bindType)||d,f=x.event.special[d]||{},p=x.extend({type:d,origType:m,data:i,handler:n,guid:n.guid,selector:o,needsContext:o&&x.expr.match.needsContext.test(o),namespace:g.join(".")},s),(h=l[d])||(h=l[d]=[],h.delegateCount=0,f.setup&&f.setup.call(e,i,g,a)!==!1||e.addEventListener&&e.addEventListener(d,a,!1)),f.add&&(f.add.call(e,p),p.handler.guid||(p.handler.guid=n.guid)),o?h.splice(h.delegateCount++,0,p):h.push(p),x.event.global[d]=!0);e=null}},remove:function(e,t,n,r,i){var o,s,a,u,l,c,p,f,h,d,g,m=q.hasData(e)&&q.get(e);if(m&&(u=m.events)){t=(t||"").match(w)||[""],l=t.length;while(l--)if(a=X.exec(t[l])||[],h=g=a[1],d=(a[2]||"").split(".").sort(),h){p=x.event.special[h]||{},h=(r?p.delegateType:p.bindType)||h,f=u[h]||[],a=a[2]&&RegExp("(^|\\.)"+d.join("\\.(?:.*\\.|)")+"(\\.|$)"),s=o=f.length;while(o--)c=f[o],!i&&g!==c.origType||n&&n.guid!==c.guid||a&&!a.test(c.namespace)||r&&r!==c.selector&&("**"!==r||!c.selector)||(f.splice(o,1),c.selector&&f.delegateCount--,p.remove&&p.remove.call(e,c));s&&!f.length&&(p.teardown&&p.teardown.call(e,d,m.handle)!==!1||x.removeEvent(e,h,m.handle),delete u[h])}else for(h in u)x.event.remove(e,h+t[l],n,r,!0);x.isEmptyObject(u)&&(delete m.handle,q.remove(e,"events"))}},trigger:function(t,n,r,i){var s,a,u,l,c,p,f,h=[r||o],d=y.call(t,"type")?t.type:t,g=y.call(t,"namespace")?t.namespace.split("."):[];if(a=u=r=r||o,3!==r.nodeType&&8!==r.nodeType&&!_.test(d+x.event.triggered)&&(d.indexOf(".")>=0&&(g=d.split("."),d=g.shift(),g.sort()),c=0>d.indexOf(":")&&"on"+d,t=t[x.expando]?t:new x.Event(d,"object"==typeof t&&t),t.isTrigger=i?2:3,t.namespace=g.join("."),t.namespace_re=t.namespace?RegExp("(^|\\.)"+g.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,t.result=undefined,t.target||(t.target=r),n=null==n?[t]:x.makeArray(n,[t]),f=x.event.special[d]||{},i||!f.trigger||f.trigger.apply(r,n)!==!1)){if(!i&&!f.noBubble&&!x.isWindow(r)){for(l=f.delegateType||d,_.test(l+d)||(a=a.parentNode);a;a=a.parentNode)h.push(a),u=a;u===(r.ownerDocument||o)&&h.push(u.defaultView||u.parentWindow||e)}s=0;while((a=h[s++])&&!t.isPropagationStopped())t.type=s>1?l:f.bindType||d,p=(q.get(a,"events")||{})[t.type]&&q.get(a,"handle"),p&&p.apply(a,n),p=c&&a[c],p&&x.acceptData(a)&&p.apply&&p.apply(a,n)===!1&&t.preventDefault();return t.type=d,i||t.isDefaultPrevented()||f._default&&f._default.apply(h.pop(),n)!==!1||!x.acceptData(r)||c&&x.isFunction(r[d])&&!x.isWindow(r)&&(u=r[c],u&&(r[c]=null),x.event.triggered=d,r[d](),x.event.triggered=undefined,u&&(r[c]=u)),t.result}},dispatch:function(e){e=x.event.fix(e);var t,n,r,i,o,s=[],a=d.call(arguments),u=(q.get(this,"events")||{})[e.type]||[],l=x.event.special[e.type]||{};if(a[0]=e,e.delegateTarget=this,!l.preDispatch||l.preDispatch.call(this,e)!==!1){s=x.event.handlers.call(this,e,u),t=0;while((i=s[t++])&&!e.isPropagationStopped()){e.currentTarget=i.elem,n=0;while((o=i.handlers[n++])&&!e.isImmediatePropagationStopped())(!e.namespace_re||e.namespace_re.test(o.namespace))&&(e.handleObj=o,e.data=o.data,r=((x.event.special[o.origType]||{}).handle||o.handler).apply(i.elem,a),r!==undefined&&(e.result=r)===!1&&(e.preventDefault(),e.stopPropagation()))}return l.postDispatch&&l.postDispatch.call(this,e),e.result}},handlers:function(e,t){var n,r,i,o,s=[],a=t.delegateCount,u=e.target;if(a&&u.nodeType&&(!e.button||"click"!==e.type))for(;u!==this;u=u.parentNode||this)if(u.disabled!==!0||"click"!==e.type){for(r=[],n=0;a>n;n++)o=t[n],i=o.selector+" ",r[i]===undefined&&(r[i]=o.needsContext?x(i,this).index(u)>=0:x.find(i,this,null,[u]).length),r[i]&&r.push(o);r.length&&s.push({elem:u,handlers:r})}return t.length>a&&s.push({elem:this,handlers:t.slice(a)}),s},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return null==e.which&&(e.which=null!=t.charCode?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,t){var n,r,i,s=t.button;return null==e.pageX&&null!=t.clientX&&(n=e.target.ownerDocument||o,r=n.documentElement,i=n.body,e.pageX=t.clientX+(r&&r.scrollLeft||i&&i.scrollLeft||0)-(r&&r.clientLeft||i&&i.clientLeft||0),e.pageY=t.clientY+(r&&r.scrollTop||i&&i.scrollTop||0)-(r&&r.clientTop||i&&i.clientTop||0)),e.which||s===undefined||(e.which=1&s?1:2&s?3:4&s?2:0),e}},fix:function(e){if(e[x.expando])return e;var t,n,r,i=e.type,s=e,a=this.fixHooks[i];a||(this.fixHooks[i]=a=z.test(i)?this.mouseHooks:I.test(i)?this.keyHooks:{}),r=a.props?this.props.concat(a.props):this.props,e=new x.Event(s),t=r.length;while(t--)n=r[t],e[n]=s[n];return e.target||(e.target=o),3===e.target.nodeType&&(e.target=e.target.parentNode),a.filter?a.filter(e,s):e},special:{load:{noBubble:!0},focus:{trigger:function(){return this!==V()&&this.focus?(this.focus(),!1):undefined},delegateType:"focusin"},blur:{trigger:function(){return this===V()&&this.blur?(this.blur(),!1):undefined},delegateType:"focusout"},click:{trigger:function(){return"checkbox"===this.type&&this.click&&x.nodeName(this,"input")?(this.click(),!1):undefined},_default:function(e){return x.nodeName(e.target,"a")}},beforeunload:{postDispatch:function(e){e.result!==undefined&&(e.originalEvent.returnValue=e.result)}}},simulate:function(e,t,n,r){var i=x.extend(new x.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?x.event.trigger(i,null,t):x.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},x.removeEvent=function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)},x.Event=function(e,t){return this instanceof x.Event?(e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.getPreventDefault&&e.getPreventDefault()?U:Y):this.type=e,t&&x.extend(this,t),this.timeStamp=e&&e.timeStamp||x.now(),this[x.expando]=!0,undefined):new x.Event(e,t)},x.Event.prototype={isDefaultPrevented:Y,isPropagationStopped:Y,isImmediatePropagationStopped:Y,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=U,e&&e.preventDefault&&e.preventDefault()},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=U,e&&e.stopPropagation&&e.stopPropagation()},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=U,this.stopPropagation()}},x.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){x.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,o=e.handleObj;return(!i||i!==r&&!x.contains(r,i))&&(e.type=o.origType,n=o.handler.apply(this,arguments),e.type=t),n}}}),x.support.focusinBubbles||x.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){x.event.simulate(t,e.target,x.event.fix(e),!0)};x.event.special[t]={setup:function(){0===n++&&o.addEventListener(e,r,!0)},teardown:function(){0===--n&&o.removeEventListener(e,r,!0)}}}),x.fn.extend({on:function(e,t,n,r,i){var o,s;if("object"==typeof e){"string"!=typeof t&&(n=n||t,t=undefined);for(s in e)this.on(s,t,n,e[s],i);return this}if(null==n&&null==r?(r=t,n=t=undefined):null==r&&("string"==typeof t?(r=n,n=undefined):(r=n,n=t,t=undefined)),r===!1)r=Y;else if(!r)return this;return 1===i&&(o=r,r=function(e){return x().off(e),o.apply(this,arguments)},r.guid=o.guid||(o.guid=x.guid++)),this.each(function(){x.event.add(this,e,r,n,t)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,t,n){var r,i;if(e&&e.preventDefault&&e.handleObj)return r=e.handleObj,x(e.delegateTarget).off(r.namespace?r.origType+"."+r.namespace:r.origType,r.selector,r.handler),this;if("object"==typeof e){for(i in e)this.off(i,t,e[i]);return this}return(t===!1||"function"==typeof t)&&(n=t,t=undefined),n===!1&&(n=Y),this.each(function(){x.event.remove(this,e,n,t)})},trigger:function(e,t){return this.each(function(){x.event.trigger(e,t,this)})},triggerHandler:function(e,t){var n=this[0];return n?x.event.trigger(e,t,n,!0):undefined}});var G=/^.[^:#\[\.,]*$/,J=/^(?:parents|prev(?:Until|All))/,Q=x.expr.match.needsContext,K={children:!0,contents:!0,next:!0,prev:!0};x.fn.extend({find:function(e){var t,n=[],r=this,i=r.length;if("string"!=typeof e)return this.pushStack(x(e).filter(function(){for(t=0;i>t;t++)if(x.contains(r[t],this))return!0}));for(t=0;i>t;t++)x.find(e,r[t],n);return n=this.pushStack(i>1?x.unique(n):n),n.selector=this.selector?this.selector+" "+e:e,n},has:function(e){var t=x(e,this),n=t.length;return this.filter(function(){var e=0;for(;n>e;e++)if(x.contains(this,t[e]))return!0})},not:function(e){return this.pushStack(et(this,e||[],!0))},filter:function(e){return this.pushStack(et(this,e||[],!1))},is:function(e){return!!et(this,"string"==typeof e&&Q.test(e)?x(e):e||[],!1).length},closest:function(e,t){var n,r=0,i=this.length,o=[],s=Q.test(e)||"string"!=typeof e?x(e,t||this.context):0;for(;i>r;r++)for(n=this[r];n&&n!==t;n=n.parentNode)if(11>n.nodeType&&(s?s.index(n)>-1:1===n.nodeType&&x.find.matchesSelector(n,e))){n=o.push(n);break}return this.pushStack(o.length>1?x.unique(o):o)},index:function(e){return e?"string"==typeof e?g.call(x(e),this[0]):g.call(this,e.jquery?e[0]:e):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){var n="string"==typeof e?x(e,t):x.makeArray(e&&e.nodeType?[e]:e),r=x.merge(this.get(),n);return this.pushStack(x.unique(r))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}});function Z(e,t){while((e=e[t])&&1!==e.nodeType);return e}x.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return x.dir(e,"parentNode")},parentsUntil:function(e,t,n){return x.dir(e,"parentNode",n)},next:function(e){return Z(e,"nextSibling")},prev:function(e){return Z(e,"previousSibling")},nextAll:function(e){return x.dir(e,"nextSibling")},prevAll:function(e){return x.dir(e,"previousSibling")},nextUntil:function(e,t,n){return x.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return x.dir(e,"previousSibling",n)},siblings:function(e){return x.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return x.sibling(e.firstChild)},contents:function(e){return e.contentDocument||x.merge([],e.childNodes)}},function(e,t){x.fn[e]=function(n,r){var i=x.map(this,t,n);return"Until"!==e.slice(-5)&&(r=n),r&&"string"==typeof r&&(i=x.filter(r,i)),this.length>1&&(K[e]||x.unique(i),J.test(e)&&i.reverse()),this.pushStack(i)}}),x.extend({filter:function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?x.find.matchesSelector(r,e)?[r]:[]:x.find.matches(e,x.grep(t,function(e){return 1===e.nodeType}))},dir:function(e,t,n){var r=[],i=n!==undefined;while((e=e[t])&&9!==e.nodeType)if(1===e.nodeType){if(i&&x(e).is(n))break;r.push(e)}return r},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}});function et(e,t,n){if(x.isFunction(t))return x.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return x.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(G.test(t))return x.filter(t,e,n);t=x.filter(t,e)}return x.grep(e,function(e){return g.call(t,e)>=0!==n})}var tt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,nt=/<([\w:]+)/,rt=/<|&#?\w+;/,it=/<(?:script|style|link)/i,ot=/^(?:checkbox|radio)$/i,st=/checked\s*(?:[^=]|=\s*.checked.)/i,at=/^$|\/(?:java|ecma)script/i,ut=/^true\/(.*)/,lt=/^\s*\s*$/g,ct={option:[1,""],thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};ct.optgroup=ct.option,ct.tbody=ct.tfoot=ct.colgroup=ct.caption=ct.thead,ct.th=ct.td,x.fn.extend({text:function(e){return x.access(this,function(e){return e===undefined?x.text(this):this.empty().append((this[0]&&this[0].ownerDocument||o).createTextNode(e))},null,e,arguments.length)},append:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=pt(this,e);t.appendChild(e)}})},prepend:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=pt(this,e);t.insertBefore(e,t.firstChild)}})},before:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},remove:function(e,t){var n,r=e?x.filter(e,this):this,i=0;for(;null!=(n=r[i]);i++)t||1!==n.nodeType||x.cleanData(mt(n)),n.parentNode&&(t&&x.contains(n.ownerDocument,n)&&dt(mt(n,"script")),n.parentNode.removeChild(n));return this},empty:function(){var e,t=0;for(;null!=(e=this[t]);t++)1===e.nodeType&&(x.cleanData(mt(e,!1)),e.textContent="");return this},clone:function(e,t){return e=null==e?!1:e,t=null==t?e:t,this.map(function(){return x.clone(this,e,t)})},html:function(e){return x.access(this,function(e){var t=this[0]||{},n=0,r=this.length;if(e===undefined&&1===t.nodeType)return t.innerHTML;if("string"==typeof e&&!it.test(e)&&!ct[(nt.exec(e)||["",""])[1].toLowerCase()]){e=e.replace(tt,"<$1>");try{for(;r>n;n++)t=this[n]||{},1===t.nodeType&&(x.cleanData(mt(t,!1)),t.innerHTML=e);t=0}catch(i){}}t&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(){var e=x.map(this,function(e){return[e.nextSibling,e.parentNode]}),t=0;return this.domManip(arguments,function(n){var r=e[t++],i=e[t++];i&&(r&&r.parentNode!==i&&(r=this.nextSibling),x(this).remove(),i.insertBefore(n,r))},!0),t?this:this.remove()},detach:function(e){return this.remove(e,!0)},domManip:function(e,t,n){e=f.apply([],e);var r,i,o,s,a,u,l=0,c=this.length,p=this,h=c-1,d=e[0],g=x.isFunction(d);if(g||!(1>=c||"string"!=typeof d||x.support.checkClone)&&st.test(d))return this.each(function(r){var i=p.eq(r);g&&(e[0]=d.call(this,r,i.html())),i.domManip(e,t,n)});if(c&&(r=x.buildFragment(e,this[0].ownerDocument,!1,!n&&this),i=r.firstChild,1===r.childNodes.length&&(r=i),i)){for(o=x.map(mt(r,"script"),ft),s=o.length;c>l;l++)a=r,l!==h&&(a=x.clone(a,!0,!0),s&&x.merge(o,mt(a,"script"))),t.call(this[l],a,l);if(s)for(u=o[o.length-1].ownerDocument,x.map(o,ht),l=0;s>l;l++)a=o[l],at.test(a.type||"")&&!q.access(a,"globalEval")&&x.contains(u,a)&&(a.src?x._evalUrl(a.src):x.globalEval(a.textContent.replace(lt,"")))}return this}}),x.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){x.fn[e]=function(e){var n,r=[],i=x(e),o=i.length-1,s=0;for(;o>=s;s++)n=s===o?this:this.clone(!0),x(i[s])[t](n),h.apply(r,n.get());return this.pushStack(r)}}),x.extend({clone:function(e,t,n){var r,i,o,s,a=e.cloneNode(!0),u=x.contains(e.ownerDocument,e);if(!(x.support.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||x.isXMLDoc(e)))for(s=mt(a),o=mt(e),r=0,i=o.length;i>r;r++)yt(o[r],s[r]);if(t)if(n)for(o=o||mt(e),s=s||mt(a),r=0,i=o.length;i>r;r++)gt(o[r],s[r]);else gt(e,a);return s=mt(a,"script"),s.length>0&&dt(s,!u&&mt(e,"script")),a},buildFragment:function(e,t,n,r){var i,o,s,a,u,l,c=0,p=e.length,f=t.createDocumentFragment(),h=[];for(;p>c;c++)if(i=e[c],i||0===i)if("object"===x.type(i))x.merge(h,i.nodeType?[i]:i);else if(rt.test(i)){o=o||f.appendChild(t.createElement("div")),s=(nt.exec(i)||["",""])[1].toLowerCase(),a=ct[s]||ct._default,o.innerHTML=a[1]+i.replace(tt,"<$1>")+a[2],l=a[0];while(l--)o=o.lastChild;x.merge(h,o.childNodes),o=f.firstChild,o.textContent=""}else h.push(t.createTextNode(i));f.textContent="",c=0;while(i=h[c++])if((!r||-1===x.inArray(i,r))&&(u=x.contains(i.ownerDocument,i),o=mt(f.appendChild(i),"script"),u&&dt(o),n)){l=0;while(i=o[l++])at.test(i.type||"")&&n.push(i)}return f},cleanData:function(e){var t,n,r,i,o,s,a=x.event.special,u=0;for(;(n=e[u])!==undefined;u++){if(F.accepts(n)&&(o=n[q.expando],o&&(t=q.cache[o]))){if(r=Object.keys(t.events||{}),r.length)for(s=0;(i=r[s])!==undefined;s++)a[i]?x.event.remove(n,i):x.removeEvent(n,i,t.handle);q.cache[o]&&delete q.cache[o]}delete L.cache[n[L.expando]]}},_evalUrl:function(e){return x.ajax({url:e,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})}});function pt(e,t){return x.nodeName(e,"table")&&x.nodeName(1===t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function ft(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function ht(e){var t=ut.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function dt(e,t){var n=e.length,r=0;for(;n>r;r++)q.set(e[r],"globalEval",!t||q.get(t[r],"globalEval"))}function gt(e,t){var n,r,i,o,s,a,u,l;if(1===t.nodeType){if(q.hasData(e)&&(o=q.access(e),s=q.set(t,o),l=o.events)){delete s.handle,s.events={};for(i in l)for(n=0,r=l[i].length;r>n;n++)x.event.add(t,i,l[i][n])}L.hasData(e)&&(a=L.access(e),u=x.extend({},a),L.set(t,u))}}function mt(e,t){var n=e.getElementsByTagName?e.getElementsByTagName(t||"*"):e.querySelectorAll?e.querySelectorAll(t||"*"):[];return t===undefined||t&&x.nodeName(e,t)?x.merge([e],n):n}function yt(e,t){var n=t.nodeName.toLowerCase();"input"===n&&ot.test(e.type)?t.checked=e.checked:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}x.fn.extend({wrapAll:function(e){var t;return x.isFunction(e)?this.each(function(t){x(this).wrapAll(e.call(this,t))}):(this[0]&&(t=x(e,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstElementChild)e=e.firstElementChild;return e}).append(this)),this)},wrapInner:function(e){return x.isFunction(e)?this.each(function(t){x(this).wrapInner(e.call(this,t))}):this.each(function(){var t=x(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=x.isFunction(e);return this.each(function(n){x(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){x.nodeName(this,"body")||x(this).replaceWith(this.childNodes)}).end()}});var vt,xt,bt=/^(none|table(?!-c[ea]).+)/,wt=/^margin/,Tt=RegExp("^("+b+")(.*)$","i"),Ct=RegExp("^("+b+")(?!px)[a-z%]+$","i"),kt=RegExp("^([+-])=("+b+")","i"),Nt={BODY:"block"},Et={position:"absolute",visibility:"hidden",display:"block"},St={letterSpacing:0,fontWeight:400},jt=["Top","Right","Bottom","Left"],Dt=["Webkit","O","Moz","ms"];function At(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=Dt.length;while(i--)if(t=Dt[i]+n,t in e)return t;return r}function Lt(e,t){return e=t||e,"none"===x.css(e,"display")||!x.contains(e.ownerDocument,e)}function qt(t){return e.getComputedStyle(t,null)}function Ht(e,t){var n,r,i,o=[],s=0,a=e.length;for(;a>s;s++)r=e[s],r.style&&(o[s]=q.get(r,"olddisplay"),n=r.style.display,t?(o[s]||"none"!==n||(r.style.display=""),""===r.style.display&&Lt(r)&&(o[s]=q.access(r,"olddisplay",Rt(r.nodeName)))):o[s]||(i=Lt(r),(n&&"none"!==n||!i)&&q.set(r,"olddisplay",i?n:x.css(r,"display"))));for(s=0;a>s;s++)r=e[s],r.style&&(t&&"none"!==r.style.display&&""!==r.style.display||(r.style.display=t?o[s]||"":"none"));return e}x.fn.extend({css:function(e,t){return x.access(this,function(e,t,n){var r,i,o={},s=0;if(x.isArray(t)){for(r=qt(e),i=t.length;i>s;s++)o[t[s]]=x.css(e,t[s],!1,r);return o}return n!==undefined?x.style(e,t,n):x.css(e,t)},e,t,arguments.length>1)},show:function(){return Ht(this,!0)},hide:function(){return Ht(this)},toggle:function(e){return"boolean"==typeof e?e?this.show():this.hide():this.each(function(){Lt(this)?x(this).show():x(this).hide()})}}),x.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=vt(e,"opacity");return""===n?"1":n}}}},cssNumber:{columnCount:!0,fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":"cssFloat"},style:function(e,t,n,r){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var i,o,s,a=x.camelCase(t),u=e.style;return t=x.cssProps[a]||(x.cssProps[a]=At(u,a)),s=x.cssHooks[t]||x.cssHooks[a],n===undefined?s&&"get"in s&&(i=s.get(e,!1,r))!==undefined?i:u[t]:(o=typeof n,"string"===o&&(i=kt.exec(n))&&(n=(i[1]+1)*i[2]+parseFloat(x.css(e,t)),o="number"),null==n||"number"===o&&isNaN(n)||("number"!==o||x.cssNumber[a]||(n+="px"),x.support.clearCloneStyle||""!==n||0!==t.indexOf("background")||(u[t]="inherit"),s&&"set"in s&&(n=s.set(e,n,r))===undefined||(u[t]=n)),undefined)}},css:function(e,t,n,r){var i,o,s,a=x.camelCase(t);return t=x.cssProps[a]||(x.cssProps[a]=At(e.style,a)),s=x.cssHooks[t]||x.cssHooks[a],s&&"get"in s&&(i=s.get(e,!0,n)),i===undefined&&(i=vt(e,t,r)),"normal"===i&&t in St&&(i=St[t]),""===n||n?(o=parseFloat(i),n===!0||x.isNumeric(o)?o||0:i):i}}),vt=function(e,t,n){var r,i,o,s=n||qt(e),a=s?s.getPropertyValue(t)||s[t]:undefined,u=e.style;return s&&(""!==a||x.contains(e.ownerDocument,e)||(a=x.style(e,t)),Ct.test(a)&&wt.test(t)&&(r=u.width,i=u.minWidth,o=u.maxWidth,u.minWidth=u.maxWidth=u.width=a,a=s.width,u.width=r,u.minWidth=i,u.maxWidth=o)),a};function Ot(e,t,n){var r=Tt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function Ft(e,t,n,r,i){var o=n===(r?"border":"content")?4:"width"===t?1:0,s=0;for(;4>o;o+=2)"margin"===n&&(s+=x.css(e,n+jt[o],!0,i)),r?("content"===n&&(s-=x.css(e,"padding"+jt[o],!0,i)),"margin"!==n&&(s-=x.css(e,"border"+jt[o]+"Width",!0,i))):(s+=x.css(e,"padding"+jt[o],!0,i),"padding"!==n&&(s+=x.css(e,"border"+jt[o]+"Width",!0,i)));return s}function Pt(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=qt(e),s=x.support.boxSizing&&"border-box"===x.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=vt(e,t,o),(0>i||null==i)&&(i=e.style[t]),Ct.test(i))return i;r=s&&(x.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+Ft(e,t,n||(s?"border":"content"),r,o)+"px"}function Rt(e){var t=o,n=Nt[e];return n||(n=Mt(e,t),"none"!==n&&n||(xt=(xt||x("