Search

10/28/2008

IE vs. FireFox 系列 - showModalDialog

IE vs. FireFox 系列 - showModalDialog
window.open - MDC

modal
Note: Starting with Mozilla 1.2.1, this feature requires the UniversalBrowserWrite privilege ( bug 180048 ). Without this privilege, it is ignored.
If set to yes, the new window is said to be modal. The user cannot return to the main window until the modal window is closed. A typical modal window is created by the alert() function.
The exact behavior of modal windows depends on the platform and on the Mozilla release version.

Blog.XDite.net » 在 Linux 上架設 Screenshot Service

Blog.XDite.net » 在 Linux 上架設 Screenshot Service


killall firefox Xvfb
Xvfb :2 -screen 0 1024x768x24 -fbdir /tmp -nolisten inet6 & sleep 10
DISPLAY=:2.0 firefox -width 1024 -height 768 http://www.google.com &
sleep 10
xwd -display :2.0 -root -out shot.xwd
xwdtopnm shot.xwd> shot.pnm
pnmscale -xysize 200 150 shot.pnm> shotsmall.pnm
pnmtojpeg shotsmall.pnm> shot_thumb.jpg
pnmtojpeg shot.pnm> shot.jpg

大吉祥香豆腐(富)

大吉祥香豆腐(富) - iPeen 愛評網-最豐富的美食餐廳情報集散地
營業時間:週一至週六11點到20點(不過客人多可能提早賣完)

地址:北縣淡水鎮北新路182巷3弄28號

10/27/2008

Overflow Auto and Position Relative

ie6 overflow:auto不起作用的情况 - DotNet开发之路 - 博客园

今天遇到一个比较特殊的情况:ie6下设置overflow:auto不起作用,在火狐下正常显示。ie下滚动条是出来了,但是内容却跑到下面去了,滚动条行同虚设。网上搜索了一下都说是设置高度和宽度就ok了,开始还以为是百分比高度引起的,但设置成绝对高度200px后还是不行。最后通过经验判断出原来是overflow的那个div没有position定位,给加了个定位和top,left属性后一切都正常了!汗,实际开发中遇到的问题远远比预料的多啊,这或许是为什么软件项目开发总是延迟,尽管开发人员加班加点成了家常便饭还是不可避免的。

Overflow Auto and Position Relative 在 ie 的 standard mode下,container設定overflow:auto; 裡面的element設定position:relative的話,一樣會visible,解決的辦法是在container也加上position:relative
http://chunghe.googlecode.com/svn/trunk/experiment/overflow.auto.and.position.relative/before.htm
http://chunghe.googlecode.com/svn/trunk/experiment/overflow.auto.and.position.relative/after.htm

Website overview - Browsershots

Website overview - Browsershots - It's free!

在ie下TABLE、 TFOOT、 THEAD 和 TR 項目 innerHTML 屬性是唯讀屬性

在 Internet Explorer 設定 Table.innerHTML PRB: 錯誤

發生的原因
為 TABLE、 TFOOT、 THEAD 和 TR 項目 innerHTML 屬性是唯讀屬性。
解決方案
若要變更這些項目, 資料表的內容使用資料表物件模型或文件物件模型 (DOM)。

Ajaxian » innerHTML Gotchas
In IE you can’t use innerHTML or outerHTML on tables and instead e to use the “table model”. On MSDN refer to IHTMLTableSection and IHTMLTableRow for methods to insert rows/cells into a table.

Today’s hack is brought to us by Microsoft’s lunacy:
var innerHTML = “Hello world!”;
var div = document.createElement(”DIV”);
div.innerHTML = “” + innerHTML + “
”;
// Get the tr from the table in the div
var trElem = div.getElementsByTagName(”TR”)[0];

deleteCell Method (IHTMLTableRow)
IHTMLTableSection Interface ()

localeCompare

如何用javascript做中文排序 @ 雜七雜八的kewang部落格 :: PIXNET 痞客邦 ::

