Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28465
| From | "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Move a div with mouse |
| Date | 2015-07-24 21:58 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <mou5ap$180$1@dont-email.me> (permalink) |
| References | <mola7b$fmu$1@dont-email.me> <24793803.Cl0v73UULg@PointedEars.de> |
Il 07/24/2015 08:36 PM, Thomas 'PointedEars' Lahn ha scritto:
> danca (Daniele Campagna) wrote:
>
>> I needed to solve an old stupid issue regarding an <iframe> (aka a <div>
>> containing an <iframe>) that sometimes is misplaced in a page [served by
...
>>
>> After many hours searching, studying, testing and tinkering with Firefox
>> and IE I ended up with this function:
>
> First of all, your code (style) is barely readable. If you want others to
> review your code, you should employ a code style that is easily readable.
> A decent code editor can help with that.
:-(
>
> Particularly for Usenet, you should post code that still works when word-
> wrapped at about the 72th text column. See the FAQ.
I TRIED to copy-and-paste and then to adjust the [horrible] result.
>
>> // usage: makeMovable(<id of the div to drag>,<optional id of a
>> "handler" (f.e. a small image inside the div) to drag the div>)
>
> This code was word-wrapped by your newsreader and does not work anymore
> because of that. It would not have happened had you used /*… */ instead,
> which I recommend for documentation comments.
>
OK.
>> var makeMovable = function(target, handle) {
>> target = document.getElementById(target);
>> if (!handle) handle = target; else
>> handle=document.getElementById(handle); if (document.addEventListener){
>>
>> handle.addEventListener("mousedown",function(event){e=event||
> window.event;if
>> (e.preventDefault) e.preventDefault(); else e.returnValue = false;})
>
> Wrong. You are testing “document.addEventListener”, but you are calling
> “handle.addEventListener” – a different method. Test exactly that which you
> will be using, and test for callable objects to be callable, not merely
> existing. In particular, do not subject methods of host objects to simple
> type-converting tests; this is error-prone (search for “isHostMethod”).
So it is not correct to infer[It exists? I mean make a deduction] that
if document.addEventListener does not exist <something>.addEventListener
couldn't instead exist? Hummmmm...
(Ubi major minus cessat).
>
>> }else{
>>
>> handle.attachEvent("onmousedown",function(event){e=event||window.event;if
>> (e.preventDefault) e.preventDefault(); else e.returnValue = false; })
>> }
>> handle.onmousedown = function(event) {
>
> It makes no sense to use one of EventTarget::addEVentListener() from the W3C
> DOM and eventTarget.attachEvent() from the MSHTML DOM, *and* subsequently
> EventTarget::onmousedown from the Netscape/HTML5 DOM. See my tests about
> the side effects of using both from earlier this year, and
> jsx.dom.addEventListener() for the correct approach.
OMG. Ok, I'll take a look.
>
>> […]
>> }else{ alert("no event")// just in case}
>
> This may be a syntax error. Your code is so unreadable that it is difficult
> to tell without copying and reformatting it.
>
>> document.onmouseup = function() {
>> document.onmousemove = null;
>> document.onmouseup = null;
>> }
>
> Nonsense.
Ehm... it should cancel the event listeners - and it seems to work in IE
and FF. What's wrong with canceling eventListeners that simple way?
>
>> […]
>> So, JFC,
>
> You want to refrain from cursing when asking a question.
>
> See also <http://www.catb.org/~esr/faqs/smart-questions.html>.
>
>> why this does not work with those 2 browsers?
>
> You are still under the misconception that it would be prudent to think in
> terms of browsers instead of DOM implementations.
>
NoNo, I am not thinking at all. I just reported the thing. What the
hell, I didn't tried browser sniffing at all, and I simply can't imagine
what feature detection I should put on to distinguish between the
[working] IE and FF and the [aliens] Chrome and Safari.
I exhausted all my thinking capabilities in the hours I tried to make it
work. Now I am void of ideas - and this is the reason I bother people in
this NG.
Anyway thanks for your time - but, an idea about the fact that Chrome
and Safari seem to dislike my code is still to come, while an idea about
why you dislike it has been clearly expressed. :-)
Dan
--
"Everybody should pay taxes with a smile"
I tried, but they want money.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Move a div with mouse "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-21 13:26 +0200
Re: Move a div with mouse Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-24 20:36 +0200
Re: Move a div with mouse "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-24 21:58 +0200
Re: Move a div with mouse Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-25 14:07 +0200
Re: Move a div with mouse "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-25 19:47 +0200
Re: Move a div with mouse Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-25 20:54 +0200
Re: Move a div with mouse "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-26 12:54 +0200
Re: Move a div with mouse Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-26 13:36 +0200
csiph-web