Skip to content

Commit

Permalink
plugins can be directories
Browse files Browse the repository at this point in the history
  • Loading branch information
WardCunningham committed Apr 30, 2012
1 parent 2c2fe35 commit 3372b50
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 57 deletions.
28 changes: 8 additions & 20 deletions client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,17 +1082,22 @@ require.define("/lib/plugin.coffee", function (require, module, exports, __dirna
if (scripts[url] != null) {
return callback();
} else {
return $.getScript(url, function() {
return $.getScript(url).done(function() {
scripts[url] = true;
return callback();
}).fail(function() {
return callback();
});
}
};

plugin.get = wiki.getPlugin = function(name, callback) {
if (window.plugins[name]) return callback(window.plugins[name]);
return getScript("/plugins/" + name + ".js", function() {
return callback(window.plugins[name]);
return getScript("/plugins/" + name + "/" + name + ".js", function() {
if (window.plugins[name]) return callback(window.plugins[name]);
return getScript("/plugins/" + name + ".js", function() {
return callback(window.plugins[name]);
});
});
};

Expand Down Expand Up @@ -1149,23 +1154,6 @@ require.define("/lib/plugin.coffee", function (require, module, exports, __dirna
});
}
},
chart: {
emit: function(div, item) {
var captionElement, chartElement;
chartElement = $('<p />').addClass('readout').appendTo(div).text(item.data.last().last());
return captionElement = $('<p />').html(wiki.resolveLinks(item.caption)).appendTo(div);
},
bind: function(div, item) {
return div.find('p:first').mousemove(function(e) {
var sample, time, _ref;
_ref = item.data[Math.floor(item.data.length * e.offsetX / e.target.offsetWidth)], time = _ref[0], sample = _ref[1];
$(e.target).text(sample.toFixed(1));
return $(e.target).siblings("p").last().html(util.formatTime(time));
}).dblclick(function() {
return wiki.dialog("JSON for " + item.caption, $('<pre/>').text(JSON.stringify(item.data, null, 2)));
});
}
},
changes: {
emit: function(div, item) {
var a, i, key, ul, _ref, _results;
Expand Down
27 changes: 10 additions & 17 deletions client/lib/plugin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ getScript = wiki.getScript = (url, callback = () ->) ->
if scripts[url]?
callback()
else
$.getScript(url, ->
scripts[url] = true
callback()
)
$.getScript(url)
.done ->
scripts[url] = true
callback()
.fail ->
callback()

plugin.get = wiki.getPlugin = (name, callback) ->
return callback(window.plugins[name]) if window.plugins[name]
getScript "/plugins/#{name}.js", () ->
callback(window.plugins[name])
getScript "/plugins/#{name}/#{name}.js", () ->
return callback(window.plugins[name]) if window.plugins[name]
getScript "/plugins/#{name}.js", () ->
callback(window.plugins[name])

plugin.do = wiki.doPlugin = (div, item) ->
error = (ex) ->
Expand Down Expand Up @@ -53,17 +57,6 @@ window.plugins =
bind: (div, item) ->
div.dblclick -> wiki.textEditor div, item
div.find('img').dblclick -> wiki.dialog item.text, this
chart:
emit: (div, item) ->
chartElement = $('<p />').addClass('readout').appendTo(div).text(item.data.last().last())
captionElement = $('<p />').html(wiki.resolveLinks(item.caption)).appendTo(div)
bind: (div, item) ->
div.find('p:first').mousemove (e) ->
[time, sample] = item.data[Math.floor(item.data.length * e.offsetX / e.target.offsetWidth)]
$(e.target).text sample.toFixed(1)
$(e.target).siblings("p").last().html util.formatTime(time)
.dblclick ->
wiki.dialog "JSON for #{item.caption}", $('<pre/>').text(JSON.stringify(item.data, null, 2))
changes:
emit: (div, item) ->
div.append ul = $('<ul />').append if localStorage.length then $('<input type="button" value="discard all" />').css('margin-top','10px') else $('<p>empty</p>')
Expand Down
21 changes: 21 additions & 0 deletions client/plugins/chart/chart.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
formatTime = (time) ->
d = new Date (if time > 10000000000 then time else time*1000)
mo = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()]
h = d.getHours()
am = if h < 12 then 'AM' else 'PM'
h = if h == 0 then 12 else if h > 12 then h - 12 else h
mi = (if d.getMinutes() < 10 then "0" else "") + d.getMinutes()
"#{h}:#{mi} #{am}<br>#{d.getDate()} #{mo} #{d.getFullYear()}"

window.plugins.chart =
emit: (div, item) ->
chartElement = $('<p />').addClass('readout').appendTo(div).text(item.data.last().last())
captionElement = $('<p />').html(wiki.resolveLinks(item.caption)).appendTo(div)
bind: (div, item) ->
div.find('p:first').mousemove (e) ->
[time, sample] = item.data[Math.floor(item.data.length * e.offsetX / e.target.offsetWidth)]
$(e.target).text sample.toFixed(1)
$(e.target).siblings("p").last().html formatTime(time)
.dblclick ->
wiki.dialog "JSON for #{item.caption}", $('<pre/>').text(JSON.stringify(item.data, null, 2))

33 changes: 33 additions & 0 deletions client/plugins/chart/chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(function() {
var formatTime;

formatTime = function(time) {
var am, d, h, mi, mo;
d = new Date((time > 10000000000 ? time : time * 1000));
mo = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];
h = d.getHours();
am = h < 12 ? 'AM' : 'PM';
h = h === 0 ? 12 : h > 12 ? h - 12 : h;
mi = (d.getMinutes() < 10 ? "0" : "") + d.getMinutes();
return "" + h + ":" + mi + " " + am + "<br>" + (d.getDate()) + " " + mo + " " + (d.getFullYear());
};

window.plugins.chart = {
emit: function(div, item) {
var captionElement, chartElement;
chartElement = $('<p />').addClass('readout').appendTo(div).text(item.data.last().last());
return captionElement = $('<p />').html(wiki.resolveLinks(item.caption)).appendTo(div);
},
bind: function(div, item) {
return div.find('p:first').mousemove(function(e) {
var sample, time, _ref;
_ref = item.data[Math.floor(item.data.length * e.offsetX / e.target.offsetWidth)], time = _ref[0], sample = _ref[1];
$(e.target).text(sample.toFixed(1));
return $(e.target).siblings("p").last().html(formatTime(time));
}).dblclick(function() {
return wiki.dialog("JSON for " + item.caption, $('<pre/>').text(JSON.stringify(item.data, null, 2)));
});
}
};

}).call(this);
File renamed without changes.
28 changes: 8 additions & 20 deletions client/test/testclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -1192,17 +1192,22 @@ require.define("/lib/plugin.coffee", function (require, module, exports, __dirna
if (scripts[url] != null) {
return callback();
} else {
return $.getScript(url, function() {
return $.getScript(url).done(function() {
scripts[url] = true;
return callback();
}).fail(function() {
return callback();
});
}
};

plugin.get = wiki.getPlugin = function(name, callback) {
if (window.plugins[name]) return callback(window.plugins[name]);
return getScript("/plugins/" + name + ".js", function() {
return callback(window.plugins[name]);
return getScript("/plugins/" + name + "/" + name + ".js", function() {
if (window.plugins[name]) return callback(window.plugins[name]);
return getScript("/plugins/" + name + ".js", function() {
return callback(window.plugins[name]);
});
});
};

Expand Down Expand Up @@ -1259,23 +1264,6 @@ require.define("/lib/plugin.coffee", function (require, module, exports, __dirna
});
}
},
chart: {
emit: function(div, item) {
var captionElement, chartElement;
chartElement = $('<p />').addClass('readout').appendTo(div).text(item.data.last().last());
return captionElement = $('<p />').html(wiki.resolveLinks(item.caption)).appendTo(div);
},
bind: function(div, item) {
return div.find('p:first').mousemove(function(e) {
var sample, time, _ref;
_ref = item.data[Math.floor(item.data.length * e.offsetX / e.target.offsetWidth)], time = _ref[0], sample = _ref[1];
$(e.target).text(sample.toFixed(1));
return $(e.target).siblings("p").last().html(util.formatTime(time));
}).dblclick(function() {
return wiki.dialog("JSON for " + item.caption, $('<pre/>').text(JSON.stringify(item.data, null, 2)));
});
}
},
changes: {
emit: function(div, item) {
var a, i, key, ul, _ref, _results;
Expand Down

0 comments on commit 3372b50

Please sign in to comment.