« first day (381 days earlier)      last day (4573 days later) » 

12:00 AM
that's what the comma is for, though it is generally considered better to declare them outside the loop
 
I see. thank you very much!
 
Huh, apparently "Zero or more tbody elements" are allowed
 
well that stinks :\
 
in html5, at least
 
@Dennis hm... just tested the syntax... seems it isn't within the scope of the loop
 
12:06 AM
According the w3c documentation - multiple tbodys are allowed, but you can only have 1 thead and 1 tfoot
 
Thanks for the info and sorry for the trouble... After considering it, I probably should have been able to find that. :S
scope difference for for loop: jsfiddle.net/uB7pE vs jsfiddle.net/uB7pE/1
 
There is no block scope in JS
 
I thought that was the whole point of the var in for(var i=0; i<5; i++) :\
oh well yet another concept learned
 
@Dennis yes. Its a pain. but tahts not how it works
The browser vendors will inject a <tbody> for you in the <table>
There is no block scope
for (var k = 0; k < 10; k++) { } is just convenience
writing :
 
Right, but the question was "can I have two tbody elements"
 
12:18 AM
var k = 0;
for (k;k < 10;k++) {}
Is a pain
Ah I see
Well you can have as many tbodies as you want
> The tbody element represents a block of rows that consist of a body of data for the parent table element, if the tbody element has a parent and it is a table.
Having multiple <tbody>'s make sense in pagination of tables.
Althought I don't know whether its more sensible to have the tbodys in the DOM but hidden or whether its more sensible to have them as detached nodes in some array
Or I guess any other kind of grouping of rows you want to do in a table
 
0
Q: Optimizing my CSS selector library

minitechI've made a selector library at https://github.com/minitech/Sprint.js and it appears to be much slower than jQuery on the ID selectors #test and #test2, and on the selector *. Can anyone point out some optimizations that could be made to make it faster?

 
@Raynos thanks for those explanations :)
 
1:11 AM
0
Q: What structure is best used to model maps for games like Bard's Tale / Dungeon Hack

Landstander(First off, if anyone can tell me what this type of 3d engine may be called or fill me in on better terms than 'cube 3d engine' it might help me in my search for information.) I would like to create or use an existing Javascript engine to build a game in the spirit of Dungeon Hack, Eye of the Be...

 
1:52 AM
hm... I don't suppose you're up to code review this late, @Raynos?
anyone on who can answer a best practices question?
 
 
8 hours later…
9:36 AM
@Joseph what is it?
 
10:00 AM
0
Q: Javascript canvas animation slowing down and hogging memory

xaddictI'm experimenting with moving shapes in javascript with a canvas tag. I have one half circle (only stroked) which rotates on set intervals. I've written the code so many more can be added. I can give starting rotations and a lot of other handy parameters. I've tried this with twelve circles an...

 
 
1 hour later…
11:00 AM
0
Q: Can some one please tell me what is wrong with my plugn?

phantom.omagatwo days back a made a plugin that allows me to insert toggle box in to the post with the short code [toggle Title="My title"]toggle test[/toggle] i also posted my plugin on wordpress.org plugins http://wordpress.org/extend/plugins/toggle-box/. The Problem i made the whole plugin on san...

 
yay, without even doing anything for it
That happens when you let someone in the US design a map of "the rest of the world"
 
 
1 hour later…
12:20 PM
@IvoWetzel :(
 
12:53 PM
@Raynos I was wondering about attaching click events. I know there are several ways to do it, but I would like to know what is the best conventionally
 
el.addEventListener("click", function _callback(ev) {
  // like a boss
});
 
@Raynos Thanks :)
 
@Joseph disclaimer .addEventlistener does not work in IE<9
disclaimer 2: DOM-shim only fixes .addEventListener in IE8
 
oh rats XD
 
disclaimer 3: there is no clean way to do events in IE6/7 without writing utility methods
things like
var addEvent = function (el, type, cb) {
  if (el.addEventListener) {
    // modern
    el.addEventListener(type, cb);
  } else if (el.attachEvent) {
    // IE<9
    el.attachEvent("on" + type, cb);
  } else {
    // you never need this
    el["on" + type] = cb;
  }
}
Personally I say use the DOM-shim and use .addEventListener and ignore IE7.
 
