Archive for May, 2009

最简单的dojo学习笔记 – Part 2(create a widget)

<Create Your Own Widget Class/>
Creating a Widget Programmatically
var button1 = new dijit.form.Button(params, srcNodeRef);
eg.
new dijit.form.Button({ “class”: “large”, style: “color: red” }, dojo.byId(“someDiv”));
<div id=”someDiv” class=”large” style=”color:red”></div>

Creating a Widget declaratively
eg.
<div dojoType=”dijit.TitlePane” title=”Outer Pane”></div>

IMPORTANT:
startup()
Certain widgets require a startup() method to be called. Haha, java is here again :) just like GUI, rite?

accordion = new dijit.layout.AccordionContainer({}, dojo.byId(“accordionShell”));
accordion.addChild(new dijit.layout.ContentPane());
accordion.addChild(new dijit.layout.ContentPane());
accordion.addChild(new dijit.layout.ContentPane());
accordion.startup(); //after all the elements added, start up

Interacting with Widgets
Obtaining a Widget Reference
dijit.byId(“idOfWidget”)

<Write Your Own Widget Class/>
IMPORTANT: I know it’s cool hack the source code is cool, but that should be last thing you want to do if there is no suitable widget.

WHY the dojo div i put in is so different from what ends up in “view page source”?
Dojo replaces the simple nodes of our example with groups of HTML elements. That’s one of the jobs of the Dojo parser.

eg.

<div dojoType=”dijit.layout.AccordionPane” title=”pane 1″>
Text of Pane 1
</div>

dijit/layout/templates/AccordionPane.html:
<div class=’dijitAccordionPane’
><div dojoAttachPoint=’titleNode,focusNode’ dojoAttachEvent=’ondijitclick:_onTitleClick,onkeypress:_onKeyPress’
class=’dijitAccordionTitle’ wairole=”tab”
><div class=’dijitAccordionArrow’></div
><div class=’arrowTextUp’ waiRole=”presentation”>?</div
><div class=’arrowTextDown’ waiRole=”presentation”>?</div
><span dojoAttachPoint=’titleTextNode’>${title}</span></div
><div><div dojoAttachPoint=’containerNode’ style=’overflow: hidden; height: 1px; display: none’
dojoAttachEvent=’onkeypress:_onKeyPress’
class=’dijitAccordionBody’ waiRole=”tabpanel”
></div></div>
</div>

${title}
is replaced with the title=”…” attribute sent to the widget
dojoAttachPoint=’containerNode’
An attachPoint is a tag merged with user-provided HTML. It’s like a substitution variable for HTML.
what is attachPoint

//hm?? what the ** ??

eg.
sepecify dojoAttachPoint=’titleNode,focusNode’ so that you can use the reference in the widget (this.titleNode).

dojoAttachEvent=’onkeypress:_onKeyPress’
Connects an event to an event handler at that node.

Dijit.Declaration

declaratively create a widget
eg1.
<div dojoType=”dijit.Declaration”
widgetClass=”dojoc.widget.ImageAccordion”
mixins=”dijit.layout.AccordionPane”
><div class=’dijitAccordionPane’
><div dojoAttachPoint=’titleNode,focusNode’
dojoAttachEvent=’ondijitclick:_onTitleClick,onkeypress:_onKeyPress’
class=’dojocAccordionTitle’ wairole=”tab”
><div class=’dijitAccordionArrow’></div
><div class=’arrowTextUp’ waiRole=”presentation”>?</div
><div class=’arrowTextDown’ waiRole=”presentation”>?</div
><span dojoAttachPoint=’titleTextNode’><img alt=”${title}” src=”${src}”
></span></div
><div><div dojoAttachPoint=’containerNode’
style=’overflow: hidden; height: 1px; display: none’
dojoAttachEvent=’onkeypress:_onKeyPress’
class=’dojocImageAccordionBody’ waiRole=”tabpanel”
></div></div>
</div>
</div>
eg2.
<div dojoType=”dijit.Declaration” widgetClass=”simpleConnectedWidget” >
Just a plain ol’ piece of text
<script type=”dojo/connect” event=”dblclick”>
console.debug(“Ouch!  I’ve been double-clicked”);
</script>
</div>

Notes

