inside Factory_rounded_corners function is not working:
function Factory_rounded_corners(selector, color, type, numb_elem)
{
var rounded_container;
if(numb_elem == "one" && type == "all_round")
{
rounded_container = new All_rounded_corners_one_element(selector, color);
alert(rounded_container.color);//Does not work
alert(rounded_container.temp_array); //Does not work
rounded_container.elements_to_be_affected();//Does not work
}
}
So if the selector variable contains a falsy value (which could be undefined, false, null, “”, 0) it will be that falsy value which is assigned to this.temp_array
If selector doesn’t contain a falsy value, it will be considered as a truthy value and execution will carry on to the selector.split(" ") part, which will then be assigned to this.temp_array
That way, regardless of even if selector and/or color are undefined, the properties still get set on the object without causing an error to occur.
Step by step, that’s the way to do it. Give me a few moments to catch up. I’ve given up any hope of that jsfiddle being updated, and am attempting to match what you’re doing (badly) with local code instead.
Currently you have mootools loaded, with the javascript activating in the web pages onload event.
You should use no library instead of mootools, change the loading to no wrap (in body).
After that the HTML code should have the scripting code at its end removed, and placed at the end of the scripting section instead.
I don’t think I’m using it correctly. I have done as you said.
After reading the jsfiddle documentation under Fiddle Settings (Sidebar) section:
it says ‘no wrap(body):
do not wrap the JavaScript code, place it in <body> section’
I have now added body tags in html section and moved the javascript code from below the html section to just below the body section.
Is that what you meant?
The updated javascript if it makes it easier:
/* Function Factory_rounded_corners
* -------------------------
* Parameter: selector
* Return: None
* Description: Create a rounded container around elements to be affected
*/
function Factory_rounded_corners(selector, color, type, numb_elem)
{
var rounded_container;
if(numb_elem == "one" && type == "all_round")
{
rounded_container = new All_rounded_corners_one_element(selector, color);
alert(rounded_container.color);//works
alert(rounded_container.temp_array); // works
rounded_container.elements_to_be_affected();//Does not work
}
}
/* Function All_rounded_corners
* -------------------------
* Parameter: selector
* Return: None
* Description: Create a rounded container around elements to be affected
*/
function All_rounded_corners_one_element(selector, color)
{
alert("Inside All_rounded_corners");
Custom_rounded_container.call(this);
//this.superclass(selector, color);
}
/* Function custom_rounded_container
* ----------------------------------
* Parameters: selector
* Properties: this.temp_array
* Methods: this.elements_to_be_affected, this.apply
* Returns: Returns a object
* Description: selector parameter should be in two formats: id of element if only one element is to be affected ie: 'content'
or id of surrounding element and the tag of the elements to be affected, ie: 'content li'
*/
function Custom_rounded_container(selector, color)
{
/*
if(selector == undefined)
{
alert("selector is undefined");
}
else
{
alert("selector is: " + " " + selector);
alert("Inside Custom_rounded_container");
}
*/
alert("Inside Custom_rounded_container");
this.temp_array = selector && selector.split(" ");
//alert(this.temp_array);
this.color = color;
}
Custom_rounded_container.prototype.test = function()
{
alert("Inside test");
}
/* Function elements_to_be_affected
* ----------------------------------
* Parameters: None
* Properties: None
* Local variables: None
* Local methods: None
* Returns: elements in array or one element
* Description: Custom_rounded_container that retrieves elements to be affected
*/
Custom_rounded_container.prototype.elements_to_be_affected = function()
{
alert("Inside elements_to_be_affected");
//alert(this.temp_array.length);
//return = document.getElementById(this.temp_array[0]).getElementsByTagName(this.temp_array[1]);
/*
children_elements = function(parent_element)
{
switch(parent_element.nodeName)
{
case 'UL': return parent_element.getElementsByTagName("li");
}
}
*/
//return children_elements(parent_element[0]);
}
//All_rounded_corners_one_element.prototype.superclass = Custom_rounded_container;
//alert(rounded_container.selector);//works
//alert(rounded_container.color);
//All_rounded_corners_one_element.prototype = new Custom_rounded_container(selector, color);
All_rounded_corners_one_element.prototype = new Custom_rounded_container();
All_rounded_corners_one_element.prototype.constructor = All_rounded_corners_one_element;
No, remove ALL of the scripting code from the HTML section. It doesn’t belong there and more importantly, tries to execute before any of the other scripting code has even begun yet to exist.