(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
require("../third_party/jquery.cursor-position.js"),$.extend(KhanUtil,{matrixInput:{eventsAttached:!1,eventNamespace:"matrix-input",containerEl:null,bracketEls:null,cells:null,LEFT_ARROW:37,UP_ARROW:38,RIGHT_ARROW:39,DOWN_ARROW:40,ENTER_KEY:13,ROWS:3,COLS:3,maxRow:0,maxCol:0,contentMaxRow:0,contentMaxCol:0,init:function(){var t=this;this.initContainer();var n=$(".matrix-row .sol input[type='text']");this.cells=_.map(n,function(n,e){return{el:n,index:e,row:t.indexToRow(e),col:t.indexToCol(e),val:function(){return $.trim($(this.el).val())},clearVal:function(){$(this.el).val("")}}}),this.addBrackets(),this.bindInputEvents(),this.resetAllMaxVals(),this.render()},initContainer:function(){this.containerEl=$("#solutionarea .matrix-input"),this.containerEl[0]||(this.containerEl=$("#solutionarea").addClass("matrix-input"))},addBrackets:function(t){var n=$("<div>").addClass("matrix-bracket bracket-left"),e=$("<div>").addClass("matrix-bracket bracket-right");this.containerEl.prepend(n,e),this.bracketEls=[n,e]},removeBrackets:function(){_.each(this.bracketEls,function(t){$(t).remove()})},indexToRow:function(t){return Math.floor(t/this.COLS)},indexToCol:function(t){return t%this.COLS},coordToIndex:function(t,n){return this.COLS*t+n},bindInputEvents:function(){var t=this,n=!1;$("body").on("click."+t.eventNamespace,function(){n||(t.resetMaxToContentMax(),t.render()),n=!1}),_.each(this.cells,function(e){$(e.el).on({focus:function(n){t.setMaxVals(e),t.render()},blur:function(n){t.setMaxVals(e)},click:function(t){n=!0},keydown:function(n){var i,a=t.ROWS-1,o=t.cells.length-1,s=null;if(n.which===t.LEFT_ARROW){if(0===e.index||!$(this).isCursorFirst())return;s=e.index-1}else if(n.which===t.RIGHT_ARROW){if(e.index===o||!$(this).isCursorLast())return;s=e.index+1}else if(n.which===t.UP_ARROW){if(0===e.row)return;i=e.row-1,s=t.coordToIndex(i,e.col)}else if(n.which===t.DOWN_ARROW){if(e.row===a)return;i=e.row+1,s=t.coordToIndex(i,e.col)}else n.which===t.ENTER_KEY&&t.setMaxVals(e);null!==s&&($(t.cells[s].el).focus(),n.preventDefault())}})})},setContentMaxRow:function(t){this.contentMaxRow=Math.max(t,this.contentMaxRow)},setContentMaxCol:function(t){this.contentMaxCol=Math.max(t,this.contentMaxCol)},setMaxRow:function(t){this.maxRow=Math.max(t,this.contentMaxRow)},setMaxCol:function(t){this.maxCol=Math.max(t,this.contentMaxCol)},resetMaxToContentMax:function(){this.maxRow=this.contentMaxRow,this.maxCol=this.contentMaxCol},resetAllMaxVals:function(){this.maxRow=0,this.maxCol=0,this.contentMaxRow=0,this.contentMaxCol=0},setMaxValsFromScratch:function(){this.resetAllMaxVals();var t=this;_.each(this.cells,function(n){n.val()&&(t.setContentMaxRow(n.row),t.setContentMaxCol(n.col))}),this.resetMaxToContentMax()},setMaxVals:function(t){var n=t.val();n?(this.setContentMaxRow(t.row),this.setContentMaxCol(t.col)):(t.clearVal(),(this.contentMaxRow===t.row||this.contentMaxCol===t.col)&&this.setMaxValsFromScratch()),this.setMaxRow(t.row),this.setMaxCol(t.col)},positionBrackets:function(){var t=$(this.cells[0].el),n=this.bracketEls[0].width(),e=this.maxRow+1,i=this.maxCol+1,a=t.outerHeight(!0)*e,o=t.outerWidth(!0)*i-n;_.each(this.bracketEls,function(t){t.css({height:a})}),this.bracketEls[1].css({"margin-left":o})},render:function(){this.positionBrackets()},cleanup:function(){$("body").off("."+this.eventNamespace),this.removeBrackets()}}}),$.fn["matrix-inputLoad"]=function(){KhanUtil.matrixInput.eventsAttached||($(Exercises).on("newProblem.matrix-input",function(){KhanUtil.matrixInput.init()}),$(Khan).on("showGuess.matrix-input",function(){KhanUtil.matrixInput.setMaxValsFromScratch(),KhanUtil.matrixInput.render()}),KhanUtil.matrixInput.eventsAttached=!0)},$.fn["matrix-inputCleanup"]=function(){KhanUtil.matrixInput.eventsAttached&&(KhanUtil.matrixInput.cleanup(),$(Exercises).off("newProblem.matrix-input"),$(Khan).off("showGuess.matrix-input"),KhanUtil.matrixInput.eventsAttached=!1)};
},{"../third_party/jquery.cursor-position.js":2}],2:[function(require,module,exports){
!function(t){t.fn.getCursorPosition=function(){var e=t(this).get(0),n=0;if("selectionStart"in e)n=e.selectionStart;else if("selection"in document){e.focus();var r=document.selection.createRange(),i=document.selection.createRange().text.length;r.moveStart("character",-e.value.length),n=r.text.length-i}return n},t.fn.isCursorFirst=function(){var e=t(this).getCursorPosition();return 0===e},t.fn.isCursorLast=function(){var e=t(this).getCursorPosition(),n=t(this).val().length;return e===n}}(jQuery);
},{}]},{},[1]);