* widgetsInTemplate is automatically set to true, so any widgets you place in the template will be automatically filled in.
* If you do not specify mixin, the widget class will be a subclass of dijit._Widget and mix in dijit._Templated. If you specify mixin, the first class listed must be a subclass of dijit._Widget. At least one of the mixins should itself mixin dijit._Templated, or you should supply dijit._Templated yourself as a mixin.
* Only one extension point implementation of preamble.

programatically create a widget(More flexible – dijit.declare )
one class -> multiple templates

eg.
dojoc/layout/ImageAccordion.js
// all packages need to dojo.provide() _something_, and only one thing
dojo.provide(“dojoc.widget.ImageAccordion”);
// AccordionContainer is the module with dijit.layout.AccordionPane
dojo.require(“dijit.layout.AccordionContainer”);
// our declared class
dojo.declare(“dojoc.widget.ImageAccordion”,
// we inherit from this class, which in turn mixes
// in _Templated and _Layout
[ dijit.layout.AccordionPane ],
// class properties:
{
templatePath: dojo.moduleUrl(“dojoc”,”layout/templates/ImageAccordion.html”),
// Necessary to keep Dijit from using templateString in AccordionPane
templateString: “”,
// src: String
//      src url for AccordionPaneExtension header
src: “”
});

dojoc/widgets/template/ImageAccordion.html:
<div class=’dojocImageAccordion’
><div dojoAttachPoint=’titleNode,focusNode’
dojoAttachEvent=’ondijitclick:_onTitleClick,onkeypress:_onTitleKeyPress,onfocus:_handleFocus,onblur:_handleFocus’
class=’dojocImageAccordionTitle’ wairole=”tab”
><img alt=”${title}” src=”${src}”
></div
><div><div dojoAttachPoint=’containerNode’
style=’overflow: hidden; height: 1px; display: none’
class=’dojocImageAccordionBody’ waiRole=”tabpanel”
></div></div>
</div>

<The Widget Life-cycle/>

onstructor
Your constructor method will be called before the parameters are mixed into the widget, and can be used to initialize arrays, etc.
parameters are mixed into the widget instance
This is when attributes in the markup (ex: <button iconClass=…>) are mixed in
postMixInProperties
If you provide a postMixInProperties method for your widget, it will be invoked before rendering occurs, and before any dom nodes are created. If you need to add or change the instance’s properties before the widget is rendered – this is the place to do it.
buildRendering
_Templated provides an implementation of buildRendering that most times will do what you need. The template is fetched/read, nodes created and events hooked up during buildRendering. If you dont mixin _Templated (and most OOTB dijits do) and want to handle rendering yourself (e.g. to really streamline a simple widget, or even use a different templating system) this is where you’d do it.
————> widget rendered
postCreate
This is typically the workhorse of a custom widget. The widget has been rendered (but note that sub-widgets in the containerNode have not!)
startup
If you need to be sure parsing and creation of any child widgets is complete, use startup.
destroy
Implement destroy if you have special tear-down work to do (the superclasses will take care of most of it for you; be sure to call this.inherited(arguments);)

,

No Comments

最简单的dojo学习笔记 – Part 1(dojo basics)

<dojo functions/>

1.  dojo.require(“dojo.fx”);
//This registers a function to be run when the document (and all required dependencies) are ready
2. dojo.addOnLoad(function(){
console.log(“document ready!”);
});
similarly,
var init = function(){
console.log(“document ready!”);
}
3. dojo.addOnLoad(init);

4. dojo.byId -  get DomNode
5. digit.byId – get widget

6. dojo.query – returns a list of Dom nodes based on CSS selector

eg.  // every element in the page with the class “blueButton” assigned
dojo.query(“.blueButton”).forEach(function(node, index, arr){
console.debug(node.innerHTML);
});

7.dojo.forEach
eg.disable all the select tags
dojo.forEach(
dojo.query(“select”, document),
function(selectTag) {
selectTag.disabled = true;
}
);
// >= 1.0 only.
dojo.query(“select”, document).forEach(“item.disabled = true;”);

8. dojo.connect

eg. connect event to js event handler
function helloPressed(){
alert(‘You pressed the button’);
}

function init(){
button = dojo.byId(‘helloButton’);
dojo.connect(button, ‘onclick’, ‘helloPressed’);
}