看了這兩篇「JavaScript中实现数组的排序、乱序和搜索。」和「利用JavaScript的sort()对包含汉字字符串数组进行排序」之後,才知道javascript有localeCompare()這種函式可以拿來做本地化的字串比較。

localeCompare的使用方法就是像這樣:
ret = '國立宜蘭大學'.localeCompare('國立台灣大學')

原始字串(國立宜蘭大學)跟要比較的字串(國立台灣大學)做比較,如果原始字串比較小的話,則ret就會傳回小於0的數字;如果比較大的話,則傳回大於0的數字;如果相等就傳回0。

http://chunghe.googlecode.com/svn/trunk/experiment/sort.by.filename.htm


function sortByFileName(a, b){
var x = parseInt(a);
var y = parseInt(b);
if(( isNaN(x)) || (isNaN(y)))
return a.localeCompare(b);
return x-y;
}

10/26/2008

萬華美食

食尚玩家2007-10-13 萬華夜市超猛又好呷-生活好料理食譜-新浪部落
福州元祖胡椒餅
和平西路三段109巷裏
2308-3075

西昌街青草巷:百年青草店
四知青草葯膏
台北市西昌街224巷5號
2308-1256

76年老店-好吃傳三代冰果店
龍都冰果店
廣州街168號

台南擔仔麵
華西街31號
2308-1123

漢記剝骨鵝肉
華西街28號
2308-8046

頂級甜不辣
廣州街與梧州街交叉口
2302-6022

GreyNick Life:[食尚玩家]-萬華古早味..永富冰淇淋 - yam天空部落

Mobile01 萬華區:麗珠什錦麵/排骨飯(這家的排骨無敵好吃)
Meiko's 強迫症患者的異想世界:【萬華50年老店】麗珠什錦麵 - yam天空部落
麗珠什錦麵

