# HG changeset patch # User hamidouk # Date 1319188895 -7200 # Node ID df08c7f9535c14c9b0a487bc69faeaee98421167 # Parent 048125f1a16721c173bc7a951a64bda19993f9cf added a basic layout manager. diff -r 048125f1a167 -r df08c7f9535c src/js/layout.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/js/layout.js Fri Oct 21 11:21:35 2011 +0200 @@ -0,0 +1,46 @@ +/* layout.js - very basic layout management */ + +/* + a layout manager manages a div and the layout of objects + inside it. +*/ + +IriSP.LayoutManager = function(options) { + this._Popcorn = null; + this._widgets = []; + + this._div = "#LdtPlayer"; + this._width = 640; + this._height = 480; + + if (options === undefined) { + options = {}; + console.error("The options parameter is undefined."); + }; + + if (options.hasOwnProperty('divId')) { + this._div = options.divId; + } + + if (options.hasOwnProperty('width')) { + this._width = options.width; + } + + if (options.hasOwnProperty('height')) { + this._height = options.height; + } + + IriSP.jQuery(this._div).css("width", this._width); + IriSP.jQuery(this._div).css("height", this._height); +}; + +/* we need this special setter because of a chicken and egg problem : + we want the manager to use popcorn but the popcorn div will be managed + by the manager. So we need a way to set the instance the manager uses +*/ + +IriSP.LayoutManager.prototype.setPopcornInstance = function(popcorn) { + this._Popcorn = popcorn; + /* FIXME - don't forget to add the popcorn messages handlers there */ +} + diff -r 048125f1a167 -r df08c7f9535c unittests/index.html --- a/unittests/index.html Fri Oct 21 11:21:14 2011 +0200 +++ b/unittests/index.html Fri Oct 21 11:21:35 2011 +0200 @@ -24,6 +24,7 @@ + diff -r 048125f1a167 -r df08c7f9535c unittests/tests/layout.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/unittests/tests/layout.js Fri Oct 21 11:21:35 2011 +0200 @@ -0,0 +1,30 @@ +/* tests for layout.js */ +function test_layout() { + module("layout manager", {setup: + function() { + IriSP.jQuery("#widget-div").append("
"); + IriSP.jQuery("#widget-div").append("
"); + }}); + + test("test the default initialization of layout manager", function() { + var lay = new IriSP.LayoutManager(); + equal(lay._div, "#LdtPlayer", "the default div is set correctly"); + equal(lay._width, 640, "the default width is set correctly"); + equal(lay._height, 480, "the default height is set correctly"); + + console.log(IriSP.jQuery(lay._div).css("width")); + equal(IriSP.jQuery(lay._div).css("width"), lay._width + "px", "div width is set correctly"); + equal(IriSP.jQuery(lay._div).css("height"), lay._height + "px", "div height is set correctly"); + }); + + test("test custom init of layout manager", function() { + var lay = new IriSP.LayoutManager({divId: "#myDiv", width: 327, height: 542}); + equal(lay._div, "#myDiv", "the default div is set correctly"); + equal(lay._width, 327, "the default width is set correctly"); + equal(lay._height, 542, "the default height is set correctly"); + + equal(IriSP.jQuery(lay._div).css("width"), lay._width + "px", "div width is set correctly"); + equal(IriSP.jQuery(lay._div).css("height"), lay._height + "px", "div height is set correctly"); + }); + +};