Magento中获取指定会员下的所有订单

2010-08-04 11:21:49.0

magento中如果我们需要在会员的控制面板中获取该会员的所有订单,我们可以使用下面的方法来获取指定会员下的所有订单

$customerId=userId;
$limit=10;
$orders=Mage::getResourceModel('sales/order_collection');
$orders->addAttributeToFilter('customer_id', $customerId)->getSelect()->order('e.entity_id desc')
->limit($limit);

改造jQuery lazyLoad插件

2010-07-30 13:01:16.0

最近前端数据延迟加载(lazyload)技术很流行...

淘宝,新浪网都有使用延迟加载技术,

这样做的目的可以使得一些未在本屏幕显示的图片随着滚动条的滚动进行延迟显示。

好处显而易见,可以减少客户端对服务器端图片的Http请求,减轻服务器的压力,

对于长篇并且大批量的图片的网页效果非常明显

可惜淘宝网的延迟加载是基于YUI写的。。

 

Java实现blog ping

2010-07-28 16:37:49.0

想给博客加上pingback的功能,在百度,google中一顿乱搜,相关的文章好少。。

然后再各大源代码搜索引擎中寻找也没有找到有关于任何blog ping的文章...

我说的没有是指没有blog ping的实现原理,相关代码示例等。。

倒是找到了通过ping服务加快各搜索引擎

收录博客文章的一些介绍文章,so用Java实现blog ping功能来提高搜索引擎对博客的收录速度

通过网上的文章,东了解一点,西了解一点弄了个简单的blog ping功能,一更新文章后自动ping百度,goole等提供自动ping服务的中文搜索引擎或者RSS聚合

Java实现标签云

2010-07-24 17:15:47.0

博客的标签云功能实现已经很久了,但是只有标签功能,没有云的功能,囧!~~~

标签云主要有以下几点重要的 功能:

能根据标签下面文章的多少来决定标签的显示样式的大小

标签云能实现随机颜色

这样标签云就能云起来了,每个标签的字体大小根据数量来决定,数量越多的字体越大,最小的数量也使用12px字体,这样看起来不会太累,颜色直接随机好了

public void tag_cloud(Map<String, Integer> tags) {
int maxsize = 38;//最大字体大小
int minsize = 12;
List<Integer> list2 = CollectionUtils.toList(tags);//这里是我自己的内库实现的map转换为list
int maxval = CollectionUtils.max(list2);//获取标签下文章数量的最大值
int minval = CollectionUtils.min(list2);//获取最小值
int spread = maxval - minval;
int step=1;
if(spread!=0)
step = (maxsize - minsize) / spread;
String[] color = new String[] { "#FF0000", "#FFCC00", "#FF9900",
        "#0099FF", "#999999" };
Iterator<String> it = tags.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
int val = tags.get(key);
int index = RandomUtil.nextInt(0, color.length - 1);//产生0到数组长度的随机数字,来实现随机颜色
int size = Math.round(minsize + ((val - minval) * step));
System.out.println("<a href=\"#\" style=\"font-size:"+size+"px;color:"+color[index]+"\">"+key+"</a>");
}
}

ajax请求中高效率的获取XMLHttpRequest

2010-07-24 16:13:25.0

现在一直都是用jquery的ajax,对于原生js的ajax的原理 只能看懂....却不会写,翻开保存的网络资料,刚好找到司徒的一篇高效的获取XMLHttpRequest,剔除了原文中他自己框架中的代码。。。

本文仅记录ajax原理中的xmlhttprequest对象的创建.....

首先是W3C标准的XMLHttpRequest对象,微软从IE7开始也支持XMLHttpRequest对象,so我们在支持W3C标准的现代浏览器中(包括 IE 7)只需要

js通过classname来获取元素

2010-07-21 12:10:16.0

原生JS有3种方式来获取元素:

  1. getElementById('id')
  2. getElementsByName('name')
  3. getElementsByTagName('tag')

getElementById是获取元素最快的方式,但我们不能给每个HTML元素都加以ID吧,所以我们需要一个很方便的通过classname来获取元素:

function getElementsByClassName(className,tagName){
var ele=[],all=document.getElementsByTagName(tagName||"*");
for(var i=0;i<all.length;i++){
if(all[i].className==className){
ele[ele.length]=all[i];
}
}
return ele;
}
console.log(getElementsByClassName("entry"));
console.log(getElementsByClassName("entry","div"));

Array数组的each方法

2010-07-20 16:10:44.0

在jQuery中有个很方便的each方法来遍历数组,Firefox中的Array也有each方法,这里我们自己实现一个array的each方法

Array.prototype.each = function( callback ){ 
for( var i = 0 ,j = this.length ; i < j ; i++ ){ 
    callback.call( this, this[i], i ); 
      }    
   } 

SEO中meta标签的优化技巧

2010-07-15 14:52:35.0

seo中meta标签的优化很多人都很了解,这是做为一个SEO最起码的标志,但很多SEOER不能很好的运

用,往往meta标签成了简单的关键词的叠加,这样对搜索引擎来说很不友好,从用户体验角度

来说也起不到很好的引导效果。

Title

  用一句通顺的语句介绍自己网页的内容,根据需要优化的关键词的重要度来包含你想优化的词,这样就可以让用户知道你想要表达什么

  要把最重要的关键词放在最前面,不要出现特殊符号,字数一般20字左右,融入长尾关键词,保持标题的可读性和美观,不要出现干扰文字

js框架中类继承的比较

2010-07-13 09:24:16.0

首先我们来看下jQuery之父john resig的实现方法:

jq之父写的类继承方式的特点是:

  • 有私有变量
  • 可以写在一个构造函数中
  • 可以多级继承,可以有多个父类(需要某种特定格式)
  • 继承基于prototype,且不会执行父类的构造函数
  • 保持了父类的函数链,可以在子类中用this._super简单调用
  • instanceof 对子类、父类都生效

这是目前为止我看到的最好的方法。除了定义了一个全局变量Class外

// Inspired by base2 and Prototype
(function(){
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing)
this.Class = function(){};
// Create a new Class that inherits from this class
Class.extend = function(prop) {
var _super = this.prototype;
// Instantiate a base class (but only create the instance,
// don't run the init constructor)
initializing = true;
var prototype = new this();
initializing = false;
// Copy the properties over onto the new prototype
for (var name in prop) {
// Check if we're overwriting an existing function
prototype[name] = typeof prop[name] == "function" &&
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
(function(name, fn){
return function() {
var tmp = this._super;
// Add a new ._super() method that is the same method
// but on the super-class
this._super = _super[name];
// The method only need to be bound temporarily, so we
// remove it when we're done executing
var ret = fn.apply(this, arguments);
this._super = tmp;
return ret;
};
})(name, prop[name]) :
prop[name];
}
// The dummy class constructor
function Class() {
// All construction is actually done in the init method
if ( !initializing && this.init )
this.init.apply(this, arguments);
}
// Populate our constructed prototype object
Class.prototype = prototype;
// Enforce the constructor to be what we expect
Class.constructor = Class;
// And make this class extendable
Class.extend = arguments.callee;
return Class;
};
})();

jquery.add()追加元素

2010-07-12 15:02:21.0

我们先来看下jQuery官方文档上add()方法的使用

1)add(expr)  在原对象的基础上附加符合指定表达式的jquery对象 

2)add(el)  在匹配对象的基础上附加指定的dom元素。

3)add(els)  在匹配对象的基础上附加指定的一组对象,els是一个数组。

4)add(html)在匹配对象的基础上再附加指定的一段HTML片段