TEL:2308-6530
ADD:台北市興寧街48號
營業時間:11:30~23:00(星期一公休

10/25/2008

border: none

在IE下, 如果設定
在standard mode下, 還是會顯示 border
在quirk mode下, 不會顯示 border
可能的workaround可以是 border: 1px solid #fff
http://chunghe.googlecode.com/svn/trunk/experiment/input.border/input.border.none.standard.mode.htm
http://chunghe.googlecode.com/svn/trunk/experiment/input.border/input.border.quirk.mode.htm

10/24/2008

回头来看看Table:TD也玩overflow:hidden

* 在ie下, tr不能有border, td才有
* 在td下要使用white-space:nowrap, overflow:hidden
第一種方法. 用nobr;
第二種方法. td width用%表示
第三種方法. td span{display:block; overflow:hidden; white-space:nowrap}
回头来看看Table:TD也玩overflow:hidden - 飘零雾雨的庄园

10/22/2008

JavaScript's class-less objects by Stoyan Stefanov

JavaScript's class-less objects by Stoyan Stefanov
By convention, though, constructor functions are named with a capital letter to distinguish visually from normal functions and methods.

So which way is better - object literal or constructor function? Well, that depends on your specific task. For example, if you need to create many different, yet similar objects, then the class-like constructors may be the right choice. But if your object is more of a one-off singleton, then object literal is definitely simpler and shorter.

(Actually in JavaScript pretty much everything is an object, with the exception of the few primitive data types - string, boolean, number and undefined. Functions are objects, arrays are objects, even null is an object. Furthermore, the primitive data types can also be converted and used as objects, so for example "string".length is valid.)

Inheritance via the prototype
Here's a constructor function which will be the parent:

function NormalObject() {
this.name = 'normal';
this.getName = function() {
return this.name;
};
}

Now a second constructor:
function PreciousObject(){
this.shiny = true;
this.round = true;
}

PreciousObject.prototype = new NormalObject();

Notice how we needed to create an object with new and assign it to the prototype, because the prototype is just an object. It's not like one constructor function inherited from another, in essence we inherited from an object. JavaScript doesn't have classes that inherit from other classes, here objects inherit from other objects.
If you have several constructor functions that will inherit NormalObject objects, you may create new NormalObject() every time, but it's not necessary. Even the whole NormalObject constructor may not be needed. Another way to do the same would be to create one (singleton) normal object and use it as a base for the other objects.
var normal = {
name: 'normal',
getName: function() {
return this.name;
}
};

PreciousObject.prototype = normal;

Inheritance by copying properties
var shiny = {
shiny: true,
round: true
};

var normal = {
name: 'name me',
getName: function() {
return this.name;
}
};

function extend(parent, child) {
for (var i in parent) {
child[i] = parent[i];
}
}

extend(normal, shiny); // inherit
shiny.getName(); // "name me"

function begetObject(o) {
function F() {}
F.prototype = o;
return new F();
}

Parent object:

var normal = {
name: 'name me',
getName: function() {
return this.name;
}
};

A new object inheriting from the parent:
var shiny = begetObject(normal);


Augment the new object with more functionality:
shiny.round = true;
shiny.preciousness = true;

YUI's extend()
function extend(Child, Parent) {
var F = function(){};
F.prototype = Parent.prototype;
Child.prototype = new F();
}


/**
* Utility to set up the prototype, constructor and superclass properties to
* support an inheritance strategy that can chain constructors and methods.
* Static members will not be inherited.
*
* @method extend
* @static
* @param {Function} subc the object to modify
* @param {Function} superc the object to inherit
* @param {Object} overrides additional properties/methods to add to the
* subclass prototype. These will override the
* matching items obtained from the superclass
* if present.
*/
extend: function(subc, superc, overrides) {
if (!superc||!subc) {
throw new Error("extend failed, please check that " +
"all dependencies are included.");
}
var F = function() {};
F.prototype=superc.prototype;
subc.prototype=new F();
subc.prototype.constructor=subc;
subc.superclass=superc.prototype;
if (superc.prototype.constructor == Object.prototype.constructor) {
superc.prototype.constructor=superc;
}

if (overrides) {
for (var i in overrides) {
if (L.hasOwnProperty(overrides, i)) {
subc.prototype[i]=overrides[i];
}
}

L._IEEnumFix(subc.prototype, overrides);
}
},

  • there are no classes
  • objects inherit from objects
  • object literal notation var o = {};
  • constructor functions provide Java-like syntax var o = new Object();
  • functions are objects
  • all function objects have a prototype property
    v And finally, there are dozens of ways to inmplement inheritance, you can pick and choose depending on your task at hand, personal preferences, team preferences, mood or the current phase of the Moon.

  • jslibs - Google Code

    jslibs - Google Code - try jshost examples/systray.js

    jslibs is a standalone JavaScript development runtime environment for using JavaScript as a general-purpose scripting language.

    jslibs uses SpiderMonkey library that is Gecko's JavaScript engine (SpiderMonkey is used in various Mozilla products, including Firefox).

    jslibs provides a set of native modules that contains various general purpose classes and functions.

    Some of these modules are simple wrappers for familiar libraries such as: zlib, SQLite, FastCGI, NSPR (Netscape Portable Runtime) , ODE (Open Dynamics Engine) , libpng, libjpeg, librsvg, SDL, libiconv, OpenGL, OpenAL, ogg vorbis, libTomCrypt, libffi (Foreign function interface) , ...

    via Ajaxian » jslibs - free JavaScript of browser limitations

    10/20/2008

    10/18 SA@Taipei 主講 Open at Yahoo!

    10/18 SA@Taipei 主講 Open at Yahoo!
    Instance-based:可例項化
    YUI 2.x: YAHOO 作為全域變數,只能有一個,容易被覆寫


    YAHOO.widget.HelloWorld = doSomething; // 開發者 1 寫的
    ...
    YAHOO.widget.HelloWorld = doNothing; // 開發者 2 寫的

    YUI 3.x: YUI() 可建立起一個全新的例項,不會被覆寫

    YUI().use('node', function(Y) { // 開發者 1 寫的
    Y.HelloWorld = doSomething;
    };);
    YUI.use('drag', function(Y) { // 開發者 2 寫的
    Y.HelloWorld = doNothing;
    };);

    YUI 3.x: 取得的物件不再是 HTMLElement

    var el = Y.get('#foo');
    alert(el.nodeName); //output: undefined
    alert(el.get('nodeName')); //output: DIVs

    YUI 2.xFunction-based 的存取方式

    var $D = YAHOO.util.Dom; // reference cache
    var el = $D.get('foo');
    YUD.addClass(el, 'highlighted');
    el.innerHTML += ' clicked';

    YUI 3.x: Object-based 的存取方式

    var el = Y.get('#foo');
    el.addClass('highlighted');
    el.set('innerHTML') = el.get('innerHTML') + ' clicked';

    YUI 3: event listener
    事件的綁法
    方法一:Y.on()

    YUI().use('node', function (Y) {
    Y.on('click', function (e) {
    // 處理事件
    }, '#foo');
    });

    方法二:Node.on()

    YUI().use('node', function (Y) {
    var el = Y.get('#foo');
    el.on( click', function (e) {
    // 處理事件
    });
    });

    YUI 2.x: 還是一般 DOM Event

    var $E = YAHOO.util.Event; // reference cache
    $E.on('foo', 'click', function (e) {
    alert(e.type); //output: click
    $E.preventDefault(e); //防止像是連結或表單送出的預設事件
    $E.stopPropogation(e); //防止Bubbleup
    });

    YUI 3.x: 封裝後更物件導向

    Y.on('click', function (e) {
    alert(e.type); //output: undefinded
    e.preventDefault();
    e.stopPropogation();
    }, '#foo');

    Textile

    Textile
    Textile - SWiK

    Textile is a web text markup-language that balances the strength of HTML with speed and ease of editing.

    Unlike many wiki or other markup languages, Textile sticks closely to the semantics of HTML, headings for example are represented by ‘h1’, ‘h2’ for <h1> and <h2>. Attaching classes and ids to elements is also easy with Textile.

    Textile is used by both blogs and a number of wikis, including the Ruby on Rails instiki powered wiki and by SWiK. Textile does not make a provision for wiki links however, so various wikis have interpreted their own wiki link standards.

    http://jrm.cc/extras/live-textile-preview.php

    test data

    一張很慢的圖
    http://sowrock.com/bin/sleep.cgi?type=gif&sleep=3&expires=-1&last=0&imagenum=13&t=1224467689
    一個很慢的script
    http://sowrock.com/bin/sleep.cgi?type=js&sleep=10&expires=-1&last=0

    tag: steve

    10/17/2008

    Best Practices for Speeding Up Your Web Site

    Best Practices for Speeding Up Your Web Site
    Add an Expires or a Cache-Control Header

    Browsers (and proxies) use a cache to reduce the number and size of HTTP requests, making web pages load faster. A web server uses the Expires header in the HTTP response to tell the client how long a component can be cached. This is a far future Expires header, telling the browser that this response won't be stale until April 15, 2010.

    Expires: Thu, 15 Apr 2010 20:00:00 GMT

    If your server is Apache, use the ExpiresDefault directive to set an expiration date relative to the current date. This example of the ExpiresDefault directive sets the Expires date 10 years out from the time of the request.

    ExpiresDefault "access plus 10 years"

    Avoid Redirects
    One of the most wasteful redirects happens frequently and web developers are generally not aware of it. It occurs when a trailing slash (/) is missing from a URL that should otherwise have one. For example, going to http://astrology.yahoo.com/astrology results in a 301 response containing a redirect to http://astrology.yahoo.com/astrology/ (notice the added trailing slash). This is fixed in Apache by using Alias or mod_rewrite, or the DirectorySlash directive if you're using Apache handlers.

    Make JavaScript and CSS External
    Home pages that have few (perhaps only one) page view per session may find that inlining JavaScript and CSS results in faster end-user response times.

    Remove Duplicate Scripts
    Unnecessary HTTP requests happen in Internet Explorer, but not in Firefox. In Internet Explorer, if an external script is included twice and is not cacheable, it generates two HTTP requests during page loading. Even if the script is cacheable, extra HTTP requests occur when the user reloads the page.

    Configure ETags
    Entity tags (ETags) are a mechanism that web servers and browsers use to determine whether the component in the browser's cache matches the one on the origin server. (An "entity" is another word a "component": images, scripts, stylesheets, etc.) ETags were added to provide a mechanism for validating entities that is more flexible than the last-modified date. An ETag is a string that uniquely identifies a specific version of a component. The only format constraints are that the string be quoted. The origin server specifies the component's ETag using the ETag response header.

    HTTP/1.1 200 OK
    Last-Modified: Tue, 12 Dec 2006 03:03:59 GMT
    ETag: "10c24bc-4ab-457e1c1f"
    Content-Length: 12195

    Later, if the browser has to validate a component, it uses the If-None-Match header to pass the ETag back to the origin server. If the ETags match, a 304 status code is returned reducing the response by 12195 bytes for this example.

    Minimize the Number of iframes
    <iframe> pros:

    * Helps with slow third-party content like badges and ads
    * Security sandbox
    * Download scripts in parallel

    Use Cookie-free Domains for Components
    When the browser makes a request for a static image and sends cookies together with the request, the server doesn't have any use for those cookies. So they only create network traffic for no good reason. You should make sure static components are requested with cookie-free requests. Create a subdomain and host all your static components there.

    Avoid Filters
    The best approach is to avoid AlphaImageLoader completely and use gracefully degrading PNG8 instead, which are fine in IE. If you absolutely need AlphaImageLoader, use the underscore hack _filter as to not penalize your IE7+ users.

    Optimize Images
    You can check the GIFs and see if they are using a palette size corresponding to the number of colors in the image. Using imagemagick it's easy to check using
    identify -verbose image.gif
    When you see an image useing 4 colors and a 256 color "slots" in the palette, there is room for improvement.

    tag: yslow

    08金馬影展預告

    11/6 pm 19:30(儘管如此,我沒做過)
    11/7 pm 19:10 (血色入侵)
    11/8 pm 23:30 (東京狂想曲)
    11/9 pm 21:40 (黑道快餐店)
    11/10 am 10:30 (非關英雄) pm 18:30 (大家都愛查理)
    11/13 pm 22:30 (陌生的孩子)
    11/14 pm 20:40 (神的孩子都在跳舞)
    11/15 pm 16:00 (阿拉斯加之死) pm 19:30 (沉默的蘿娜) pm 22:00 (2001太空漫遊)
    11/18 am 10:30 (完全虐囚守則)pm 15:30 (庸人自擾)
    11/19 pm 18:20 (囧男孩)

    10/15/2008

    Geolocation API Specification

    Geolocation API Specification

    This specification defines an API that provides scripted access to geographical location information associated with the hosting device.

    instanceof vs. typeof

    JS中的instanceof和typeof - AJAXBBS.NET

    instanceof和typeof都能用来判断一个变量是否为空或是什么类型的变量。
    typeof用以获取一个变量的类型,typeof一般只能返回如下几个结果:number,boolean,string,function,object,undefined。我们可以使用typeof来获取一个变量是否存在,如if(typeof a!="undefined"){},而不要去使用if(a)因为如果a不存在(未声明)则会出错,对于Array,Null等特殊对象使用typeof 一律返回object,这正是typeof的局限性。

    如果我们希望获取一个对象是否是数组,或判断某个变量是否是某个对象的实例则要选择使用instanceof。instanceof用于判断一个变量是否某个对象的实例,如var a=new Array();alert(a instanceof Array);会返回true,同时alert(a instanceof Object)也会返回true;这是因为Array是object的子类。再如:function test(){};var a=new test();alert(a instanceof test)会返回true。

    谈到instanceof我们要多插入一个问题,就是function的arguments,我们大家也许都认为arguments是一个Array,但如果使用instaceof去测试会发现arguments不是一个Array对象,尽管看起来很像。

    計算 2 Bytes 中文字數

    用下面這段 Reg Expession 可以計算出中文字和英文字的字數,如此一來英文可以填寫50個字、中文只能填寫 25 個字。

    var textNumber = sStr.value.replace(/[^\x00-\xff]/g,"00").length;
    if (textNumber>50){
    alert("您填寫文字過長,僅供填寫25個中文字,請修改您的文字");
    return false;
    }

    10/14/2008

    Imageload with downgrade graceful

    http://chunghe.googlecode.com/svn/trunk/project/image.loader.downgrade.graceful/index.htm

    For browsers support javascript, it will behave like normal imageload do.
    For those don't, it will still display images.

    The little trick is that


    <script>
    document.write('<style>.yui-imgload-scrollgroup{background:none !important}</style>');
    </script>

    For those browser doesn't support javascript, it simply ignore script tag. Without the "background:none !important" decoration, the image will still show up.
    In the other hand, if browsers support javascript, it will write <style>.yui-imgload-scrollgroup{background:none !important}</style> and behave just like normal imageload.

    I think these's still some better ways than document.write, but this is a OK method for adopting imageload.

    crossdomain.xml

    crossdomain.xml 的路徑


    <?xml version="1.0" encoding="utf-8"?>
    <cross-domain-policy>
    <allow-access-from domain="*.wretch.cc" />
    <allow-access-from domain="tw.rd.yahoo.com" />
    <allow-access-from domain="*.corp.yahoo.com" />
    <allow-access-from domain="l.yimg.com" />
    </cross-domain-policy>

    今天譬如一段embed code嵌在 chunghe.blogspot.com 裡面

    <embed id="diguRssReader" width="200" height="278" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" allowscriptaccess="sameDomain" flashvars="name=bigvan&Interval=10000" name="diguRssReader" wmode="transparent" bgcolor="#869ca7" quality="high" src="http://l.yimg.com/wretch.yimg.com/photos/serv/digu/diguRssReader.swf"/>

    crossdomain.xml裡面的allow domain是check swf l.yimg.com 這個 domain 而不是check chunghe.blogspot.com這個domain

    10/13/2008

    How to style undefined tag?

    How to style undefined tag?
    <hi>wretch</hi>
    <style>hi{color:red}</style>
    <script>var hi = document.createElement('hi')</script>

    10/06/2008

    RsAnAn's Blog - (新竹)GB5用心的咖啡

    RsAnAn's Blog - (新竹)GB5用心的咖啡

    GB5用心的咖啡
    新竹市食品路542號
    Tel:03-561-9939

    Matintainable javascript

    Nicholas Zakas: "Maintainable JavaScript" on Yahoo! Video
    Avoid null comparisons
    * Use instanceof for sepcific types of objects
    if (value instanceof constructor){
    * Use typeof to test for string, number, Boolean
    if (typeof value == "string") {

    10/01/2008

    smush it!

    smush it!
    Smush.it presentations

    * Turn GIFs into PNG8. Results are reported only if there's a saving, the file name then becomes source.gif.png. Smush.it uses imagemagick to do the conversion and then pngcrush to crush the pngs
    * Crush PNGs using pngcrush
    * Strip JPEG metadata and make them progressive, using jpegtran
    * GIF animations: use gifsicle to remove pixels that don't change from one frame to another


    7 mistakes in image optimization - O'Reilly's Velocity, SFO, June 2008
    1. No Gifs
    2. Crush PNGs
    3. strip JPEG meta
    4. Avoid truecolor PNG, use PNG8
    5. Avoid AlphaImageLoader
    6. Optimize and cache dynamic images
    7. Combine images into sprites