Browse Source

Use an event library

dev/git-series/gccdum
Matt Godbolt 6 years ago
parent
commit
d636ade95a
  1. 3
      bower.json
  2. 3
      static/main.js
  3. 15
      static/toggles.js

3
bower.json

@ -22,6 +22,7 @@
"golden-layout": "^1.5.1",
"jquery": "^3.1.0",
"bootstrap": "^3.3.7",
"selectize": "^0.12.2"
"selectize": "^0.12.2",
"eventEmitter": "^5.1.0"
}
}

3
static/main.js

@ -6,7 +6,8 @@ require.config({
goldenlayout: 'ext/golden-layout/dist/goldenlayout',
selectize: 'ext/selectize/dist/js/selectize.min',
sifter: 'ext/sifter/sifter.min',
microplugin: 'ext/microplugin/src/microplugin'
microplugin: 'ext/microplugin/src/microplugin',
events: 'ext/eventEmitter/EventEmitter'
},
packages: [{
name: "codemirror",

15
static/toggles.js

@ -2,6 +2,7 @@ define(function (require) {
"use strict";
var _ = require('underscore');
var $ = require('jquery');
var EventEmitter = require('events');
function get(domRoot) {
var result = {};
@ -12,8 +13,8 @@ define(function (require) {
}
function Toggles(root, state) {
EventEmitter.call(this);
this.domRoot = root;
this.changeHandlers = [];
state = state || this.get();
this.domRoot.find('.btn')
.click(_.bind(this.onClick, this))
@ -23,6 +24,8 @@ define(function (require) {
this.state = get(this.domRoot);
}
_.extend(Toggles.prototype, EventEmitter.prototype);
Toggles.prototype.get = function () {
return this.state;
};
@ -32,15 +35,7 @@ define(function (require) {
button.toggleClass('active');
var before = this.state;
var after = this.state = get(this.domRoot);
_.each(this.changeHandlers, function (f) {
f(before, after);
});
};
Toggles.prototype.on = function (event, handler, that) {
if (event === "change") {
this.changeHandlers.push(_.bind(handler, that));
}
this.emit('change', before, after);
};
return Toggles;

Loading…
Cancel
Save