I'm just starting out with OOP in JavaScript. I want to create a custom "panel." Here is what I have so far:
function ShinyPanel(css, attributes)
{
this.container = $(document.createElement("div")).addClass("shinyPanel");
this.titleBar = $(document.createElement("div")).addClass("shinyPanelTitleBar").appendTo(this.container);
this.topShine = $(document.createElement("div")).addClass("shinyPanelTopShine").appendTo(this.container);
this.leftShine = $(document.createElement("div")).addClass("shinyPanelLeftShine").appendTo(this.container);
this.content = $(document.createElement("div")).addClass("shinyPanelContent").appendTo(this.container);
if (!css) css = {};
if (!attributes) attributes = {};
this.css = css;
$(this.container).css(this.css);
this.title = attributes["title"];
$(this.titleBar).html(this.title);
}
Now I can instantiate this object and append it to the body via something like this:
var panel = new ShinyPanel({position:"absolute", top:"25%", width:"300px", height:"200px"}, {title:"Test"});
$("body").append(panel.container);
My question is, is there a way for me to make the object itself a div, thus eliminating the need for a "container" div? Then I could just call $("body").append(panel);.
It's not that its much trouble for me to have the container div there, it's more just for me...wanting to learn the right way to do things.
I tried this = document.createElement("div");, but I got an error: invalid assignment left-hand side.
return this.container;not work? :)