summaryrefslogtreecommitdiff
path: root/js/matrix.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-12-09 16:15:37 -0500
committerJules Laplace <jules@okfoc.us>2014-12-09 16:15:37 -0500
commitda3b3feedfe3a928dec6ac615579538a9ab5b582 (patch)
tree2b176b394b301e2d633372d70f6bc8743e317feb /js/matrix.js
parent6a16ad9c408fb84dd27c618312f3111563ca2ad5 (diff)
less-destructive resize; stub out selection
Diffstat (limited to 'js/matrix.js')
-rw-r--r--js/matrix.js65
1 files changed, 53 insertions, 12 deletions
diff --git a/js/matrix.js b/js/matrix.js
index fd4ee4f..79f3d9f 100644
--- a/js/matrix.js
+++ b/js/matrix.js
@@ -98,6 +98,59 @@ Matrix.prototype.getCell = function(x,y){
if (this.aa[y] && this.aa[y][x]) return this.aa[y][x]
else return null
}
+Matrix.prototype.resize = function(w,h){
+ var div, row, lex
+ var f = this.f, old_h = this.h, old_w = this.w
+ var rapper = this.rapper
+ w = max(w, 1)
+ h = max(h, 1)
+ if (h < old_h) {
+ for (var y = old_h; y > h; y--) {
+ row = this.aa.pop()
+ div = row[0].span.parentNode
+ row.forEach(function(lex, x){
+ lex.demolish()
+ })
+ div.parentNode.removeChild(div)
+ }
+ }
+ else if (h > old_h) {
+ for (var y = old_h; y < h; y++) {
+ div = document.createElement("div")
+ rapper.appendChild( div )
+ this.aa[y] = new Array (w)
+ for (var x = 0; x < w; x++) {
+ lex = this.aa[y][x] = f(x,y)
+ div.appendChild(lex.span)
+ }
+ }
+ }
+
+ if (w < old_w) {
+ this.aa.forEach(function(row, y){
+ while (row.length > w) {
+ lex = row.pop()
+ lex.demolish()
+ }
+ })
+ }
+ else if (w > old_w) {
+ this.aa.forEach(function(row, y){
+ div = row[0].span.parentNode
+ for (var x = row.length; x < w; x++) {
+ lex = row[x] = f(x,y)
+ div.appendChild(lex.span)
+ }
+ })
+ }
+
+ this.w = w
+ this.h = h
+ this.bind && this.bind()
+}
+
+//
+
Matrix.prototype.ascii = function () {
var lines = this.aa.map(function(row, y){
var last, line = ""
@@ -160,15 +213,3 @@ Matrix.prototype.irssi = function(){
}
return '/exec -out printf "' + escaped_txt + '"\n'
}
-Matrix.prototype.expand = function(i){
- var w = this.w = clamp(this.w+i, 1, 9), h = this.h = clamp(this.h+i, 1, 9)
- console.log(w,h)
- controls.width.char = ""+w
- controls.width.build()
- controls.height.char = ""+h
- controls.height.build()
- this.rebuild()
-}
-Matrix.prototype.contract = function(i){
- this.expand(-i)
-}