12:59 PM
fascinating. I've seen that done before... is it really the best way to do it if you have to support IE < 8?
 
@Raynos: does DOM-shim properly implement addEventListener?
 
@AndyE for some value of proper.
I know theres a bug where it doesnt gaurd againts double binding of the same type and callback. its on the two fix list
 
cool
 
And theres another bug >_<
@AndyE apart from bugs. Yes EventTarget is properly shimmed. the Event parameter is not shimmed
 
what about KeyEvent, MouseEvent, etc?
 
1:03 PM
No, none of that is fixed yet.
 
brb -_- Windows is acting up... I miss Linux >.>
 
Just EventTarget. The Event interface is defined in DOM3 events. It's on the roadmap
@AndyE to be honest DOM3 events shim is going to be a bitch. Mutation events emulation alone is a nightmare.
Anyway, ill fix the outstanding bugs today and again as mentioned Event is on the to-do list. EventTarget works cleanly in IE8 once the bugs are gone.
 
@Raynos mutation events emulation is nigh on impossible. IE's onpropertychange event can do only so much.
 
its impossible to emulate without a ridiculious run-time cost.
 
DOM shim might be better as a behaviour
(I know I've said that before)
 
1:07 PM
Oh you mean a HTC ?
 
* { behavior: url(DOM-shim.htc); }
yeah
 
DOM-shim also fixes firefox/chrome/safari/opera.
It's not just fix IE8.
 
hmm I see.
 
@AndyE compliance
 
how about a HTC/JS pair?
 
1:08 PM
unless your running chrome 16 some should fail.
FF7 fails quite a few.
 
I'm just thinking that you could probably add support for IE 6 & 7 by attaching your behaviour to all elements. And that's probably the only way you'd get mutation events too.
 
@AndyE sure, feel free to write the HTC o/ I see your point. I need to look at it
 
@Raynos: I'd love to help (I really would), but I'm up to my elbows in my own stuff at the moment.
 
I know.
If you know stuff about HTC I would appreciate code reviews on HTCs once I need them.
Maybe point me at why I should use HTCs over extending host objects
 
Sure. My IE quirks knowledge is pretty awesome, too. If you have any Qs on particular problems, just ping me on here and I'll answer when I can.
@Raynos HTCs allow you to extend host objects, including writing getters and setters in IE 6 & 7
<PUBLIC:METHOD NAME="addEventListener" />
<script>function addEventListener(evt, fn, capture) { /* ... */ }</script>
 
1:15 PM
hey guys, is there a way to slow down the page load until some jQuery action has completed?
 
@Victor It depends on the "jQuery action", I suppose
 
well, specifically it's the DataTables initialization. I want it to finish wrapping the table markup before it is actually shown on the page
because right now this function is used on document.ready and when you first load the page, for half a second it shows the original table markup before wrapping it in DataTables
 
I'd probably use CSS to hide the table, and then once the DataTables init is finished, show the table through JavaScript.
 
will the DataTables be able to wrap it if the table is hidden with CSS?
 
The elements still exist, so I don't see why not.
There's really only one way to find out, though - try it
 
1:22 PM
true
 
<!-- HTML -->
<table class="initializing">...</table>

/** CSS **/
.initializing { display: none; }

/** jQuery/JS **/
$('.initializing').removeClass('initializing');
 
1:49 PM
hey all does anyone know a function already in existance that converts utc to local time in javascript?
 
@JohnMerlino: Date()
 
I am passing a utc daqte from server
and this function not working for some reason:
function localTimeFromUTCString (string, format) {
// get time offset from browser
var currentDate = new Date();
var offset = -(currentDate.getTimezoneOffset()) / 60;

// get provided date
var tagText = string;
var givenDate = new Date(tagText);

// apply offset
var hours = givenDate.getHours();
hours += offset;
givenDate.setHours(hours);

// format the date
var localDateString = $.format.date(givenDate, format);

return localDateString;
}
 
Date() and add/substract hours depending on your time zone
 
Im trying to get local time zone to whoever is viewing the page
 
@JohnMerlino: you shouldn't have to do anything.
new Date("2011-11-01T15:56:30+00:00") will return a date object in the local time zone
 
1:57 PM
I have a time returned from server:
2011-11-01 13:29:59 UTC
I want it formatted like this: MM/dd/yyyy hh:mm:ss a
 
is it behind or ahead of real time?
 
but in local time of user browser
 
if not, just use regular date
 
I tried it nt working:
function localTimeFromUTCString (string, format) {
// get time offset from browser
var currentDate = new Date();
var offset = -(currentDate.getTimezoneOffset()) / 60;

// get provided date
var tagText = string;
var givenDate = new Date(tagText);

// apply offset
var hours = givenDate.getHours();
hours += offset;
givenDate.setHours(hours);

// format the date
var localDateString = $.format.date(givenDate, format);

return localDateString;
}
I use date
but it still returns the date of utc
not sure why that function is wrong
 
@JohnMerlino it looks like you're adjusting the offset yourself when you don't need to. Like I said, new Date("2011-11-01 13:29:59 UTC") will create that date in the current time zone.
 
1:59 PM
0
A: What is the actual problem with a prototype based design?

Incognito But it seems like they are avoided for the creation of executable applications and of bigger projects in general. Why that? I don't know, but the assumption is false. Larger projects use prototypical languages: JavaScript is the most popular language on github. Cloud9 is a full-blown clou...

 
see if this helps ya onlineaspect.com/2007/06/08/…
 
@JohnMerlino: for example, if your tz is +0200, new Date("2011-11-01 13:29:59 UTC").getHours() will return 15.
 
But the date I want to dispay is not current date, its a datre in database
in utc format
I want to display that date in local time
 
@JohnMerlino: it doesn't matter.
 
so instead of applying offset, what should I do?
 
2:01 PM
absolutely nothing
 
what do you mean?
 
@JohnMerlino: you don't need to apply any offset. It's all done for you. See the example I posted before, where I set the time to 13:29:59 in UTC, but the local time is returned for getHours() et al, 15:29:59.
 
you suggest this:
function localTimeFromUTCString (string, format) {

givenDate = new Date(string).getHours()

var localDateString = $.format.date(givenDate, format);

return localDateString;
}
 
Can somebody unstar my example code? It's not worth having in the starred messages.
 
it sitll not working
 
2:10 PM
@John: no, lose the getHours() that was just for my example.
function localTimeFromUTCString (string, format) {
    var givenDate = new Date(string),
        localDateString = $.format.date(givenDate, format);

    return localDateString;
}
 
@RyanKinal sorry I starred it, by the way your idea worked perfectly
 
That is, assuming $.format.date doesn't use getUTCHours.
 
Sweet! Glad to hear it.
 
@RyanKinal done.
 
For future reference, though, stars in chat are publicly visible. So if it's only useful to you, don't star it
If, however, it's generally useful, or just funny, feel free to star :-)
 
2:13 PM
thats not giving local time either
 
@JohnMerlino: then $.format.date doesn't work how you want it to.
 
@AndyE does that extend every element everywhere?
 
even if i dont use $.format.date it still doesnt reutnr local time
 
did getTimezoneOffset( ) work for you?
 
no
server sends something like this:
2011-05-10 11:23:15 UTC
 
2:22 PM
@Incognito epic.
 
Im trying to get this: 2011-05-10 07:23:15
all the suggestions and my original code still return this: 2011-05-10 11:23:15 UTC
 
@Raynos Thought you'd enjoy that.
 
My favourite line was:
 
this should work
 
2:24 PM
> Oh wait, we can be sure how to write quality code in JavaScript. It's called reading the funny manual,
 
o/
l2softwareengineer.
 
hey all
 
hey @Neal
 
is it possible to have a js popup use all the same scripts as the parent window?
 
@JohnMerlino did you read that article? did it help?
 
2:30 PM
The article uses yahoo library
 
@Neal like a new window, not just a popup?
 
@Neal look at window.opener
That will have all the globals of the parent available
 
@RyanKinal ahhh, but how do i transfer that over to the new window. so i can just use it globally?
hmmm maybe.
var new_win = window.open();
new_win.onload = function(){ this = window.opener}
or is that just dumb?
 
@Raynos within the document, yeah. I probably wouldn't extend it that way, though. Rather, add the functions to the element from within the behavior in IE 6 & 7, add them to the prototype in IE 8.
 
var myFunc = window.opener.myFunc;
 
2:35 PM
@RyanKinal i dont want to do that for all functions...
how do i just move all of them? there must be a way...
 
Namespacing?
 
yeah namespacing would work I imagine @RyanKinal
 
/** in the parent **/
var interface = {
    func1: function()
    {
    },
    func2: function()
    {
    }
    /*...*/
};

/** in the child **/
var interface = window.opener.interface;
interface.func1();
interface.func2();
 
@RyanKinal true. but right now my code isnt set up like that....
0
Q: Move all functions to child window

NealIf I do this: var niew_win = window.open(); How do I make it so that all of the functions that could be used in the parent window can now be used in the child window (new_win)? I do not want to do: var fun1 = window.opener.fun1; var fun2 = window.opener.fun2; ...

 
I've actually been using a similar technique for (shudder) iframes, rather than new windows
/** in the child **/
var interface = window.opener;
interface.func1();
interface.func2();
 
2:40 PM
@RyanKinal lol yes, but all the code is already written, just want to move peices of it to a child window
(i was originally using jQuery dialogs, which they do not want now...)
 
Please note the changed first line: var interface = window.opener; (not window.opener.interface)
Oh, so you don't want to refactor the code in the child?
It's already written?
 
@RyanKinal yes
 
Oi. That's... interesting.
 
for a jquery dialog.
 
@AndyE what are the run time costs /expenses of HTC ?
 
2:42 PM
but now they dont want the dialog
 
they want a window eh?
god I hate opening new windows, feels so old school to me
 
i know
but they want to organize all their charts on multiple windows
 
Please note that what follows is a dangerous, dirty, messy, M$-level hack. I am fully aware of this, but it (theoretically) does what @Neal wants. (I'm a little scared to even post it)
/** What follows is a dangerous, dirty, messy, M$-level hack **/
var i, w = window.opener;
for (i in w)
{
    if (w.hasOwnProperty(i) && !window.hasOwnProperty(i) && typeof w[i] === 'function')
    {
        window[i] = w[i];
    }
}
 
@AndyE feel free to dump links on the issue for beating IE6 with HTCs
 
Ugh. I need a shower, that's so dirty.
 
2:45 PM
@RyanKinal lol yes, i guess that would work. lol
can u add it as an answer on SO
im sure someone can clean it up lol
@RyanKinal HA :-D
 
lol
 
That is seriously the dirtiest piece of code I've written in a long, long, long time.
 
@RyanKinal woh! .hasOwnProperty on host objects is dangerous in IE.
 
@RyanKinal lol
 
@Raynos I'm fully aware
 
2:47 PM
@Raynos so write something cleaner ^_^
u like complaining but not doing anything.
@RyanKinal why do you need this piece: w.hasOwnProperty(i)? and do i need the typeof w[i] === 'function' if i might also tranfer other vars?
 
Well, not strictly... but that only makes it dirtier.
 
@RyanKinal i responded to the comment on ur answer, idk if i was correct or not.
 
Shit. We might have to use .bind
 
@RyanKinal edit your code awaaaay! :-)
lemme know when there might be a final answer.
:-)
thank youuuuuuuuuuuuuuuuuuuu
 
Will SOMEBODY downvote this answer? I've gotten 50 rep for this piece of crap.
2
I need a drink
@Neal You're welcome? :-D
 
2:55 PM
@RyanKinal ^_^
 
looks like using display:none and then changing back to something messes up table column width
 
@Victor wow. that's random
 
@Victor I was afraid of that. With display: none set, it doesn't actually render, so no resizing is done. But you're closer?
 
@RyanKinal or it is not, and i am missing something? ^_^
 
@Neal It's in reference to a previous question :-)
 
2:57 PM
@RyanKinal i see ^_^
 
@RyanKinal I think I may have to hard code the column width
but I was wonderin if there's some trick I can use
if I use visibility: hidden will it be the same thing?
wow, it worked
 
That was going to be my solution :-)
Well done
@Neal Edited
 
hmmmm
 
@Incognito Cheat Engine, a magnificent tool, is also written in Lua.
 
@RyanKinal If you look at my profile, you'll see that I've gotten 80 rep for location.hash in this question
 
3:05 PM
@Amaan Yes, but that isn't a terribly bad idea
 
@RyanKinal Hahahaha. True. But i've gotten less rep for the other answers, that are so much better than that
 
:-)
 
:)
 
@RyanKinal what is the bind for?
 
It allows this inside the function to reference the child window, rather than the parent window. Which isn't exactly what is needed to re-reference document, but it helps alleviate some scope issues.
 
