Nested Objects :: Reuse Some Code In A Different Context To Do A Different Job?

Apr 29, 2011

I'm trying to reuse some code in a different context to do a different job.The code to be reused contains hundreds of lines similar to a = new b.c.d(e,f) with different value for e and f.I need to create a new user defined object with the structure b.c.d. I've made numerous attempts along the lines of:

function d (e, f) {
this.e = e;
this.f = f;
}

[code]....

with various permuations of functional declarations.However I get error message "Object expected" or "b.c.d is null or not an object" at the final line of the example.It works with the test line var a = new d("test", "message") but not when I start to build up the expression.How should I define of b.c.d?

View 8 Replies


ADVERTISEMENT

Using Recursion To Print Out Nested Objects

Dec 29, 2009

I am having trouble with a recursive function I created to list out the indexes and values of various nested objects.
var macros={
CTRL: {
ALT: {
ENTER: "<br />",
P: "<p>.</p>",
A: "<a href="">.</a>",
_1: "<h1>.</h1>",
_2: "<h2>.</h2>",
_3: "<h3>.</h3>",
_4: "<h4>.</h4>",
_5: "<h5>.</h5>",
_6: "<h6>.</h6>"
}}};

I want to print out the whole 'bread crumb trail' to each object, ie CTRL ALT 6: <h6>.</h6>, but at the moment my function prints out CTRL ALT twice for 'ENTER' and then never again. The function:
function printObj(obj) {
for(i in obj) {
var n=i.replace("_", "");
document.write(n);
if(typeof obj[i]=="string") {
document.write(":");
document.write(" "+obj[i].replace(/</g, "<").replace(/>/g, ">"));
} else {
document.write(n);
}
if(typeof obj[i]=="object") printObj(obj[i]);
document.write("
");
}}
printObj(macros);

The current output:
CTRLCTRLALTALTENTER: <br /> P: <p>.</p> A: <a href="">.</a> 1: <h1>.</h1> 2: <h2>.</h2> 3: <h3>.</h3> 4: <h4>.</h4> 5: <h5>.</h5> 6: <h6>.</h6>

View 4 Replies View Related

Error In IE When Appending Nested Objects

Mar 31, 2006

I'm writing examples for placing standards-compliant java applets in XHTML or HTML documents. And I'm also testing with Javascript. At some point, I created two 'object' elements, each with their 'param' children. Code:

View 6 Replies View Related

Resolved Inheritance And Nested Objects (non-DOM Related)?

Nov 17, 2009

I posted this once, but it disappeared, and I have no notifications that I did anything wrong. I read the rules before posting and wasn't breaking any so I am not sure why it disappeared but here goes again.

I am trying to learn Javascript (particularly OOP) from a series of screencasts by Douglas Crockford. I have developed a theoretical "game" to build to illustrate it to myself better, and learn by example.

I must be misunderstanding how inheritance works, because my code is not producing the results I thought it would. Here is what I have, followed by an explanation of my understanding. $(function()

[Code]...

View 11 Replies View Related

JQuery :: Updating / Adding And Deleting Objects Nested In Other Ones?

Aug 9, 2011

I have the following object:
var wDefaults = {
"skin":1,
"pagewidth":"960px",
"c1col":[
{"wid":"w001","pcol":0,"wpos":0,"wclosed":"false","wcollapsed":"true"}
],
"c3col":[
{"wid":"w002","pcol":0,"wpos":0,"wclosed":"false","wcollapsed":"false"},
{"wid":"w003","pcol":0,"wpos":1,"wclosed":"false","wcollapsed":"false"},
{"wid":"w004","pcol":0,"wpos":2,"wclosed":"false","wcollapsed":"false"},
{"wid":"w005","pcol":1,"wpos":0,"wclosed":"false","wcollapsed":"false"},
{"wid":"w006","pcol":1,"wpos":1,"wclosed":"false","wcollapsed":"false"},
{"wid":"w007","pcol":1,"wpos":2,"wclosed":"false","wcollapsed":"false"},
{"wid":"w008","pcol":1,"wpos":3,"wclosed":"false","wcollapsed":"false"},
{"wid":"w009","pcol":2,"wpos":0,"wclosed":"false","wcollapsed":"false"},
{"wid":"w010","pcol":2,"wpos":1,"wclosed":"false","wcollapsed":"false"}, {"wid":"w011","pcol":2,"wpos":2,"wclosed":"false","wcollapsed":"false"}
]}

First, how do I access a single value? I've tried some of the examples I saw on the forum, but nothing happened. The alert did not fire:
alert(wDefaults.c3col[0].wid); //first try
alert(wDefaults.c3col.0.wid); //second try
var obj = wDefaults.c3col[0]; //third try
alert(obj.wid);

The nested objects are the properties for widgets within a portal. After the user moves around the widgets, I need to update the object, putting the widgets in a different order within c3col and updating the values saved in pcol, wpos, wclosed, & wcollapsed. I also may need to add or delete an object, for example, delete wid=w003 and add a new one called w012.

My logic would be:
for each widget on the page
found = false
find the object in c3col where wid == x and update its other values
. set found = true
if found == false then add a new object to c3col with x & its properties
end for
for each object in c3col
if that wid isn't found in the list of widgets on the page, delete it from c3col
end for
sort the objects under c3col by pcol and then wpos

The red parts are the ones I'm unclear about how to do it. My basic questions are:
(1) How do you access a single nested object?
(an object within c3col, find and change its values)
(2) How do you add a new nested object to an existing object?
(add a new object to c3col)
(3) How do you delete an nested object?
(remove an object from c3col)
(4) How do you sort nested objects?
(sort the objects in c3col by pcol and wpos)

View 3 Replies View Related

Code To Print Div1 With All Nested Divs?

Aug 25, 2010

I have multiple divs something like this

<div id="div1">
<div id="div2">
<div id="div3">

[code]....

I want JavaScript code to print div1 with all nested divs as well I tried using the following code but it only print div1 content

var printContent = document.getElementById('div1');
var windowUrl = 'about:blank';
var uniqueName = new Date();

[code]...

View 5 Replies View Related

How Do Objectify This Since Need To Reuse?

Sep 18, 2010

I have some carousel code that I include on a page that has one carousel. Well, now we need to have two carousels with different content. So, instead of me having to recreate dbl data, I am curious how I can retrofit my current code to that I can objectify it for reusability.

[code].....

View 1 Replies View Related

Popup Reuse In FireFox

Jul 23, 2005

I am trying to reuse a popup in my application. The reused popup also
opens another popup. From this final popup I then try and reference a
function located in the window that origionally opened the reused
popup. This works fine in IE but doesn't in FireFox. Looking at the
code through the Javascript debugger in FireFox it tells me that the
reused popup's opener is closed even though it is still open. Is this
a bug with FireFox or just bad practice?

View 11 Replies View Related

JQuery :: Reuse Datepicker Formatting For Multiple Fields

Apr 9, 2010

I want to use the datepicker for multiple fields in a form however I don't know how to have it re-use the settings for multiple fields. For example, I have a form with 4 different fields for dates. I want to use the same datepicker formatting for each field. So instead of having to do something like this

[Code]..

View 1 Replies View Related

JQuery :: Lambda Functions - Edit And Reuse The Function Easily

Apr 10, 2011

Seeing the examples I have noted that you always use lambda functions. Is there any reason for that? why you don't make something like this:

I think is more clear than:

And we can edit and reuse the function easily, also if you are using an editor like Netbeans you can see all your functions in a list.

Even more, I think in some situations is faster a closure because we are not creating a new object every time we pass the function:

Is there any reason for chosing lambda functions?

View 3 Replies View Related

Optimization - Building Objects In Visual Basic - Code Creates A Button Which Changes On Mouseover And On Mouseclick

May 15, 2011

I'm used to building objects in Visual Basic and I'm having difficulty simplifying this code into an object so I can just define and run about a dozen of them.

The code creates a button which changes on mouseover and on mouseclick. The button is a link to another page.

Also on mouseover the button slides to the right, giving a more intelligent feel for the user.

What are my options for streamlining this code so I can reduce the number of lines of code-clutter?

The code below is formatted properly.

PHP Code:

View 5 Replies View Related

Objects Under Mouse - Return An Array Of All Objects Underneath A Certain Point

Apr 17, 2011

Is there a way in Javascript or Jquery to return an array of all objects underneath a certain point, ie. the mouse position. Basically, I have a series of images which link to various web pages but I have a large semi transparent image positioned over the top of the other images. I want to find the href of the background image that the mouse pointer clicks over.

View 1 Replies View Related

JQuery :: Extending Objects With Internal Objects?

Sep 5, 2009

Is there a better way to extend object with internal objects?

$.fn.bestShow = function(s) {
var d = {
width: 0,
height: 0,
order: "numeric",
orderBy: "",

[Code]...

View 3 Replies View Related

Node.context.nextElementSibling.value Nothing In IE8?

Mar 25, 2011

I am building an sftp application. It has requirements to upload and download. To upload, a target folder that exists on the server needs to be set. I have a jQuery folder tree that dynamically creates a tree view of a directory on the server. Currently in Firefox, Opera, and Chrome if someone clicks on a branch of the tree on the afterClick event I am able to get the target path by using the DOM via node.context.nextElementSibling.value; The code for the afterClick is:

[Code]...

View 6 Replies View Related

ADD To Context Menu?? RESTORE It??

Dec 12, 2005

I know how to disable the context menu (the right hand mouse button) and how to replace it by my own menu. I also know that not everybody likes this - so let's not discuss about that here.

What I can't figure out and what I would like to know, is:
1) How to ADD elements to it, i.e. keep the original contents and add something to it;
2) How to RESTORE it to its original contents.

Does anyone know the code for a simple working example of these things?

View 1 Replies View Related

Dynamicly Changing Context Menus

Jul 29, 2005

I'm making a web application which is a copy of existing desktop application.
I use telerik controlls for MS visual studio I have a little bit complicated situation beacuse I need context menus but the main problem is that they have to be downloaded from server after the page loads. I can't load all of them on page because there are to many.

This is my solution of the problem. When user right-clicks js download from server through XMLHttpRequest some data from serwer and make menu from them.
But it needs much work to make the menu look nice, now I just have one level
menu.

I've been looking for some controlls that can do the things I need but with
no result.

View 2 Replies View Related

Access Context Path Using Javascript?

Jul 11, 2006

I am running my website using Weblogic, so the path is something like
http://<myip>:<port>/<servername>/


On JSP pages I can use <%=request.getContextPath()%to get the root
path of the site, ie that specified above. How can I get the same using
Javascript?

For example, something like <a href='/home'>..</awill not work as
that would point to http://<myip>:<port>/home and needs to point to
http://<myip>:<port>/<servername>/home

View 1 Replies View Related

Problem With Dynarch Context Menu

Aug 2, 2007

I am creating html pages with forms where I use Dynarch menu script in a
context menu mode. Their script needs to be initialized like this:
<body onload="DynarchMenu.setup('menu', { context: true });">

This is in the beginning of the html page.
But, in my webpages I have only few pages where I actually use this kind of
menu. Since I use smarty template engine, I have single html-header file for
all pages - it includes the same <html><head><bodyetc. for each page.
So I tried to initialize this dynarch script only within the page that
actually uses this menu. I do it like this:

<form>[...]</form>
<ul id="menu">
[context menu elements definition here]
</ul>

<script>window.onload=DynarchMenu.setup('menu',{ context: true });</script>

This thing works OK in Firefox, however when I load such page in IE6 it
aborts the operation without even showing the page, and the popup message
says:

"Internet Explorer cannot open the Internet site http://example.com.
Operation aborted."

Does anyone know a way how to initialize the DynarchMenu.setup not from the
<bodyelement but from anywhere else in the html page?

View 2 Replies View Related

Event Handlers, OO And Function Context

Sep 11, 2007

I am writing a javascript code that parses dom and finds event
handlers attached to mouseover events. Then i will replace the
existing handler say B() with my own function say A(). When the event
happen and control comes to my function A(), after doing required
processing i will call B() as shown below

<a href = "abc.com" mouseover = "B();"link </a>

while parsing i will have (trimmed down version)

var oldHandler = node.onmouseover;
node.

function A()
{
/ * my code */
oldHandler.call(this);
}

This was working fine as long as B() was a global function. I started
getting problems when B was a member function. For eg:

function Alerter(text)
{
this.text=text;
var me=this;
this.invoke=function ()
{
alert(this.text);
}
}
var sayHi = new Alerter('Hello, world!');

The web developer would have code like
<a href = "abc.com" mouseover = "sayHi.invoke()"link </a>

But this time around, my function A() fails since although i have
handler to sayHi.invoke(), it has to be executed in correct context.
Other wise "this.text" is giving me error because when i say
oldHandler.call(this), i am executing the sayHi.invoke() with the html
element being passed as this.

View 2 Replies View Related

JQuery :: Get The Whole Temp Context After Manipulation

Aug 23, 2010

I am trying to use Jquery as an XML tool to transform xml data other than the DOM.

This works very well and i can change my xml data.

Now i want back my whole xml that i just transform and this is where there is a problem !

$(xml).find('#id').html('some text').parent.parent.parent ... is not a good way

I read something about the defaultContext but it seems risky / hazardous.

Needed fonction would be $(xml).find('#id').html('some text').getRoot().html(); or something like that.

View 2 Replies View Related

JQuery :: Object's Context Always Is Undefined?

Aug 11, 2010

I try to usejQuery( html, [ ownerDocument ] ) to create a element and get the jquery object.

var $list = $('<ul class="list">');
console.log($list.context); // return undefined
$('body').append($list);

[code]....

View 12 Replies View Related

YUI Context Menu In Php Generated Table Row?

Apr 23, 2009

I have a problem with YUI context menu. I want the menu to show different links (with product_id) in every row. I have been struggling with this for days no without result.My code is as follow:

Code:

$result = dbquery("SELECT ..........
echo "<table id='dataset' style='vertical-align: bottom' cellpadding='0' cellspacing='0' width='".$laius."' class='table11'>";
echo "<tr><td >TABLE HEADER</td></tr>";

[code]....

As you can see table row takes menu items according to id (type1, type2 etc).But as my table is created from mysql database dynamically, it does'n work that way.

View 1 Replies View Related

JS Context Help Menu (Right Side Popup)

May 14, 2003

opens a new window on the right side. resizes the main window. good for online help and
guided tours over multiple websites. still improving it....

View 2 Replies View Related

Get Context Path In Script Functions?

Nov 7, 2011

I am trying to get context path of my Applcation. But it is showing errors in that. Can you please mention the way how to get context path in javascript functions.

View 4 Replies View Related

Canceling Context Menu In Chrome And FF?

Dec 9, 2009

I am displaying my own context menu in response to a right-click on control (textbox) in my ASP.NET application. In IE, I can suppress the display of the browser's own context menu by simply returning false from the javascript that displays my context menu.How can I suppress the browser context menus from Chrome or Firefox?

View 2 Replies View Related

Adding Context-menu To A Button Only

Feb 16, 2005

I want to add a context-menu to a button only. The aontext menu has to be dynamic one. it can be configurable.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved