Showing posts with label WEB. Show all posts
Showing posts with label WEB. Show all posts

Friday, March 18, 2011

Javascript delaying

In need of executing Javascript after the page has loaded, or something else has been initialized I came up with a simple but useful tiny "Delayer":



/**
* @param handler a callback accepting Delayer.dispatch as argument
*/
function Delayer(handler) {
var self = this;

this.dispatch = function() {
for (var i = 0; i < self.length; ++i) {
console.log("running delayed init "+i+": "+self[i]);
self[i]();
}
};

if (typeof handler == "function" || handler instanceof Function) {
handler(this.dispatch);
}
}

Delayer.prototype = Array.prototype;

It can be initialized the following way:



/* e.g. with jQuery */
window.delayedInits = new Delayer($(document).ready);
/* e.g. with Facebook */
window.fbDelayedInits = new Delayer(function(dp){window.fbAsyncInit = dp;});

Then you push your work the usual way:



delayedInits.push(function() {alert("Hello, delayed!");});

Monday, May 10, 2010

WebSockets Handshake non HTTP conforming?

Update:


Just found a revelatory discussion. The summary of Bjoern Hoehrmann is especially interesting with regards to that topic.




While skimming through the new HTML5 WebSocket draft, I noticed the following exemplar HTTP message demonstrating the client message of a WebSocket handshake:



GET /demo HTTP/1.1
Host: example.com
Connection: Upgrade
Sec-WebSocket-Key2: 12998 5 Y3 1 .P00
Sec-WebSocket-Protocol: sample
Upgrade: WebSocket
Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5
Origin: http://example.com

^n:ds[4U

To me this looks non conforming to the HTTP spec due to the lack of an indicator that the request contains a message body.


Quoting the 4th paragraph of section 4.3 of RFC2616:


The presence of a message-body in a request is signaled by the inclusion of a Content-Length or Transfer-Encoding header field in the request's message-headers. A message-body MUST NOT be included in a request if the specification of the request method (section 5.1.1) does not allow sending an entity-body in requests. A server SHOULD read and forward a message-body on any request; if the request method does not include defined semantics for an entity-body, then the message-body SHOULD be ignored when handling the request.


Huh?

Thursday, May 3, 2007

Two pitfalls in one afternoon

This is not my day.


<quote url="http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html">
words that are present in more than 50% of the rows are considered common and do not match
</quote>


RTFM! ;)

Apache MultiViews are evil

Suppose you've got a similar setup to:



RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [QSA,L]

RewriteRule ^network/?(w+)?$ network.php?path=$1

Apache will expand e.g. "network/foo/bar" to "network.php/foo/bar" which won't be expanded to "network.php?f=" because it --of course-- exists (RewriteCond -f).


Evil! :)

Friday, January 27, 2006

Apache2 mod_domaintree version 1.3

I just released mod_domaintree-1.3 on freshmeat.


It'll take some time to appear, though.


The code has been cleaned up a lot and a host name to directory cache (per server/process) has been added.


Enable the cache by setting DomainTreeCache to a reasonable high number, like the amount of different domains being hosted.


Drop me a mail if you like it! ;)

Thursday, August 5, 2004

Update: overflow:auto in Mozilla

If you want the page to scroll when the scrolling-enabled DIV has nothing to scroll you'll have to wrap the contents of the scrollMe function into the following if statement:



function scrollMe(event)
{
if (event.currentTarget.scrollHeight >
event.currentTarget.offsetHeight) {
// ...
}
}

Have fun!

Monday, August 2, 2004

Scrollable overflow:auto Elements in Mozilla

Doing some extensive Javascript work lately, I managed to make HTML elements styled with //overflow:auto// scrollable in Mozilla.


Just place this snippet at the bottom of your page with DIV elements that have scroll as classname:



<script type="text/javascript"> <!--
// enable scrolling for overflow:auto elements in Mozilla
function scrollMe(event)
{
var st = event.currentTarget.scrollTop;
st += (event.detail * 12);
event.currentTarget.scrollTop = st < 0 ? 0 : st;
event.preventDefault();
}
if (document.body.addEventListener) {
var divs = document.getElementsByTagName('DIV');
for (var d in divs) {
if (divs[d].className && divs[d].className == 'scroll') {
try {
divs[d].addEventListener(
'DOMMouseScroll', scrollMe, false);
} catch (ex) {}
}
}
}
// -->
</script>

I already posted a feature request to embed something similar in pearweb.