Jump to content


JS help : jqDnR


9 replies to this topic

#1 adamfran

    Young Padawan

  • Members
  • Pip
  • 91 posts

Posted 20 May 2007 - 06:28 AM

Hi,

I am currently trying to use jqDnR on a project ( link )

The only thing is, one part the script that they give you to insert onto the page is:

$().ready(function() {
	$('#ex1').jqResize('.jqResize');
});

Normally this wouldn't be a problem, but my divs are coming from a database meaning that I can't define each one in the script as the database rows will be changing all the time.

Is there any way I could use a different method so that I could use this script, for example document.getElementsByName('something');?

I can get it to work in Firefox but not IE with this code:
function init () {
	var test = document.getElementsByName('test');
	for (var i = 0; i < test.length; i++) {
		$().ready(function() {
		$('#' + test[i].id).jqResize('.jqResize');
		});
	}
}

window.onload = function()
{
init()
}


...with this html
<div id="ex1" name="test" class="jqDnR">
	I am an example Box "#ex1"<br />
	You can *RESIZE* Me.
	<div class="jqHandle jqResize"></div>
</div>
and I also have tried this...and again works with firefox but not IE (the error message I get in IE is test[...].id is null or not an object)

function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}

function init () {

	var test = getElementsByClass('jqDnR');
	for(i=0; i<test.length; i++)
		$().ready(function() {
		$('#' + test[i].id).jqResize('.jqResize');
		});

	
}

window.onload = function()
{
init()
}
...with this html

<div id="ex1" class="jqDnR">
	I am an example Box "#ex1"<br />
	You can *RESIZE* Me.
	<div class="jqHandle jqResize"></div>
</div>
As I am not a javascript expert, I haven't had much luck but maybe you could help me?

(or maybe theres another light javascript resize div script?)

- Adam

Edited by adamfran, 20 May 2007 - 08:16 AM.


#2 adamfran

    Young Padawan

  • Members
  • Pip
  • 91 posts

Posted 23 May 2007 - 01:16 PM

Ah, figured it out myself...

Anyway can you help me with a different situation, still related with jqDnR:

/*
 * jqDnR - Minimalistic Drag'n'Resize for jQuery.
 *
 * Copyright (c) 2007 Brice Burgess <bhb@iceburg.net>, http://www.iceburg.net
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * $Version: 2007.02.09 +r1
 */
(function($){
$.fn.jqDrag=function(r){$.jqDnR.init(this,r,'d'); return this;};
$.fn.jqResize=function(r){$.jqDnR.init(this,r,'r'); return this;};
$.jqDnR={
init:function(w,r,t){ r=(r)?$(r,w):w;
	r.bind('mousedown',{w:w,t:t},function(e){ var h=e.data; var w=h.w;
	hash=$.extend({oX:f(w,'left'),oY:f(w,'top'),oW:f(w,'width'),oH:f(w,'height'),pX:e.pageX,pY:e.pageY,o:w.css('opacity')},h);
	h.w.css('opacity',0.8); $().mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
	return false;});
},
drag:function(e) {var h=hash; var w=h.w[0];
	if(h.t == 'd') h.w.css({left:h.oX + e.pageX - h.pX,top:h.oY + e.pageY - h.pY});
	else h.w.css({width:Math.max(e.pageX - h.pX + h.oW,0),height:Math.max(e.pageY - h.pY + h.oH,0)});
	return false;},
stop:function(){var j=$.jqDnR; hash.w.css('opacity',hash.o); $().unbind('mousemove',j.drag).unbind('mouseup',j.stop);},
h:false};
var hash=$.jqDnR.h;
var f=function(w,t){return parseInt(w.css(t)) || 0};
})(jQuery);
$().ready(function() {
	$('#ex1').jqResize('.jqResize');
});

With this code how would I find the id of the div that is being resized (

#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 23 May 2007 - 02:17 PM

That particular dialect of JS is somewhat beyond me. I honestly don't understand half of it (due to seriously poor formatting mostly), and have never used the '$' operator myself (have heard bad things, can't remember what though).

If what i can remember (and am observing about it), the following could work.
var id = $.id;
But as i'm almost certain it won't, as a back-up, i noticed the use of the 'e' parameter in the function definitions. Typically, when dealing with events, that is used to pass data about the event. Thanks to quirksmode.org's extensive event handling tutorials, specifically the one on event properties, i've put this together.
// This would go inside the mousedown event handling function i believe.
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	var id = targ.id;


#4 adamfran

    Young Padawan

  • Members
  • Pip
  • 91 posts

Posted 24 May 2007 - 10:02 AM

No, both of them seem dont seem to work :)

#5 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 24 May 2007 - 11:36 AM

What exactly are you trying to do? I have some jQuery experience, but I'm missing your point here...

#6 adamfran

    Young Padawan

  • Members
  • Pip
  • 91 posts

Posted 24 May 2007 - 01:09 PM

Using the plugin jqDnR for jQuery, I am using the plugin to resize divs.

The divs are being called from the database, but when the user resizes the div - I want it to update the size through ajax (that side I know) but to update the div in the database, I need the id of the div (and the id of the div relates to the database row number) and thats the part I'm stuck on as I cant seem to find a way to get the div id.

Hopefully thats a bit better explanation than my last post.

#7 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 24 May 2007 - 01:33 PM

You have a working copy online?

#8 adamfran

    Young Padawan

  • Members
  • Pip
  • 91 posts

Posted 24 May 2007 - 01:58 PM

There is an example located on their website here:

http://dev.iceburg.net/jquery/jqDnR/

#9 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 25 May 2007 - 07:04 AM

Well, I have seriously tried but can't get it to work. I hate saying this, but this is beyond me. I'll continue looking into it, but nothing guaranteed.

#10 adamfran

    Young Padawan

  • Members
  • Pip
  • 91 posts

Posted 25 May 2007 - 09:35 AM

Thanks! Greatly appreciated...

I've treid contacting the owner and also on various other sites...but no-one seems to either answer or find out how to do it.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users