OO JS And SoundManager2 - Wrap Around Object Oriented Js
May 9, 2010
I will be the first to admit, I don't know much about JS and am just starting to wrap my mind around object oriented js. I have this small bit of code that has been giving me problems for days.
playlistItems[numItems-1] = soundManager.createSound({
id : songId,
url : $(this).attr('href'),
whileloading : player.whileloading,
onfinish: next
});
"next" is a function on the same object that playlistItems is defined on, but it doesn't ever seem to fire. I tried this.next as well, but it just gives me a runtime error....
I was writing my classes in an old fashion until today when I came across a new design pattern. Javascript is not an established OOP like C++ or Java. It doesn't have any easy way to create classes and to make private/public methods or properties as well as class-constructor. But it could be done in many ways.
My old way of OO design in Javascript was like following:
Code:
Those who were trying to write constructor and access public vars from private or vice versa, you would have probably faced some minor difficulties. But it was doable.
Now, the challenge is how can we make things cleaner and better. Here's the procedure I came up with:
I just released javascript lib that really helps to develop robust and clear js-scenarios following the OOP directions. The library is compatible with wide range of browsers on different platforms, including Netscape 4.x, Netscape 6.x, Netscape 7.x, Opera 6, Opera 7, Mozilla 1.0, IE 4, IE 5, IE 6.
The problems with the setTimeout and setInterval functions provided in Javascript are twofold. First, you can't call a local object method without losing your scope, and second, you can't pass objects to the function, since the function call is implemented as a string.
The Timer class solves these difficulties by employing a static array to store the parent object and function arguments until the function is called.
This class is provided as-is and pro bono, so go ahead and muck with it if you see things that could be done better.
Thanks to WA for giving me the idea for this (albeit indirectly)!
Updated 4/18/2003: Footprint decreased, minor code improvements. Updated 5/3/2003: Minor comment clarification; no code changes. Updated 5/10/2003: Minor code improvements. // The constructor should be called with // the parent object (optional, defaults to window).
function Timer(){ this.obj = (arguments.length)?arguments[0]:window; return this; }
// The set functions should be called with: // - The name of the object method (as a string) (required) // - The millisecond delay (required) // - Any number of extra arguments, which will all be // passed to the method when it is evaluated.
Timer.prototype.setInterval = function(func, msec){ var i = Timer.getNew(); var t = Timer.buildCall(this.obj, i, arguments); Timer.set[i].timer = window.setInterval(t,msec); return i; } Timer.prototype.setTimeout = function(func, msec){ var i = Timer.getNew(); Timer.buildCall(this.obj, i, arguments); Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec); return i; }
// The clear functions should be called with // the return value from the equivalent set function.
I'm trying to convert some Procedural code to be more Object Oriented and I'm stuck...
The page is really simple:
It's just a big picture w/ a caption under it, and a few thumbnail pics off to the side, that when clicked, replace the big picture as well as swap out the caption for a new one.
In the code (external JS file):
I've got 2 arrays:
One that holds the thumbnail image file URLs, and the other that holds the captions.
And a function:
I've created an object prototype that I can instantiate in order to:
1.) create the event: do the actual swapping of the thumbnail, and the changing of the caption.
2.) and attach that event to the thumbnail's link onclick event handler.
The code below is the closest I've come to making it work. The problem is that when I click any of the thumbnail links it only executes the last event instead of the one that corresponds to the link that was just clicked. Hopefully someone can take a look at my code and let me know what I'm doing wrong.
Simplified version of the code:
The x,y,z variable assignments are only in the window.onload function for the sake of clarity, but the event object instantiation block has to be in there for anything to work at all.
I know that the event0,event1,event2 objects work, and are attached to the onclick handler because they will swap the last thumbnail and caption when I click any of the thumbnail links. Of course that's the problem now... any click only activates the last event. It's like it attached the last event to all the onclick event handlers.
In fact, if I only create the event0 object, it works like it's supposed to... but when I create the event1 object, it does what it's supposed to and it takes over for event0. Creating event2 makes it take over for all of them. Each subsequent event# object seems to attach its own addy[ ] and caption[ ] to each previous x[ ] link.
I am trying to make a round corners script in object oriented programming method. This is purely for learning purposes.
The script is no where near complete but I am already having problems with it.
I am trying out the techniques described in 'David Flanagan ' text book 'JavaScript: The Definitive Guide, 5th Edition'
This code is called from html page which once working will place a round container around element
The selector parameter in Custom_rounded_container function is defined because only the else part of the if statement in Custom_rounded_container is executing. I put this in because few people at other forums thought the problem was because of the selector parameter being undefined.
Trying to figure out OO programming for JavaScript and I'm totally lost.
Here's what I'm trying to do:
I'm posting search data to a PHP form to run a query on a database.
The structure is sort of like this:
So I'm thinking I need to create search objects or arrays. Initially, I thought I could do something like this:
Code:
This doesn't seem to work. It says object not defined whenever I try to do something.
I've also tried creating a JSON object like this:
Code:
This will allow me retrieve the data like I want to:
Code:
The problem is I can't figure out how to add data to the JSON object without manually typing it in. I need to be able to loop through form elements on my HTML page and set them to these variables. I'm using jQuery and doing something like this:
This scroller shows images that fade out to be replaced by other images of the same size. I would like to wrap text around the slideshow.If the slideshow were an image, all I would have to do is:
I have anonymous function "xhr.onreadystatechange = function() {}" in the method "this.update" of an object that receives 2 arrays through AJAX. I need these 2 arrays to be assigned to this.images and this.folders, respectively, through this anonymous function. I try to use "var self" technique, but it doesn't work.
When the thing is first ran, IE displays alert saying "virtual" and successfully turns the wrap off. When I run it again, the alert still says "virtual"! It's like it doesn't save the settings but does apply them.
Is it possible to wrap a tag around another tag with javascript, but without using jQuery?
For example to put each IMG tag inside a SPAN ? Lets say I have [code]...
It can't be done with insertAdjacentHTML - if I try to add only the opening tag, the browser automatically appends the closing tag right after it. If I try to add only the closing tag, just nothing happens.
im trying to get the syntax down to find all img tags that are NOT surrounded by tags and wrap those img tags in tags. I can get the selector to get all img tags and wrap it in a tag but i need to further take it to disregard the img tags that already are wrapped in pseudocode $(img parent tag not equal to p).each().....
I have a JS function that is susposed to toggle word wrap on and off in a textarea. It works fine in IE but does not work in FireFox or Opera.
Does anyone know what the trick is to get it to work in FF and Opera?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <script type="text/javascript">
[Code]....
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
I have to wrap text in a td in firefox. My text is long single word like How can I wrap it to fit the width of the td. At the moment it is expanding the width of the whole table.
I'll try to explain as best I can, I wasn't able to find anything relevant on this on my searches so I'm guessing it isn't a commonly needed requirement... here goes: For the design of a website I've made all H1's (and a class for any others that require this look) and sub navs have a background colour of black.
This is fine, the 'problem' comes when a line of text is longer than the space it is contained within (this bit also fine), when the line wraps, the last letter/word of the first line and first letter/word of the second line don't respect the padding applied to it's tag (h1, li, a etc.)I have a css solution but I am unable to use it due to it's infeasibility, so I am looking for a js solution.Here is an example of what I'm looking to achieve:
http:[url].....But I need to somehow detect with js the last letter of the first line and the first of the last and then use that to apply a class to each of the offending letters.
Okay guys what I would like to do is add a class to this:
.wrap("<a href='" + item.link + "'></a>"); So that i can style this link
.wrap("<a class="grouped_elements" href='" + item.link + "'></a>"); When i try to use the second approach i get an error that reads: missing ) after argument list