PDA

View Full Version : None of jQuery UI functions work when called inside of a JS object?


kaisellgren
04-02-2009, 02:18 PM
Hi,

I am using objects in JS and I am trying to add draggable() into a DIV that works when I move the function out of the object context.

Example:
function obj_xxx() {
this.init = function() {
$(function() { $("#test").draggable();
}
}

testobj = new obj_xxx();
testobj.init();

That does not work. However, if I do this:

testobj = new obj_xxx();
testobj.init();
$(function() { $("#test").draggable();

Then it will work... because the draggable() function is not within the object.

I need this to work within the object, because I will have several DIVs associated with objects and I need them to have draggable() in specific cases.

Help?

Eldarrion
04-02-2009, 02:37 PM
Seems to work fine like this:


<script type="text/javascript">
function obj_xxx() {
this.init = function() {
$("#test").draggable();
}
}
$(document).ready(function() {
testobj = new obj_xxx();
testobj.init();
})
</script>


All in all, it seems you have one too many unnamed functions, plus you don't seem to be closing all parentheses in your version.

kaisellgren
04-02-2009, 02:41 PM
Oh thanks. It works now... I just removed the function part of it...

kaisellgren
04-02-2009, 03:03 PM
Damn I have a new problem...

$("#test").resizable({resize: function (event, ui) { ... }});

I am calling that inside the object, but it will not work, because again, there is a function that I use as a callback for onresize event. How would I solve this? I can't just drop the word function...