eg.bind mult connections when exampleObj.bar() gets called, exampleObj.foo() will be called.
var exampleObj = {
counter: 0,
foo: function(){
alert(“foo”);
this.counter++;
},
bar: function(){
alert(“bar”);
this.counter++;
}
};

dojo.connect(exampleObj, “foo”, exampleObj, “bar”);

<OO -Object Orientied/>
OO,think is as Java.

pass Functions as Variables
eg.

function applyTwoParameterFn(a, b, function){
return function(a,b);
}
console.debug(applyTwoParameterFn(1, 2, Math.max)); //not as strict as java in terms of type/variables checking.


<delcare a class/>
– woo… pretty much like java
dojo.declare(“ClassName”, null, {/*class body*/});

dojo.declare(“Person”, null, {
constructor: function(name, age, currentResidence){
this.name=name;
this.age=age;
this.currentResidence=currentResidence;
},
moveToNewState: function(newState){
this.currentResidence=newState;
}
});
eg. create person class and instantialize it

var matt= new Person(‘Matt’, 25, ‘New Mexico’);

<Arrays and Objects as Member Variables/>
eg.
dojo.declare(“my.classes.bar”, my.classes.foo, {
constructor: function() {
this.someData = [ ]; // each object has it’s own array
},
someData: [1, 2, 3, 4], // doesn’t do what I want: ends up being static
numItem : 5, // one per bar
strItem : “string”, // one per bar
statics: { counter: 0, somethingElse: “hello” } // static variables
});

IMPORTANT:
Why is this true for arrays and objects, but not primitives? It’s because, like most OOP languages, JavaScript uses object references. For example, given:

x = { fruit: “apple” };
y = x;

Now x and y both refer to the same object. Modifying x.fruit will also affect y.fruit.

<inheritance/> – haha, it is java
dojo.declare(“Employee”, Person, {
constructor: function(name, age, currentResidence, position){
// remember, Person constructor is called automatically as the parent
this.password=”";
this.position=position;
},
login: function(){
if(this.password){
alert(‘you have successfully logged in’);
}else{
alert(‘please ask the administrator for your password’);
}
}
});
initialize the subclass
var kathryn=new Employee(‘ Kathryn ‘, 26, ‘Minnesota’, ‘Designer’);

Calling Superclass Methods
someMethod: function() {
// call base class someMethod
this.inherited(arguments);
// now do something else
}

<Mixins/> – multiple inheritance, hmm… java doesn’t do this.
eg. blizzard class will inherit VanillaSoftServe, MandMs, CookiDough
dojo.declare(“VanillaSoftServe”,null, {
constructor: function() { console.debug (“mixing in Vanilla”); }
});
dojo.declare(“MandMs”,null, {
constructor: function() { console.debug(“mixing in MandM’s”); },
kind: “plain”
});
dojo.declare(“CookieDough”,null, {
chunkSize: “medium”
});
dojo.declare(“Blizzard”, [VanillaSoftServe, MandMs, CookieDough], {
constructor: function() {
console.debug(“A blizzard with “+
this.kind+” M and Ms and “+
this.chunkSize+” chunks of cookie dough.”
);
}
});

PS. VanillaSoftServe is the only superclass of Blizzard, others two just mixed in. Does not make sense to me, thinking it as three superclasses makes more sense

<Understanding The Parser/>

Not sure why dojo doc always tries to complicate this part. Parser is just create widget object for your source node.

pretty straight forward:
* locating the nodes with dojoType attributes in the page
* taking the attributes assigned to them and passing them into the constructor as properties on the configuration object
* passing the source node for the widget as the second parameter to the constructor
constructor: function(args, node){}

<modules/>
modularization – namespace, collection of your widgets
function sum() {
var sum1; object level var
sum2; globel var
}

Module Helpers
eg.
var imgNode = document.createElement(“img”);
imgNode.src = dojo.moduleUrl(“explosive.space”,”images/kaboom.gif”);

once the module is binded with the gif. It doesn’t matter where the code snippet is located relative to kaboom.gif.Yeah!!!

Use requireIf to save runtime.
dojo.requireIf(dojo.isIE, “explosive.space.BlueScreenOfDeathCatcher”);

,

2 Comments

XAMPP快速安装

XAMPP, Apache, Mysql, PHP, Perl all in one. 开始你网站开发的第一步只需要短短5分钟。

中国的朋友如果不能看以上youtube视频,这里是ku6的链接 – XAMPP快速安装

