-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
147 lines (121 loc) · 4.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
(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){
'use strict';
var wm = require('./windowManager');
function Isfahan(options) {
console.log(options);
}
Isfahan.prototype = {
};
module.exports = function(options) {
return new Isfahan(options);
};
},{"./windowManager":2}],2:[function(require,module,exports){
'use strict';
/* Constructs WindowManagers which offer an interface for
* manipulating Windows through Tilers. Interfaces with d3 for
* rendering/drawing.
*
* var wm = new Isfahan.WindowManager(...)
*/
var WindowManager = function(options) {
this.windows = {};
this.selectedWindow = options.selectedWindow || null;
// Tiler; manages layout
this.tiler = new _isfahan.Tiler({
bind: options.bind,
container: options.element,
layout: options.layout,
padding: options.padding
});
// Callbacks for window creation
this.onCreate = options.onCreate || function(window) {};
this.onUpdate = options.onUpdate || function(window) {};
this.onDelete = options.onDelete || function(window) {};
};
WindowManager.prototype = {
/* TODO: Returns a deep copy of this workspace's settings, but not
* its data. This is useful if you want to create a new empty
* workspace with the same configuration or settings as this one.
*/
clone: function() {},
/* TODO: Returns a shallow copy which is an exact replica of this
* workspace, including its nodes and data.
*/
copy: function() {},
/* Get a window by its DOM/d3 element id */
getWindow: function(id) { return this.windows[id]; },
/* Grep the tiler layout for node representing id */
getNode: function(id) { return this.tiler.getNode(id); },
/*
Changes focus to the specified Window or, the Window to the
`direction` ∈ ['l' | 'u' | 'r' | 'd'] of Window.
*/
select: function(window, direction) {
var _this = this;
var node = _this.getNode(window.id);
// XXX use window.neighbors
console.log('select this window')
},
/* Reset the window manager based on the initial layout and
* parameters */
reset: function() {
this.tiler.reset(); // resets tiler to default layout
this.render(); // performs tiler.prime()
},
render: function() {
var _this = this;
// tiler recalculates size + pos from current state of layout
_this.tiler.prime();
var data = _this.tiler.layout.filter(function(d) {
return !d.children;
});
// Data Join.
var divs = d3.select("#" + _this.element.attr('id'))
.selectAll(".layout-slot")
.data(data, function(d) { return d.id; });
// Update
// Implicitly updates the existing elements.
// Must come before the enter function.
divs.call(cell).each(function(d) {
_this.onUpdate(_this.getWindow(d.id));
});
// Enter
divs.enter().append("div")
.attr("class", "layout-slot")
.attr("data-layout-slot-id", function(d) { return d.id; })
.call(cell)
.each(function(d) {
var $container = jQuery(
_this.element.children('div')
.filter('[data-layout-slot-id="' + d.id + '"]')[0]
);
var window = new _this.Window({ id: d.id, container: $container });
_this.windows[d.id] = window;
_this.onCreate(window);
});
// Exit
divs.exit()
.remove("div")
.each(function(d) { _this.onDelete(); });
function cell() {
_this
.style("left", function(d) { return d.x + "px"; })
.style("top", function(d) { return d.y + "px"; })
.style("width", function(d) { return Math.max(0, d.dx ) + "px"; })
.style("height", function(d) { return Math.max(0, d.dy ) + "px"; });
}
},
/* Allows the WindowManager to react to browser events,
* e.g. resizing
*/
bindEvents: function() {
var _this = this;
d3.select(window).on('resize', function(event) {
_this.render();
});
}
};
module.exports = function(options) {
return new WindowManager(options);
};
},{}]},{},[1]);