Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to add bars from other modules #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion controls/strip/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
</div>
</div>
</div>
<div class="bars">
</div>

<!-- Scripts -->
<script src="/socket.io/socket.io.js"></script>
Expand All @@ -65,7 +67,9 @@

<!-- Main -->
<script type="text/javascript">
var strip = strip_c({ strip_el: $('.strip') }).init();
var strip = strip_c({
strip_el: $('.strip'),
bars_el: $('.bars')}).init();
</script>
</body>
</html>
Expand Down
12 changes: 12 additions & 0 deletions controls/strip/strip.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
-webkit-user-select: none;
}

.bars {
position: absolute;
left: 0;
top: 45px;
right: 0;
bottom: 0;
}

.bar {
width: 100%;
}

.strip .bottom {
position: absolute;
bottom: 0;
Expand Down
47 changes: 39 additions & 8 deletions controls/strip/strip_c.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
* @author: spolu
*
* @log:
* - 2014-07-08 spolu Disable actions when not available #11
* - 2014-06-16 spolu Tabs filtering
* - 2014-06-13 spolu Remove favicon on navigation #2
* - 2014-06-13 spolu Loading progress dumpling
* - 2014-06-11 spolu Removed angularJS
* - 2014-06-04 spolu Forked from `mod_stack`
* - 2014-05-21 spolu New state format (tabs on core_state)
* - 2013-08-15 spolu Creation
* - 2014-08-03 gammagec Added add_bar to insert external module bars under the strip
* - 2014-07-08 spolu Disable actions when not available #11
* - 2014-06-16 spolu Tabs filtering
* - 2014-06-13 spolu Remove favicon on navigation #2
* - 2014-06-13 spolu Loading progress dumpling
* - 2014-06-11 spolu Removed angularJS
* - 2014-06-04 spolu Forked from `mod_stack`
* - 2014-05-21 spolu New state format (tabs on core_state)
* - 2013-08-15 spolu Creation
*/
'use strict'

Expand All @@ -28,6 +29,7 @@ var strip_c = function(spec, my) {
spec = spec || {};

my.strip_el = spec.strip_el || $('.strip');
my.bars_el = spec.bars_el || $('.bars');
my.wrapper_el = my.strip_el.find('.wrapper');
my.tabs_el = my.strip_el.find('.tabs');
my.back_el = my.strip_el.find('.command.back');
Expand All @@ -40,6 +42,9 @@ var strip_c = function(spec, my) {
my.tabs_divs = {};
my.active = null;

/* Dictionary of child bars attached underneath the strip. */
my.bar_divs = {};

my.color = color({});

//
Expand All @@ -62,6 +67,7 @@ var strip_c = function(spec, my) {
var update_tab; /* update_tab(tab_id, data); */
var position_tab; /* update_tab(tab_id, idx); */
var remove_tab; /* update_tab(tab_id); */
var create_bar; /* create_bar(bar); */

var mousewheel_handler; /* mousewheel_handler(evt); */
var dblclick_handler; /* dblclick_handler(evt); */
Expand Down Expand Up @@ -114,6 +120,23 @@ var strip_c = function(spec, my) {
return tab;
};

// ### create_bar
//
// Creates a new bar div element with the specified id.
// ```
// @bar {object} bar data.
// ```
create_bar = function(bar) {
var bar = $('<iframe/>')
.attr('id', bar.id)
.attr('height', bar.dimension)
.attr('frameborder', 0)
.attr('scrolling', 'no')
.addClass('bar')
.attr('src', bar.url);
return bar;
}

// ### update_tab
//
// Updates the tab with the specified id with the newly received state
Expand Down Expand Up @@ -365,6 +388,14 @@ var strip_c = function(spec, my) {
my.strip_el.find('.tabs').append(my.tabs_divs[t.tab_id]);
}
});
if(state.bars) {
state.bars.forEach(function (b) {
if(!my.bar_divs[b.id]) {
my.bar_divs[b.id] = create_bar(b);
my.bars_el.append(my.bar_divs[b.id]);
}
});
}
/* Cleanup Closed tabs */
Object.keys(my.tabs_divs).forEach(function(tab_id) {
if(!tabs_data[tab_id]) {
Expand Down
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* @author: spolu
*
* @log:
* - 2014-07-22 spolu Fix DNS error when not connected
* - 2014-06-04 spolu Move to `mod_layout`
* - 2014-01-17 spolu Creation
* - 2014-08-03 gammagec Added add_bar method to add external modules under the strip
* - 2014-07-22 spolu Fix DNS error when not connected
* - 2014-06-04 spolu Move to `mod_layout`
* - 2014-01-17 spolu Creation
*/
"use strict"

Expand Down Expand Up @@ -73,6 +74,10 @@ var bootstrap = function(http_srv) {
common.exit(0);
});
});

breach.expose('add_bar', function(src, args, cb_) {
common._.strip.add_bar(args.id, args.url, args.dimension, cb_);
});
});

var io = require('socket.io').listen(http_srv, {
Expand Down
57 changes: 54 additions & 3 deletions lib/strip.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* @author: spolu
*
* @log:
* - 2014-06-16 spolu Tabs filtering
* - 2014-06-16 spolu Removed action_next/prev towards tabs filtering
* - 2014-06-04 spolu Creation
* - 2014-08-03 gammagec Added ability to insert external module bars under the strip
* - 2014-06-16 spolu Tabs filtering
* - 2014-06-16 spolu Removed action_next/prev towards tabs filtering
* - 2014-06-04 spolu Creation
*/
"use strict"

Expand Down Expand Up @@ -38,12 +39,15 @@ var strip = function(spec, my) {
my.breach_update = false;
my.module_update = false;

my.bars = [];

//
// ### _public_
//
var handshake; /* handshake(socket) */
var init; /* init(cb_); */
var kill; /* kill(cb_); */
var add_bar; /* add_bar(id, url, dimension, cb_); */

//
// ### _private_
Expand Down Expand Up @@ -96,6 +100,7 @@ var strip = function(spec, my) {
var state = {
active: -1,
tabs: [],
bars: [],
breach_update: my.breach_update,
module_update: my.module_update
};
Expand All @@ -114,6 +119,9 @@ var strip = function(spec, my) {
return false;
});
}
if(my.bars) {
state.bars = my.bars;
}
return state;
};

Expand Down Expand Up @@ -498,9 +506,52 @@ var strip = function(spec, my) {
}, cb_);
};

// ### add_bar
//
// Adds an iframe for an external module to put new bars underneath the strip.
// ```
// @id {string} information about the bar to add.
// @url {string}
// @dimension {number}
// @cb_ {function(err)} the async callback.
// ```
add_bar = function(id, url, dimension, cb_) {

// check if bar with id already exists
var found = false;
my.bars.forEach(function(b) {
if (b.id === id) {
found = true;
}
});
// don't do anything if bar with id already exists
if(found) return cb_();

// insert the new bar to the state
my.bars.push({ id: id, url: url, dimension: dimension });
// push state change to UI
socket_push();

var total_height = 45;
// calculate the new strip height
my.bars.forEach(function(b) {
total_height += b.dimension;
});
async.series([
// reset the height of the strip bar.
function(cb_) {
breach.module('core').call('controls_dimension', {
type: 'TOP',
dimension: total_height
}, cb_);
}
], cb_);
}


common.method(that, 'init', init, _super);
common.method(that, 'kill', kill, _super);
common.method(that, 'add_bar', add_bar, _super);

common.method(that, 'handshake', handshake, _super);

Expand Down