3:10 PM
Anyone know if there's a simple way to move all global functions to an object?
 
@Amaan thats the Q up there...
 
@Neal That's what prompted it, except I don't want a window to inherit the functions
Oh. Wait
The window's an object.
Right!
 
Ding ding ding!
 
Everything's an object, except null and undefined
Also, window refers to the global object.
 
@Amaan lol
 
3:13 PM
@Neal I'm an idiot. XD
 
@Amaan ^_^
 
hello :]
 
@aydinch Sup?
 
Not much, started JS recently and already very happy to have an active community
 
Well, as a beginner, are you using w3schools.com? Because if you are, don't.
 
3:23 PM
no, I don't
 
Good
 
I'm taking the O'Reilly "JavaScript Path to Mastery" approach
 
Cool. I haven't read it, though
 
and "JavaScript: The Definitive Guide" already on my desk, waiting to be opened :p
 
Hah
I'm getting Crockford's JavaScript: The Good Parts soon
 
3:25 PM
it's just a series of books recommended by O'Reilly. You can check it here: oreilly.com/javascript/index.html
 
@aydinch Thanks
 
already really excited, I want to use the new Audio API and have plans to visualize my beatbox records ;)
Canvas etc.
 
@aydinch Hahaha
@aydinch Canvas is pretty darned awesome
 
