Objects And Prototyping - Transform XML Into HTML In Different Views
Nov 8, 2009
I am ok with using objects creating classes if someone else defines, but when it comes to defining my own, I hit a nasty brick wall... I am using an XML/XSLT wrapper called Sarissa to help with programming a utility to transform XML into HTML in different views. For this to happen, I have created a Loader class which loads in XML required. I am aware of prototyping for binding methods to objects (as opposed to replicating the same method every time an instance is created)... The aim being I want to create a progress bar for the essential files that need to be loaded in. Presently I have them load in Synchronous mode just to get the utility working, which I know is poor, so would like to address it.
[Code]...
View 1 Replies
ADVERTISEMENT
Apr 23, 2007
I've been pretty infatuated with JSON for some time now since
"discovering" it a while back. (It's been there all along in
JavaScript, but it was just never "noticed" or used by most until
recently -- or maybe I should just speak for myself.)
The fact that JSON is more elegant goes without saying, yet I can't
seem to find a way to use JSON the way I *really* want to use it: to
create objects that can be instantated into multiple instances without
prototyping. I've seen (and used) JSON for singleton object instances
-- this not a problem and this is how it works right out of the gate.
But given the following custom object written the past "normal" way, I
would like to write it in JSON format, and then be able to create new
instances from the one definition. Here's an example using the "old
way" most who have been writing JavaScript for years have seen:
function Two( x, y ) {
this.x = x;
this.y = y;
}
Two.prototype.sum = function () { return this.x + this.y }
Two.prototype.max = function () { return this.x this.y ? this.x :
this.y }
Two.prototype.min = function () { return this.x this.y ? this.y :
this.x }
Two.prototype.pow = function () { return Math.pow( this.x, this.y ) }
Now, I know I can get all "fancy" with the above and do either this:
Two.prototype = {
sum : function { return this.x + this.y },
max : function () { return this.x this.y ? this.x : this.y },
min : function () { return this.x this.y ? this.y : this.x },
pow : function () { return Math.pow( this.x, this.y ) }
};
Or this:
function Two( x, y ) {
// Properties.
this.x = x;
this.y = y;
// Methods.
this.sum = function () { return this.x + this.y }
this.max = function () { return this.x this.y ? this.x : this.y }
this.min = function () { return this.x this.y ? this.y : this.x }
this.pow = function () { return Math.pow( this.x, this.y ) }
}
(The later seems to work without prototyping...!)
But neither are really as close to pure JSON as I would like, so that
I can instantate those:
var hisPair = new Two( 11, 22 );
var herPair = new Two( 33, 44 );
What I'd like is a way in PURE JSON to be able to create the Two class
(as an example) using pure JSON. I've not seen anything yet on the
web that addresses this directly aside from some pages which require
you to include another JS to allow "deep embedding" of classes using
other helper "classes" (that are created the "old way" it seems), etc.
The best I've found so far on using pure JSON to create a class that
allows *multiple* instances is something like this:
function Two( x, y ) {
var class = {
x : x,
y : y,
sum : function { return this.x + this.y }
max : function () { return this.x this.y ? this.x : this.y }
min : function () { return this.x this.y ? this.y : this.x }
pow : function () { return Math.pow( this.x, this.y ) }
};
for (var element in class) this[element] = class[element];
}
Now *THAT* works, but it's still not as "pure" I would like. But it's
acceptable for now, I guess, since I *am* creating the entire "class"
as a JSON object, and I consider the outside function "wrapper" as the
necessary "constructor." But I keep wondering... There HAS to be a
better way.
I'm just wondering if anyone knows of a place that discusses JSON used
in situations like the above. Again, I've seen an ABUNDANCE of pages
and sites that discuss JSON in Singleton usage, but nothing that
discusses it as I am wanting here.
View 2 Replies
View Related
Jun 13, 2010
I am working on a rapid html prototyping framework. This would allow me (as an interaction designer) to create html prototypes fast.I have been looking in templating plugins to help with building the templates or filling them with content. For example {{ lorem_ipsum }} would be replaced with a few paragraphs of random text. This is easy to do with several plugins.
However it would be great to be able to add a bit more flexibility by using functions like {{ loremWords(100) }} which would add 100 random words which are different for each replaced item. Or something similar to add a menu or other snippets.It is probably not too difficult but so far I have not gotten it working yet. And the pluginsI have found are either too complex, requires script tags or can't handle functions.
View 2 Replies
View Related
Jan 12, 2011
I have the following script sent to me and would like to know if I can edit this javascript to transform the layout of the products that are added to the cms system that it renders items for?
<html>
<title></title>
<head>
<link href="" rel="stylesheet" type="text/css" />
</head>
<body>
<div>
<SCRIPT type="text/JavaScript">
[Code].....
View 3 Replies
View Related
Jan 2, 2006
Im wondering if generating html objects such as tabels and rows in
javascript is faster than typing the html directly? Seems when you do
it in javascript you have to download alot of code and would slow down
displaying the page. while if you just type the html, it requires less
bandwidth and display faster?
is parsing html to display in browser slower than doing it through dom
to display the same html objects on the page?
View 1 Replies
View Related
May 3, 2005
<html>
<head>
<title> working with jscript</title>
<script>
[code]....
in my <body> tag how can i get the pname value,qty value which is built by dhtml.
View 2 Replies
View Related
Jan 10, 2010
I've seen lots of examples of invoking the getElementById and they always are given as a method of the document object. That is, they always show something like:
Code:
var theElement = document.getElementById("Fred");
But what I'd really like to do is to get an element from the document, but starting at a particular element in the hierarchy of the document.
For example, suppose I have two forms, form1 and form2, and they both have elements in them named "Fred" (and, yes, I know I shouldn't do that). But what I'd really like to do is something like:
Code:
var theElement = form1Element.getElementById("Fred");
assuming that I've already somehow retrieved the form1Element.
But Javascript reports to me that getElementById is not a method of form1Element. And the fact that every example I've ever seen of getElementById invokes it as a method of document would seem to bear that out. The thing is, on the microsoft site it actually shows the generic form of the method as:
Code:
object.getElementById(iD)
Which would seem to imply that it's more generic than just being a strictly document method, that perhaps it's intended to be a method of at least some additional HTML objects. Since that doesn't seem to be the case, how might I go about doing what I'd like to d, which is find the occurrence of the element, by its ID, but only within a particular section of the document hierarchy?
View 10 Replies
View Related
Jun 11, 2009
I am currently trying to create a thumbnail gallery that when you select a thumbnail, it loads associated thumbnails specific to that image for alternate views. I have the base of the thumbnail gallery created (click thumbnail + view larger image). I am however having issues getting it to load the associated sub images. I have the default one working for when the page is initially loaded, but it is not properly swapping out the urls for the new images, so it always uses the same three sub images.Here is the jquery code I am using:
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
[code]....
View 3 Replies
View Related
Apr 11, 2010
How do I go about comparing two jquery objects to see if they're actually the same html object.
I've got:
This should add a border to every object in the selected set except for the one defined in someobject... shouldn't it.
View 1 Replies
View Related
Apr 10, 2010
I'm trying to figure out if there's an easy way to execute all the Javascript code included or referenced in an HTML document even if given code references DOM objects.I basically have some Javascript code that makes a POST to my server. The POST payload includes a unique identifier for that html page, so I know if the JS was successfully executed if I see the unique identifier in my server's logs.
At first I wanted to test if the javascript in 5 pages worked, so I manually opened the 5 sites and verified my logs. I then wanted to see if the JS in 100 pages worked, so I wrote a little script that launches 100 tabs in FF staggered (I also used a nifty tool -- autocomplete, to close old tabs). I then wrote a utility to go through my server's logs and verify that the 100 unique identifiers that I was expecting were there... So this also worked fine!But now I want to move forward and test 1K or maybe even 10K sites. Is there anything I can use to execute Javascript embedded in an html page? Hopefully asynchronously?
View 2 Replies
View Related
May 5, 2009
I need suggestion for this.After a particular option selection in my page,how to replace the rest of the contents of the same page with its response,and too making the select action invisible... can i do it using ajax wit html. for example,i have a select option,where for each option is attached a new set of objects,i want them to be loaded on the same page at run time,without page refresh...
View 1 Replies
View Related
Jan 14, 2012
I am trying to load a view into a modal/dialog page so that I don't have to navigate to a separate page to login. I have read a couple of different forum posts but none of them have been successful. All i need is; when I click the link below, a popup dialog appears with the page loaded from the link.<a class='loginForm' id='loginForm' href="<?php echo base_url('admin/login'); ?>">Login</a>
View 1 Replies
View Related
Aug 20, 2007
Curious about how prototyping works and if there is a workaround for my problem. Say I create a new function for Objects called 'keyExists':
JavaScript Code:
Object.prototype.keyExists=function(key)
{
for(var tempKey in this)
if(tempKey==key)
return true;
return false;
};
When I use this function, one of the keys in the iteration will be the new function that I have created.
The following example would alert the following: "key1", "key2", "keyExists". The last one is my concern. Obviously their are other browser-defined functions available for Objects that don't show up when iterating through the object. I thought Object.prototype.functionname was the methodology for that but apparently not. Is there a way to achieve the effect I am looking for? Code:
View 1 Replies
View Related
Jun 3, 2009
I'd like to do something like this: After the page is loaded I have some forms with submit buttons. The buttons have a class called "open". By clicking any of these buttons the script is using AJAX to take some data from database and add some HTML to the document. This part of generated HTML has also buttons with a class "open". By clicking any of the new buttons script should do what it does with the old ones. The problem is I have no idea how to "refresh" a click function. After generating HTML it "sees" only the old buttons.
Here's some code:
$(document).ready(function(){
$(".open").click(function(){
var idVal = $(this).parent().parent().find("#PlaceId").val();
if($("#admin_places_"+idVal).html()=='')
[Code].....
View 2 Replies
View Related
Nov 3, 2009
Ultimately I'd like a set up resembling http://shop.lululemon.com/Swift_Tank...30/p/1230.html
Where you're able to click a swatch color and get a thumbnail of it on the model and a thumbnail of a fabric detail that you could then enlarge. I'm not sure how to go about this. I'm able to do it with one thumbnail, where when you rollover the various swatch colors, the thumbnail of the model gets replaced. However I'm unable to add in the 2 other thumbnails (on that site they're using 3 but I would only need 2) that would change at the same time, where you could switch back and forth from at detail of the model and the fabric.
I don't necessarily need the zoom function, but if it is possible to do all of those that would be good too.Otherwise I just need help coding how to at least get the swatches to change 3 images upon mouseover and that 2 of those images would be like the 3 thumbnails on the link above and would replace the larger thumbnail once clicked.
View 7 Replies
View Related
Feb 2, 2007
I'm having a problem with IE 7 (other versions didn't work either) when it comes to prototyping.
This is the code:
View 2 Replies
View Related
Jun 3, 2005
We all know (and love!) the fact that Mozilla exposes element constructors (HTMLParagraphElement, for example) for prototyping. Turns out Opera 8 allows you do to the same thing.
So this leaves Safari, which has actually allowed you to do this since 1.0, *but* doesn't publicly expose the constructors. The below code exports constructors into public variables matching those in Mozilla and Opera 8:
/*
HTMLElement Prototyping in KHTML and WebCore
Copyright (C) 2005 Jason Davis, www.jasonkarldavis.com
Additional thanks to Brothercake, www.brothercake.com
This code is licensed under the LGPL:
http://www.gnu.org/licenses/lgpl.html
*/
if (navigator.vendor == "Apple Computer, Inc." || navigator.vendor == "KDE") { // WebCore/KHTML
function(HTMLConstructors) {
for (var i in HTMLConstructors) {
window["HTML" + i + "Element"] = document.createElement(HTMLConstructors[i]).constructor;
}
}({
Html: "html", Head: "head", Link: "link", Title: "title", Meta: "meta",
Base: "base", IsIndex: "isindex", Style: "style", Body: "body", Form: "form",
Select: "select", OptGroup: "optgroup", Option: "option", Input: "input",
TextArea: "textarea", Button: "button", Label: "label", FieldSet: "fieldset",
Legend: "legend", UList: "ul", OList: "ol", DList: "dl", Directory: "dir",
Menu: "menu", LI: "li", Div: "div", Paragraph: "p", Heading: "h1", Quote: "q",
Pre: "pre", BR: "br", BaseFont: "basefont", Font: "font", HR: "hr", Mod: "ins",
Anchor: "a", Image: "img", Object: "object", Param: "param", Applet: "applet",
Map: "map", Area: "area", Script: "script", Table: "table", TableCaption: "caption",
TableCol: "col", TableSection: "tbody", TableRow: "tr", TableCell: "td",
FrameSet: "frameset", Frame: "frame", IFrame: "iframe"
});
function HTMLElement() {}
HTMLElement.prototype = HTMLHtmlElement.__proto__.__proto__;
var HTMLDocument = document.constructor;
var HTMLCollection = document.links.constructor;
var HTMLOptionsCollection = document.createElement("select").options.constructor;
var Text = document.createTextNode("").constructor;
var Node = Text;
}
In Opera < 8, all elements inherit directly from Object(), so you can still prototype Object() if you need to do element prototyping. Internet Explorer's elements *don't* inherit from Object, oddly enough, so who knows with that browser. In any case, there you go. It also happens to work in Konqueror (AFAIK).
View 4 Replies
View Related
Jul 20, 2005
I need to transform:
<A> x <A>
<A> y <A>
<B> i <B>
<B> j <B>
<B> k <B>
into:
<A>
<P> x <P>
<P> y <P>
</A>
<B>
<P> i <P>
<P> j <P>
<P> k <P>
</B>
There seems no easy way to do that. Am I missing somethig? I tried using variables, but they cannot be reassigned within the same context.
View 1 Replies
View Related
Jul 23, 2005
I'm having problems with a custom JS object (XMLLoadObject) I designed
to load XML and XSL files, perform an XSL transform with them and embed
the resultant HTML fragment into the host HTML document. I designed this
object so that I could generate and embed HTML fragments from more than
one XML/XSL source into a single HTML document. This is done by
instantiating an XMLLoadObject with an XML filename, an XSL filename,
and the ID of the HTML element as arguments. Once the object is created,
XSL Parameters can be assigned to the transformation with a member
function. Finally the documents are loaded and transformed with call to
the member function xmlLoad(). A distinct object must be instantiated
for each transform. The object assigns closured member functions as
event handlers to give access to the object's XML Document and XSL
Document objects (member data). Code:
View 2 Replies
View Related
Jul 20, 2005
A and B can be anything, another words those elements are variable.
I need to transform:
<A> x <A>
<A> y <A>
<B> i <B>
<B> j <B>
<B> k <B>
into:
<A>
<P> x <P>
<P> y <P>
</A>
<B>
<P> i <P>
<P> j <P>
<P> k <P>
</B>
There seems no easy way to do that. Am I missing somethig? I tried using variables, but they cannot be reassigned within the same context.
View 1 Replies
View Related
Feb 22, 2009
I'm a very beginner in Javascript. In a nutshell, I need a code which will transform a link name once user is hovering over link. Nothing really fancy, just a basic transformation, switch to upper case will do perfectly.(I got my own code for operations with text, which works when text is entered from a form. I just don't get, how to get string name on hover and put it back after). I've already googled for over an hour with no result.
View 2 Replies
View Related
Dec 17, 2009
I'm apparently misunderstanding what I'm reading on prototyping. My main task is to squeeze some performance out of an app that's a bit slow on IE, and it looks like large Arrays and their overhead may be part of the problem. I'm trying to replace those with my own array type based on Object and extend it with helper functions like .length. Here's a munged sample of what I've tried:
[Code]...
View 3 Replies
View Related
Dec 2, 2005
I have several xml files and a common stylesheet on the server. In my
html I have a sidebar of links. For each link I fire an onClick event
that triggers an xml load and transform with the output displayed in a
small popup. Everything works great for one click. My issue is that in
Firefox, each subsequent click concatenates the results to the previous
tranformed results. How can i start fresh each time. I've tried
resetting all variables involved but the problem won't go away. This
works fine in IE by the way. Does anyone have an idea on what the issue
could be?
View 2 Replies
View Related
Aug 11, 2009
I got an php page who picks up data out of my data base and puts it ina multidimensinal array. That array is being encoded to Json$event = json_encode($super_array);Then i made an javasript get funtion to get that array to my mainpage.
function get(){
$.get("../position of my file/test.php", function(data){
alert (""+data);
[code]....
View 10 Replies
View Related
Nov 8, 2011
I currently have a <p> where it changes to a textarea when a button is clicked How do I preserve the whitespace when saving that text to a database and displaying back to a <p>?
View 2 Replies
View Related
Apr 21, 2010
I'm currently using the code below to style some XML
Code:
var processor = new XSLTProcessor();
processor.importStylesheet(xslDoc);
var xmlDom = processor.transformToDocument(xmlDoc);
[Code]....
View 3 Replies
View Related