Is there any possibility to disable this feature so that the text in
the header never gets selected?
You could place an absolute positioned div within a relative positioned div
(which contains your heading) then use a 100% height by 100% width blank
image in the absolute div as your link (onclick) anchor.
This would also have the advantage of making the entire heading container
clickable and not just the text.
If you need me to mock up a working example, let me know.
Andy
Yes. That is how browsers work.
> Is there any possibility to disable this feature so that the text in
> the header never gets selected?
No.
Well, acutally, not with HTML but there is a way with heaps of javascript
but why does this actually give you a problem?
Sounds great.
I'd appreciate it very much if you could post a working example.
> "Stefan Mueller" <seek...@yahoo.com> wrote in message
> news:4d3504c9-aa43-402d...@r24g2000yqd.googlegroups.com...
>> I've a HTML table with several columns. If you click on the header of
>> a column the appropriate column gets sorted.
>> If you move the mouse while clicking the header or you even double
>> click the header the text in the header gets selected.
>
> Yes. That is how browsers work.
Really? Are you sure you are referring to web browsers and not some
spreadsheet programs?
When I mouse over or click on a column header, nothing happens, unless
there's a link there, or something. If I double click on it, a word gets
selected - nothing more. If I triple click, the entire header gets selected.
Still no sorting - and I really don't expect any sorting, as how could a
stupid wowser know that the user wants to sort? How could it figure out the
sorting order?
>> Is there any possibility to disable this feature so that the text in
>> the header never gets selected?
>
> No.
Huh? How do you _enable_ it in the first place?
--
Yucca, http://www.cs.tut.fi/~jkorpela/
> rf wrote:
>
>> "Stefan Mueller" <seek...@yahoo.com> wrote in message
>> news:4d3504c9-aa43-402d...@r24g2000yqd.googlegroups.com...
>>> I've a HTML table with several columns. If you click on the header of
>>> a column the appropriate column gets sorted.
>>> If you move the mouse while clicking the header or you even double
>>> click the header the text in the header gets selected.
>>
>> Yes. That is how browsers work.
>
> Really? Are you sure you are referring to web browsers and not some
> spreadsheet programs?
Get a grip. Rf is obviously referring to the selection behavior, not
to the sorting behavior.
sherm--
There's nothing obvious in it. "Rf" quoted text that discussed both things,
so it is fair to expect that he commented on both of them, not just one part
of the second thing - especially since "rf" did not in any way indicate
otherwise. In adequate quoting, you quote only the part that is necessary
for indicating what is commented on.
Besides, in normal browsers, double clicking selects a word - it takes a
triple click to select a larger part of text. For a single-word header,
there is no difference, but the discussion was at a general level, and at
the general level, the common browser behavior is that the clicked _word_
gets selected.
--
Yucca, http://www.cs.tut.fi/~jkorpela/
> rf wrote:
>
> > "Stefan Mueller" <seek...@yahoo.com> wrote in message
> > news:4d3504c9-aa43-402d...@r24g2000yqd.googlegroups.com...
> >> I've a HTML table with several columns. If you click on the header of
> >> a column the appropriate column gets sorted.
> >> If you move the mouse while clicking the header or you even double
> >> click the header the text in the header gets selected.
> >
> > Yes. That is how browsers work.
>
> Really? Are you sure you are referring to web browsers and not some
> spreadsheet programs?
>
The OP gave no url and it is hard to know what he was referring to,
perhaps he is somehow involved in a page with scripting? Certainly no
web browser simply sorts anything. The only other column/row sorting way
is to make things in the TH links to other html pages where the items
are differently (statically) arranged (I did this static once so people
could look at Australian towns by postcode or by alphabetical order)
> When I mouse over or click on a column header, nothing happens, unless
> there's a link there, or something. If I double click on it, a word gets
> selected - nothing more. If I triple click, the entire header gets selected.
> Still no sorting - and I really don't expect any sorting, as how could a
> stupid wowser know that the user wants to sort? How could it figure out the
> sorting order?
>
> >> Is there any possibility to disable this feature so that the text in
> >> the header never gets selected?
> >
> > No.
>
> Huh? How do you _enable_ it in the first place?
Good question and exactly what I was thinking too. OP is not telling us
something!
--
dorayme
> Sherm Pendley wrote:
>
>> "Jukka K. Korpela" <jkor...@cs.tut.fi> writes:
>>
>>> rf wrote:
>>>
>>>> "Stefan Mueller" <seek...@yahoo.com> wrote in message
>>>> news:4d3504c9-aa43-402d...@r24g2000yqd.googlegroups.com...
>>>>> I've a HTML table with several columns. If you click on the header
>>>>> of a column the appropriate column gets sorted.
>>>>> If you move the mouse while clicking the header or you even double
>>>>> click the header the text in the header gets selected.
>>>>
>>>> Yes. That is how browsers work.
>>>
>>> Really? Are you sure you are referring to web browsers and not some
>>> spreadsheet programs?
>>
>> Get a grip. Rf is obviously referring to the selection behavior, not
>> to the sorting behavior.
>
> There's nothing obvious in it.
It's patently obvious to anyone who doesn't have a preconceived notion
that everyone else in the world is a drooling moron, and a pathological
need to "prove" it.
Like I said - get a grip.
sherm--
...
> It's patently obvious to anyone who doesn't have a preconceived notion
> that everyone else in the world is a drooling moron, and a pathological
> need to "prove" it.
>
> Like I said - get a grip.
Sherm! This is really way out of line, you are being so horrid and
unfair! JK has done nothing at all in this thread to deserve this.
--
dorayme
Get a grip dorayme. JK is a fucking pedantic idiot and this thread simply
proves it.
>> Huh? How do you _enable_ it in the first place?
>
> Good question and exactly what I was thinking too. OP is not telling us
> something!
Move mouse to somewhere over some text. Press mouse button. Move mouse.
Release mouse button. Admire selected text. Pretty bloody obvious to me.
He is not being any more pedantic than any reasonable poster might be
nor idiotic, and this thread proves no such thing.
Formerly, you did nothing wrong, it was a simple matter of you probably
saying something true (as you often do) but it was unclear enough to
justify what was a perfectly polite and ordinary querying response from
JK.
Sherm was extraordinary in his vituperation and you are now surprising
me no end! Don't you scripting guys ever forgive and forget? You are
both misreading him on this occasion and being unfair. If you have
gripes from the past, keep them as ammo and dry for where they might be
more appropriate.
A grip? I know a dirty variation on an advertizing jingle for an
Australian glue called Tarzan's Grip, it used to go:
"Get a tube of Tarzan's Grip"
--
dorayme
Not in the original context and mixed up with changes of order... It is
amazing how things appear to you if you know what you mean and also in
hindsight to others...
As it happens, clicking and moving mouse does *not* guarantee the text
gets selected, you have to do a certain amount of moving. Just think
about it in detail: The OP talks about moving the mouse possibly in the
context of column sorting so maybe someone reading this is simply not
thinking "ah text selection!" Text selection requires a bit more than
just moving the mouse a bit. What has text selection got to do with
anything? Why is selection needing to be disabled?
--
dorayme
Bullshit. Nothing is unclear. The subject of this thread is "How to diable
the feature to select a text". How bloody unclear is that? The OP doesn't
want text selected. Now, read the OPs further words:
"the text in the header gets selected" and "is there any possiblility do
disable this feature so the text [in the header] never gets selected".
Selected. How does text get selected? By clicking and moving the mouse, just
like it gets selected in just about every bloody program out there. The OP
doesn't want that. That was what I was commenting on, not the bloody price
of tea.
So, we are clearly talking about selecting text here. I have no fucking idea
what Korpella was talking about, except that in his usual pedantic way he
comes over as a complete arsehole.
> So, we are clearly talking about selecting text here. I have no fucking
> idea what Korpella was talking about, except that in his usual pedantic
> way he comes over as a complete arsehole.
And here are you defending him.
Does the word "select" have any meaning to you? The OP is complaining about
text being "selected". How the bloody hell can text be selected if one has
not moved the mouse far enough to select text? And if the OP has not moved
the mouse far enough to have selected text then why would he be complaining
about text being selected?
Arguing for the sake of arguing I think. You are becoming as big a bloody
pedant as Korpela is.
> JK is a fucking pedantic idiot and this thread simply
> proves it.
I wouldn't say he's an idiot. Quite the opposite in fact - I think he's
smarter than most of the people here, including me. He is, however,
very badly lacking in people skills.
sherm--
> Bullshit. Nothing is unclear. The subject of this thread is "How to diable
> the feature to select a text".
It is an odd thing to announce this as *a feature*, it is so second
nature. If someone asks, how do you turn the sun off, you don't simply
go on to answer (unless, maybe, you are Superman). It just seems
surprising! Bundled with column sorting (the other thing mentioned
practically in the first breath of the OP's post), I say it can create a
haze in which normally intelligent beings can get a bit disorientated.
...
> I have no fucking idea
> what Korpella was talking about, except that in his usual pedantic way he
> comes over as a complete arsehole.
He did not, you must be thinking of other threads and it is influencing
you. A bit of pedantry is not so bad and it needs to be contrasted with
its opposite - please God, let someone ask me what the opposite of
pedantry is - to get a better appreciation of it. I think pedantry has
had an altogether unfair press for a long time. Pedantry does not make
for arseholiness all by itself. Be fair, Richard!
--
dorayme
You really did not give us enough to go on, certainly a URL would have
helped, and here you got some of the best regulars around here not being
very nice to each other.
So, I'm going to put on my crystal ball hat and guess at what you are
trying to do/not do.
1. You cannot sort an HTML table without some kind of client side or
server side scripting invovled. Simply clicking on text will indeed
select it - that is the way it's supposed to be.
2. There is probably a href somewhere that uses a querystring to tell
either the server side script or a client side script to sort the data
when that link is clicked. Perhaps something like
http://example.com/table.php?sort=1
If it is clearly a link, then users will click on it. If it is not
clear, and they are clicking somewhere else, you might have that select
text behaivor.
Really, without a URL it is impossible for me to go any further.
--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
> "dorayme" <dorayme...@optusnet.com.au> wrote in message
> news:doraymeRidThis-8A2...@news.albasani.net...
...
> >>
> >> Move mouse to somewhere over some text. Press mouse button. Move mouse.
> >> Release mouse button. Admire selected text. Pretty bloody obvious to me.
> >
...
>
> Does the word "select" have any meaning to you? ...
I was thinking of your words not the OP's at this point. I followed your
instructions and nothing happened. I trusted you!
>
> Arguing for the sake of arguing I think.
er... maybe a little with you yes... <g>
But I was really pissed off when I saw Sherm be so incredibly reactive
(to put it politely). I have nothing against Sherm, he uses Macs, his
seemed like such an unnecessarily angry response.
Plus, I don't like to see someone who has contributed so magnificently
to the world of HTML and CSS be hounded when he is *not* doing anything
to deserve it. This is 21st Century, not the 13th. Why don't you and
Sherm grab Jerry Stuckle and have some fun with him, he always deserves
the stocks and rotting tomatoes thrown at him...
Around Xmas maybe a little more anger management, lads!
> You are becoming as big a bloody
> pedant as Korpela is.
That is a horrible thing to say! He is not even in my league in this
pedantry business, he is too serious for that and every year I get the
silver cup... <g>
--
dorayme
You should talk, Mr Diplomacy Who Began All This! <g>
--
dorayme
The practice shows that if you click on the header row to sort the
columns to often a letter or even the whole text in the header row of
the columns gets selected.
Now I'm trying to find a way to disable this "selection feature".
I think that Andy's suggestion could be the solution for my problem:
You could place an absolute positioned div within a relative
positioned div (which contains your heading) then use a 100% height by
100% width blank image in the absolute div as your link (onclick)
anchor.
But it's not working so far. Any additional help is very welcome.
Stefan
Hi Stefan,
I've created a mock up for you...
http://www.microbuild.com/test/unselectable_heading.html
Hope this helps
Andy
Probably not ...
http://edmullen.net/temp/selected.jpg
--
Ed Mullen
http://edmullen.net
Everyone hates me because I'm paranoid.
> I have no fucking idea what Korpella was talking about,
You have made your cluelessness in such and other matters quite clear.
> except that in his
> usual pedantic way he comes over as a complete arsehole.
It remains to make my usual request that you keep using the same
anonymousness and forged address as long as you remain an insulting coward
in addition to not understanding what is being discussed.
--
Yucca, http://www.cs.tut.fi/~jkorpela/
Untested guess, but there is a DOM 2 method Event.preventDefault() which
might work.
You just call it in your event listener (the one you're using to do the
sorting etc.) on the event object.
> Sorry for my unclear and confusing posting.
An apology will not be accepted before you post a URL.
> Yes, of course, a normal HTML table is not sortable by clicking on its
> header row
Well, that's how things are, but they _could_ be otherwise, so it's not
really an "of course" matter. Browsers could be clever; they just aren't.
> and in that case I wouldn't care about the "selection feature".
In what case?
> I'm using javascript to make the HTML table sortable. Therefore you
> can click on the header row to sort the columns.
I think many people guessed that, but we cannot really guess _how_ you make
that. It depends on your JavaScript code what is really clickable.
> The practice shows that if you click on the header row to sort the
> columns to often a letter or even the whole text in the header row of
> the columns gets selected.
It does not happen in normal circumstances. As I wrote previously, double
click normally selects a word, triple click selects the content of a cell.
So what are really doing to cause what you describe? Or are you using some
special browser?
> Now I'm trying to find a way to disable this "selection feature".
Why? The URL might reveal us why it is a problem (and how the real problem
might be solvable).
> You could place an absolute positioned div within a relative
> positioned div (which contains your heading) then use a 100% height by
> 100% width blank image in the absolute div as your link (onclick)
> anchor.
It's rather pointless to make random attempts at solving a problem that has
not been identified.
--
Yucca, http://www.cs.tut.fi/~jkorpela/
Ed, me 'ol china.
Not sure what browser you're using but I tested my code in IE8 and FF.
I think you're actually selecting everything in your image as if you had
placed your pointer in the top left corner, click-hold and dragged it down
to the bottom right as you appear to have selected the whole heading row and
not just the text.
Try selecting a portion of a heading TEXT (eg HEADING >ING O< NE) which will
confirm that in your browser you can select the heading TEXT.
Andy
It doesn't matter how I sort the table. You just click on the header
row and the table gets sorted with a javascript. However, that's not
my problem.
My "problem" is that if you click on the header of the table the text
in the header sometimes gets selected. This happens for example if you
want to sort a column descending. With the first click the table gets
sorted ascending and with a second click it gets sorted descending
(same behavior like in the Windows Explorer).
When you do these two clicks quick fast it gets identified as a
doubleclick and the header word gets selected.
That's no problem for the sort function because at the end the table
is sorted descending but the table header doesn't look so nice because
its text is selected.
I'm just looking for a way to avoid this selection and I think with
Andy's solution I'm on the right way. Many thanks, Andy!
However, in Opera you can drag the header out of the browser. That's
somehow strange.
I have to do some further testing. At the moment e.g. I don't
understand the purpose of 'rule.gif'.
I'm also thinking if with this method it could be possible to prevent
the header row from being clicked while a large table gets sorted
(sort time e.g. 5 seconds)?
Stefan
> English is not my native language - what you've surely realized.
Why should that matter? It's more serious that you don't know how to quote
and that you don't post a URL.
> But is it really so hard to understand what I'm talking about?
Yes, because you did not post a URL.
We may have a rough idea of what you are doing, but you resist our attempts
at helping you.
HAND. HTH.
--
Yucca, http://www.cs.tut.fi/~jkorpela/
> English is not my native language - what you've surely realized.
> But is it really so hard to understand what I'm talking about?
No, Jukka's just being a jerk as usual. It's clear as day to the rest
of us.
> I'm just looking for a way to avoid this selection and I think with
> Andy's solution I'm on the right way. Many thanks, Andy!
> However, in Opera you can drag the header out of the browser.
Allowing foreground images to be dragged to the desktop is common
behavior for GUI browsers.
Starting with Andy's example I'd make the "mask" GIF a background for
the inner div instead of using an img for it, because background images
are typically not draggable.
> I'm also thinking if with this method it could be possible to prevent
> the header row from being clicked while a large table gets sorted
> (sort time e.g. 5 seconds)?
In your JS sorting function, check the value of a flag variable, for
example "isSorting". If it's 1, don't begin a new sort. Otherwise, set
it to 1, begin a new sort, then set it back to 0 when the sort is done.
sherm--
> Stefan Mueller <seek...@yahoo.com> writes:
>
>> I'm just looking for a way to avoid this selection and I think with
>> Andy's solution I'm on the right way. Many thanks, Andy!
>> However, in Opera you can drag the header out of the browser.
>
> Allowing foreground images to be dragged to the desktop is common
> behavior for GUI browsers.
>
> Starting with Andy's example I'd make the "mask" GIF a background for
> the inner div instead of using an img for it, because background images
> are typically not draggable.
Also, since removing the img leaves nothing for the a to wrap around,
I'd move the call to the sort function into an onClick handler on the
inner div.
For example:
<http://download.camelbones.org/testpage/unselectable_heading.html>
sherm--
As Ed stated, just how is your example not selectable?
<http://www.littleworksstudio.com/temp/usenet/alt.html.20091222.jpg>
--
Take care,
Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
> Sherm Pendley wrote:
>
>> For example:
>>
>> <http://download.camelbones.org/testpage/unselectable_heading.html>
>
> As Ed stated, just how is your example not selectable?
>
> <http://www.littleworksstudio.com/temp/usenet/alt.html.20091222.jpg>
I never claimed it was perfect! :-) Given the nature of web browsers,
there's no foolproof way to completely prevent a user from selecting
the header text - *especially* a user who's technically inclined and
determined to do so.
An imperfect solution can still be useful though. The method shown does
help keep a user from accidentally selecting the header text. That's
pretty much the best that can be achieved here.
sherm--
First of all I did nothing special, I just dragged and selected, your
"fix" did nothing at all. Secondly, the point is it is a fool's errand,
it is just not how HTML works. I guess the OP could use Flash if he
wishes to "defeat the user"...
> Sherm Pendley wrote:
>> "Jonathan N. Little"<lws...@gmail.com> writes:
>>
>>> Sherm Pendley wrote:
>>>
>>>> For example:
>>>>
>>>> <http://download.camelbones.org/testpage/unselectable_heading.html>
>>>
>>> As Ed stated, just how is your example not selectable?
>>>
>>> <http://www.littleworksstudio.com/temp/usenet/alt.html.20091222.jpg>
>>
>> I never claimed it was perfect! :-) Given the nature of web browsers,
>> there's no foolproof way to completely prevent a user from selecting
>> the header text - *especially* a user who's technically inclined and
>> determined to do so.
>>
>> An imperfect solution can still be useful though. The method shown does
>> help keep a user from accidentally selecting the header text. That's
>> pretty much the best that can be achieved here.
>
> First of all I did nothing special, I just dragged and selected, your
> "fix" did nothing at all.
I heard you the first time, and as I said - I'm aware that it's not a
perfect solution. Still, double- or triple-clicking doesn't select
text, nor does dragging that's limited to inside the header. Nor can
the "shield" image be accidentally dragged onto a user's desktop. It
isn't perfect, but it's helpful nonetheless. Sometimes that's the best
we can achieve.
Did you read Wired's recent story about Duke Nukem Forever? The game's
producer was so focused on creating the "perfect" game that he refused
to ship anything less. As a result, they ended up not shipping anything
at all.
sherm--
Jonathan's right. The second example has lost something. One can select
text normally there. On the first example from Andy, attempting to select
the heading text from the vicinity of the headings themselves fails,
because you end up dragging an image instead. (However, on the first
example, the heading text is still selectable by selecting any area above
or below the headings and dragging over the headings, too.)
--
"Because all you of Earth are idiots!"
¯`·.¸¸.·´¯`·-> freemont© <-·´¯`·.¸¸.·´¯
> Did you read Wired's recent story about Duke Nukem Forever? The game's
> producer was so focused on creating the "perfect" game that he refused
> to ship anything less. As a result, they ended up not shipping anything
> at all.
Darwin nearly went the same way...
--
dorayme
Then after you have finished sorting remove any selection from the page,
usually done by obtaining the selection and collapsing it.
http://www.quirksmode.org/dom/range_intro.html has a good discussion about
ranges and how they work in different browsers (IE and all others).
Agreed. And, I wonder if it's really worth the effort. Also, if I have
javascript turned off in my browser? It's all a moot point.
I finally realized (I think) what the OP was concerned about. That a
user whose mouse skills are challenged might move the mouse while
clicking a column heading to sort the table and, inadvertently, select
some text.
So what? What's the harm? Oh, ok, it might offend my or the OP's sense
of elegeance in application. Still? In this case isn't the cure maybe
worse than the disease?
--
Ed Mullen
http://edmullen.net
Funny, I don't remember being absent minded.
> I wonder if it's really worth the effort.
For my own site, I wouldn't bother. But I was bored today, and it was
a mildly interesting diversion. :-)
> Also, if I
> have javascript turned off in my browser?
That's one advantage of the approach that uses image links rather than
background images and an onClick handler. The link could default to
calling a server-side script that would regen the whole table, and only
do it client-side if the client were willing and able to do so.
On the other hand, if you've already made the decision (or it's been
made for you) to require JS for the sort function, there's no additional
penalty to be paid for calling it from an onClick() handler instead of
a javascript: link. In for a penny, in for a pound, as the saying goes.
sherm--
> I finally realized (I think) what the OP was concerned about.
You mean it was not completely obvious from the very beginning? I wonder
if that makes you a jerk etc etc etc... <g>
> That a
> user whose mouse skills are challenged might move the mouse while
> clicking a column heading to sort the table and, inadvertently, select
> some text.
>
> So what? What's the harm? Oh, ok, it might offend my or the OP's sense
> of elegeance in application. Still? In this case isn't the cure maybe
> worse than the disease?
Don't ask all these difficult and pertinent questions Ed, it could lead
to pedantry...
That reminds me of something else that could lead to something:
<http://dorayme.netweaver.com.au/jokes/dancing.html>
--
dorayme
An unkind cut but, on reflection, perhaps not unwarranted.
>
>> That a
>> user whose mouse skills are challenged might move the mouse while
>> clicking a column heading to sort the table and, inadvertently, select
>> some text.
>>
>> So what? What's the harm? Oh, ok, it might offend my or the OP's sense
>> of elegeance in application. Still? In this case isn't the cure maybe
>> worse than the disease?
>
> Don't ask all these difficult and pertinent questions Ed, it could lead
> to pedantry...
I'm sorry. It's a character flaw of mine.
>
> That reminds me of something else that could lead to something:
>
> <http://dorayme.netweaver.com.au/jokes/dancing.html>
>
Ah, yes! The old "One thing leads to another" conundrum!
Hmm. Uh ... Oh my. I need to go take a rest now. I feel that I may
need to be dancing soon.
--
Ed Mullen
http://edmullen.net
Always proofread carefully to see if you any words out.
> dorayme <dorayme...@optusnet.com.au> writes:
>
> > In article <m27hseo...@shermpendley.com>,
> > Sherm Pendley <spam...@shermpendley.com> wrote:
> >
> >> Did you read Wired's recent story about Duke Nukem Forever? The game's
> >> producer was so focused on creating the "perfect" game that he refused
> >> to ship anything less. As a result, they ended up not shipping anything
> >> at all.
> >
> > Darwin nearly went the same way...
>
> The OS? Or Charles? Not sure what you mean.
>
Charles... he delayed publishing till his hand was forced by a
surprising event...
--
dorayme
> In article <m2r5qmx...@shermpendley.com>,
> Sherm Pendley <spam...@shermpendley.com> wrote:
>
>> dorayme <dorayme...@optusnet.com.au> writes:
>>
>> > In article <m27hseo...@shermpendley.com>,
>> > Sherm Pendley <spam...@shermpendley.com> wrote:
>> >
>> >> Did you read Wired's recent story about Duke Nukem Forever? The game's
>> >> producer was so focused on creating the "perfect" game that he refused
>> >> to ship anything less. As a result, they ended up not shipping anything
>> >> at all.
>> >
>> > Darwin nearly went the same way...
>>
>> The OS? Or Charles? Not sure what you mean.
>
> Charles... he delayed publishing till his hand was forced by a
> surprising event...
You know, one of the projects I worked on while at PBS was the web site
for the Evolution miniseries. I *really* should have known that... :-(
sherm--
Sherm Pendley wrote:
> In your JS sorting function, check the value of a flag variable, for
> example "isSorting". If it's 1, don't begin a new sort. Otherwise, set
> it to 1, begin a new sort, then set it back to 0 when the sort is done.
Good idea but unfortunately it doesn't work.
You click on the header, isSorting is 0, will be set to 1 and the
sorting begins.
If you click now another header (while the sorting is performing) the
browser caches your click and is not able to check the value of
isSorting.
When the sorting has finished, isSorting will be set to 0. Now the
browser does what's in his cache. The next sorting starts.
Visual Basic knows the command DoEvents which passes control to the
operating system. Control is returned after the operating system has
finished processing the events in its queue and all keys in the
SendKeys queue have been sent.
No idea if there exists a similar command in javascript.
Stefan
I didn't know that would happen. But something like this might fix it:
var isSorting = false;
function sortCol(col)
{
...
isSorting = false;
}
function clickHandler(event)
{
if (isSorting) return;
isSorting = true;
...
setTimeout(function() {sortCol(col);}, 1);
}
If that doesn't work, you could do something like this:
var sorting = [0, 0];
function clickHandler(event)
{
if (event.timeStamp > sorting[0] && event.timeStamp < sorting[1])
return;
sorting[0] = event.timeStamp;
// sort the column here...
sorting[1] = Date.getTime();
}
On the assumption that the event's timestamp reflects when you actually
clicked, which it should really, not when the event started to get
processed.
Hi Stefan,
I have now come up with another solution which is both simple and elegant.
I've only tested it in IE and FF so you'll have to wait and see if it gets
shot down by the nay-sayers ;)
Anyhoo, here's the link...
http://www.microbuild.com/test/unselectable_table.html
... the secret is in the <table> element although you could apply it to the
<body> element to make none of the page selectable.
Andy
The solution with 'setTimeout' doesn't work in my case because the
browser doesn't react to any click while the sort function is running
(even if I use 'setTimeout' for the sort function).
However the solution with the time stamp is quite good. Many thanks!
At the end of the sort function I do
sort_end_time = new Date().getTime();
and at the beginning of the sort function I check how much time has
passed after the sort function finished last time
if ((new Date().getTime() - sort_end_time) > 300) {
In this example you have to wait 300 milliseconds before you can sort
the next column. Therefore if you click on a column before the running
sort function has finished doing its job the value of '(new Date
().getTime() - sort_end_time)' is less than 300 milliseconds and the
clicked column will not get sorted.
The problem I have now is that when the last javascript command
'sort_end_time = new Date().getTime();' is executed the browser needs
some time to redraw (refresh) the table on the screen. If the table
has only a couple of rows then it takes only some milliseconds but if
the table has e.g. 2000 rows it takes in IE more than 1000
milliseconds.
Therefore the result of '(new Date().getTime() - sort_end_time)' is
always greater than 300 milliseconds.
Is there any possibility, any event where I can execute the command
'sort_end_time = new Date().getTime();' just after the browser is
ready again (after the refresh)? In my case the command 'sort_end_time
= new Date().getTime();' is executed before the browser starts the
redraw (refresh).
Stefan
Great, you example works perfect in IE and FF.
Unfortunately it doesn't work in Opera. No idea why but I can live
with it.
Many thanks
Stefan
A number of things don't work well in Opera, best css-parsing browser
or not. That could be why it's barely 1% popular, if still that.
--
Neredbojias
http://www.neredbojias.org/
http://www.neredbojias.net/
On your computer... It's very difficult to say what can be achieved in
300ms of wallclock-time generally. It depends on the machine and also on
what else it's doing.
> Therefore the result of '(new Date().getTime() - sort_end_time)' is
> always greater than 300 milliseconds.
>
> Is there any possibility, any event where I can execute the command
> 'sort_end_time = new Date().getTime();' just after the browser is
> ready again (after the refresh)?
I don't think there's anything that can be reliably used for that.
> In my case the command 'sort_end_time
>= new Date().getTime();' is executed before the browser starts the
> redraw (refresh).
I think it's not worth pursuing the approach of building in hard time
limits anyway. That's why I was hoping event.timeStamp would work. But
it sounds like someone else posted a better solution altogether.
> I've created a mock up for you...
>
> http://www.microbuild.com/test/unselectable_heading.html
>
> Hope this helps
Many thanks. It works perfect in IE and FF but unfortunately not in
Opera. In Opera you can move the header title to the desktop.
Stefan
Have you considered placing the header text onto a button? After all, a
button truly represents the behaviour you want; something which can be
clicked to generate an event. The button can be styled to not look like
a button, and whilst some browsers may still allow the text on the
button to be selected, I don't think any will select the text from
ordinary clicks or doubleclicks; which seems to be the focus of your
problem.
You might even be able to take advantage of the ability to disable a
button to prevent it being used at times; although I'm not sure that the
way events are processed by a browser will help in your desire to
disable further clicks whilst sorting is in progress since the click
will probably still be picked up after the sorting handler returns
control to the browser; perhaps a timeout-controlled flush after a sort
could fix that (i.e. ignore any clicks received within 0.5s of the sort
routine ending).
Stefan
Hi Stefan,
I did make an updated version, but nobody commented on it...
http://www.microbuild.com/test/unselectable_table.html
... I think my post just got lost in the sea of other posts.
Andy