, , ,

No Comments

dojo快速安装

One Sentence定义: Dojo是Javascript的一个框架(开源工具包)。

快速安装:

三种方法:

1. 无安装,直接使用AOL’S 的DOJO(Content Distribution Network)或者google api.
2. 本地安装最新的编译后的dojo.
3. 本地维护dojo源码,编译。

总的来说,使用dojo,都需要编译和装载dojo.xd.js.

1. 使用 CDN/Google提供的dojo.  – <推荐>:  想初次体验dojo的初学者

<script type=”text/javascript” src=”http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.xd.js”></script>

<script type=”text/javascript” SRC=”http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js”></script>

2. 本地使用编译过的dojo – <推荐>大多数开发人员

传统方法: 下载编译好的dojo,放在本地服务器使用。

2.1 http://dojotoolkit.org/downloads下载编译最新版本的dojo

2.2 解压到你自己的项目文件夹下,简单起见,把解压后dojo-版本号文件夹改为dojo。Eg.我把解压后的dojo文件夹放在我项目根目录下(apache server)。浏览器中访问http://localhost/dojo/dijit/themes/themeTester.html, 如果能够看到dojo 测试页面,说明安装成功。

3. 编译源代码,DIY版本dojo – <推荐>高级Javascript开发人员

需要更改,维护源程序,使用自定义级别的dojo. IBM, Google很多大公司自己维护自己的dojo版本以及release.