Oreilly is pretty good
 
@aydinch If you're into HTML5, I've heard Introduction to HTML5 by remy sharp and brucel (Twitter name) is pretty good
 
3:29 PM
@Amaan thanks for that, will definitely look into that
 
@aydinch Anytime
 
I recently finished "HTML5 for Web Designers" by Jeremey Keith (abookapart)
 
You're a web designer?
I can't design
I gotta go
Bye!
 
posted on November 01, 2011

A while ago I made the “jQuery source viewer“. It allows you to explore jQuery’s source and has a hackable URL pattern so you can get at what you need (e.g. /jquery/append). I had been thinking about making a version 2 for sometime, and about…

 
do you know why I am getting object is not a function with this:
$(function($){
$.fn.localTimeFromUTCString = function (format) {
return this.each(function () {
// get time offset from browser
var currentDate = new Date();
var offset = -(currentDate.getTimezoneOffset() / 60);
// get provided date
var tagText = $(this).html();
var givenDate = new Date(tagText);
// apply offset
var hours = givenDate.getHours();
hours += offset;
givenDate.setHours(hours);
// format the date
var localDateString = $.format.date(givenDate, format);
$(this).html(localDateString);
});
 
3:37 PM
@JohnMerlino fOrMaT cOdE please
 
ctrl-k
 
@RyanKinal not in chat.
 
$(function($){
$.fn.localTimeFromUTCString = function (format) {
return this.each(function () {
// get time offset from browser
var currentDate = new Date();
var offset = -(currentDate.getTimezoneOffset() / 60);
// get provided date
var tagText = $(this).html();
var givenDate = new Date(tagText);
// apply offset
var hours = givenDate.getHours();
hours += offset;
givenDate.setHours(hours);
// format the date
var localDateString = $.format.date(givenDate, format);
$(this).html(localDateString);
});
it didnt work
 
click on fixed font
 
@Neal Try it ;-)
 
3:38 PM
ahhh edit
dont post again!
 
it doesnt work for me
control + k
 
@JohnMerlino click edit. then fixed font.
 
I typed this in
and hit ctrl-k
and now it's all fixed-width
    and formatted
    very nicely
 
@RyanKinal thats nice for you.
....
 
jsFiddle appears to show a different version in Firefox (as compared to Chrome and IE9)... ?
It shows "Hide sidebar" and "Show JS" buttons...
And the CSS styles are different... (fonts, borders, buttons,... )
 
user1385191
3:52 PM
there needs to be something on SO for when you use
 
user1385191
like if you don't post any HTML, your question is rejected
 
You'd have to check outside links as well.
 
user1385191
it was more of a joke, really
 
user1385191
it won't happen
 
:-)
 
user1385191
3:55 PM
but it continues to cause poor answer pollution
 
It's true
 

« first day (381 days earlier)      last day (4573 days later) »