Skip to content

Commit

Permalink
Adding element +- events
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Osbourne committed Jan 23, 2015
1 parent c983e1f commit 6852db7
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 26 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ ControlPanel.prototype.init = function () {
{
step: "Add options setting event",
fn: async.addOptionsEvent
},
{
step: "Add element events",
fn: async.addElementEvents
}
];

Expand Down
26 changes: 26 additions & 0 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,31 @@ module.exports = {
});
});
done();
},
/**
* Allow an API for adding/removing elements to clients
* @param cp
* @param done
*/
addElementEvents: function (cp, done) {

var elems = cp.pluginManager.hook("elements");
console.log(Object.keys(elems));
done();
//var bs = cp.bs;
//var socket = bs.io.of(cp.config.getIn(["socket", "namespace"]));
//var clients = bs.io.of(bs.options.getIn(["socket", "namespace"]));
//
//socket.on("connection", function (client) {
// client.emit("connection", bs.getOptions().toJS());
// client.on("cp:get:options", function () {
// client.emit("cp:receive:options", bs.getOptions().toJS());
// });
// // proxy client events
// client.on("cp:client:proxy", function (evt) {
// clients.emit(evt.event, evt.data);
// });
//});
//done();
}
};
12 changes: 0 additions & 12 deletions lib/client-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@
}
});

socket.on("cp:add:script", function (data) {
if (data.src) {
addJs(data);
}
});

socket.on("cp:add:css", function (data) {
if (data.src) {
addCss(data);
}
});

function addJs(data) {
(function (e) {
e.setAttribute("src", data.src);
Expand Down
9 changes: 9 additions & 0 deletions lib/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ module.exports = {
*/
"templates": function (hooks) {
return createInlineTemplates(hooks);
},
"elements": function (hooks) {
var obj = {};
hooks.forEach(function (elements) {
elements.forEach(function (item) {
obj[item.name] = item;
});
});
return obj;
}
};

Expand Down
16 changes: 15 additions & 1 deletion lib/plugins/history/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,21 @@ module.exports = {
controller: PLUGIN_NAME + "Controller",
order: 3,
icon: "list2"
}
},
elements: [
{
type: "css",
id: "__browser-sync-pesticidedepth__",
active: false,
file: __dirname + "/css/pesticide-depth.css",
title: "CSS Depth outlining",
served: false,
name: "pesticide-depth2",
src: "/browser-sync/pesticide-depth.css",
tagline: "Add CSS box-shadows to all elements. (powered by <a href=\"http://pesticide.io\">Pesticide.io</a>)",
hidden: ""
}
]
},
/**
* Plugin name
Expand Down
8 changes: 4 additions & 4 deletions lib/plugins/remote-debug/client-files.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var css = {
"pesticide": {
var css = [
{
type: "css",
id: "__browser-sync-pesticide__",
active: false,
Expand All @@ -11,7 +11,7 @@ var css = {
tagline: "Add simple CSS outlines to all elements. (powered by <a href=\"http://pesticide.io\">Pesticide.io</a>)",
hidden: ""
},
pesticideDepth: {
{
type: "css",
id: "__browser-sync-pesticidedepth__",
active: false,
Expand All @@ -23,6 +23,6 @@ var css = {
tagline: "Add CSS box-shadows to all elements. (powered by <a href=\"http://pesticide.io\">Pesticide.io</a>)",
hidden: ""
}
};
];

module.exports.css = css;
1 change: 1 addition & 0 deletions lib/plugins/remote-debug/remote-debug.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
var ctrl = this;
ctrl.options = options;
ctrl.section = pagesConfig[SECTION_NAME];
console.log(ctrl.options["clientFiles"]);
ctrl.items = [
{
name: "weinre",
Expand Down
20 changes: 11 additions & 9 deletions lib/plugins/remote-debug/remote-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ module.exports = {
controller: PLUGIN_NAME.replace(" ", "") + "Controller",
order: 4,
icon: "bug"
}
},
elements: clientFiles.css
},
/**
* Plugin name
Expand Down Expand Up @@ -152,7 +153,9 @@ function enableClientFile (clients, cp, bs, file) {
content: fs.readFileSync(item.file)
});
}

clientScripts = clientScripts.set(item.name, item);

addElement(clients, bs.getOptionIn(["clientFiles", item.name]).toJS());
}
}
Expand Down Expand Up @@ -205,18 +208,17 @@ function toggleWeinre (socket, clients, cp, bs, value) {

// Let the UI know about it
socket.emit("cp:weinre:enabled", _debugger);

clients.emit("cp:element:add", {
var fileitem = {
type: "js",
src: bs.getOptionIn([WEINRE_NAME, "targetUrl"]),
id: WEINRE_ELEM_ID
});
};

clientScripts = clientScripts.set("weinre", {
type: "js",
src: bs.getOptionIn([WEINRE_NAME, "targetUrl"]),
id: WEINRE_ELEM_ID
});
// Add the element to all clients
addElement(clients, fileitem);

// Save for page refreshes
clientScripts = clientScripts.set("weinre", fileitem);

} else {

Expand Down

0 comments on commit 6852db7

Please sign in to comment.