通过repository (http://svn.dojotoolkit.org/src/)下载源程序,自己维护编译。

,

No Comments

如何结束占用端口的线程

比如80端口被占用 (qq音乐开机占用我的80或者是8080端口)。如果你不清楚哪个程序在占用你的端口的话。

windows:

netstat -aon  //找出哪个线程在占用你的80端口,eg.35454线程在占用80端口。

taskkill /pid 35454 //结束占用80端口的程序,现在80端口就可用了。

linux:

lsof -P | grep 80

kill 35454

, , ,

No Comments

提升网站人气九招

拥有一个网站,什么更重要,更多的点击,更多的浏览还是让你的网站内容更有吸引力?听起来好像点击率和网站内容有吸引力是一码事。实际是这是不同的两个概念。很多网站的owner太注重于网站的点击率,太在意网站的浏览量,却忽略了很重要的一点:“ 网站的内容”。网站是一个体现你的内容的平台,却不是唯一的平台。

成功的网站明白这个原则。以Amazon为例,Amazon的主要目的是卖东西。酷六的主要目的是利用视频奠定广告平台。所以网站内容是最重要的,而不是网站本身

作 为一个网站owner,更值得思考的问题是,当你有了内容的时候,如何通过网络手段去呈现。现在火热社区网站facebook.com, kaixin001.com甚至是xiaonei.com,以网站形式建立起网络社区,这是非常重要的策略让网友无形之中与你的网站绑定,让网络社区成为 他们生活的一部分,好比油盐酱醋。所以我们一直强调“royal vistor” – 忠实网友。网站的内容,呈现形式直接影响浏览网友的忠诚度。所以当网站owner在考虑如何提高网站可见度,如何带来更多点击率的时候。应该集中精力使用 不同的网络方式,网络技术去更好的呈现网站的内容。网站只是个载体,内容才是最重要的

这里介绍九招(tips)如何提高个人网站的可见度

1. 开发网站的桌面程序。

ebay为例,ebay的客户在实时的买卖货物。他们需要的远远不止网页形式。他们希望能够在没有登录ebay网站帐号的时候,也有 桌面提醒,桌面程序操作货品买卖(很多人还是习惯桌面程序的操作,hehe, 我女朋友始终埋怨我没有给她装office在电脑上,而强迫她用google online doc)。很多人会想,这会不会太麻烦,维护自己的网站就已经很头疼了,现在你还让我开发客户端程序。我承认,自己去开 发客户端桌面程序会非常麻烦。但是有了Adobe AIR平台,将你的网站内容转移到桌面程序就很简单了。

ebay-20090422-150905

但是作为网站owner,你要思考你的客户,你的visitors是否需要桌面程序?这招是否适合你的网站内容。

2. 手机网络平台。

现 在越来越多的人开始使用黑莓(blackberry), iphone, N95, N96。这些手机都带有上网功能。现在很多的网站数据分析的结果都显示,很大一部分网站的访问是直接来之移动电话。这就给了我们所有的网站owner一个 提示。手机网络已经是一个不得不占领的市场了。但是随着网站内容的不同,手机的支持也有所不同:

建立网站的手机版本 – 手机版本跟网站版本稍有不同,屏幕更小,很多功能手机不支持,比如说,手机是不可能支持网站按钮的onclick事件。

手机短信 – 如果手机版的网站是个太难的选择,也许手机信息系统,notification 或者是 updates 会被及时的短信给用户,也会是一个很有用的卖点。

手机程序 – 开发网站手机程序支持iphone, blackberry 等等也会让用户受益匪浅。

3. 使用tweeting.

如 果你还没有听过twitter,我会忍住不笑你,但是有人可能会笑你是山顶洞人。twitter是一个让用户online做所谓的status update,简单的讲,你对全世界宣布“我现在在干嘛?”。对你感兴趣或者对你所做的事情有兴趣的其他twitter用户可以选择跟踪(follow) 你。这样你的每一部行踪,动态都会他们都会了如指掌。建立你自己网站的twitter账户,公布你网站的一举一动,利用twitter的平台做 internet level广播。自然你网站的可见度就高了。其他网友会通过搜索twitter找到你的内容。

cnn-twitter

cnn-twitter

4. 网站间充分的互相利用
不要总是觉得你的网站,你提及到其他相关网站就会带走你的浏览者,降低你的点击率。在自己的网站内容中提及到其他网站,这充分的显示你网站内容的充实和专业性。同理,到其他的网站,blog,公共社区平台去发表一些自己网站的介绍,利用已有的网络平台,免费的广告自己。

5. 拥抱facebook 和 开心网
跟使用twitter一样的道理,建立你网站的facebook 账户或者开心网账户,利用这些成熟的网络社区,对你自己的网站做最好的推广。

这里以facebook 为例:
a. 创建网站group.
b. 创建网站group的fan page.这里你可以填入你的网站主要涉及什么内容,哪些方面。简单的说,就是做一个网站内容的介绍。介绍越详细越贴切,网友就更能够通过搜索找到你的group,参与到你的网站中。
c. 很多社交网站甚至允许你基于他们的平台,开发你自己的第三方程序。

根据网站的具体内容,分析你的浏览者大多都在哪个社区。例如,如果你的浏览者大多都是大学生,他们也许大部分都在校内网,开心网注册。所以这两个社区平台也许是你最佳的切入点。

开心网群组

6. 开发widget和API

开 发网站的widget,开放性的API。用我的话讲,如果你开发了自己的API和widget,让全世界的网络开发人员都能轻松的把你的网站内容以 widget的形式嵌入到他们的网站中。成千上万的widget供你选择和使用。还是用twitter为例,因为twitter开发了一系列的API powerful API, 成千上万的开发者让你能够不到twitter就可以看到所有的twitter内容。

tweet widget

tweet widget

7. 提供更好的种子 (feed)

这个不用我多说,应该大家都知道feed的重要性。当用户RSS你的网站feed后,能够提供完美,稳定的种子是非常重要的。很多用户使用Google Reader 或者其他feed reader,长期保持和确认你的种子在这些reader中正确的显示。

8. 多媒体手段

越来越多的网站使用多媒体的方式,迅速的让新用户熟悉网站系统,结构。让新用户快速上手。适当的采用多媒体形式,能够让你的网站轻松简单的被广大不是电脑专家的网友迅速接受。Wine Library TV 合理的利用了多没体做内容呈现。

wine

9. 不要忘记email

现 在我敢说每个使用网络的人,拥有至少一个email.email 也许是一个网站能够接触到用户最简单,最快速的方法。如果用户订阅你的网站内容,让他们以邮件形式订阅网站内容更新也不是一件难事。qq订阅是一个非常成 功的例子,值得大家去借鉴和学习。

,

1 Comment

sql基于时间查询(select)

返回所有posts表中,2009年5月13号到16号的记录。created是posts表的timestamp。

select * from posts where date(created) bettwen date(2009-05-13) and date(2009-05-16)

除了date(),还有year(),month(),day()可以使用。year(2009-05-13) 返回2009,month(2009-05-13)返回05,day(2009-05-13)返回13

Happy Coding…

2 Comments