fd-gulp-convert-encoding
Version:
convert file to assigned charset
142 lines • 5.46 kB
JavaScript
/**
* ���������û��Ӵ��ռ�չʾ��Ŀ
* @author : yu.yuy
* @createTime : 2011-9-20
*/
jQuery.namespace('FE.operation.module');
(function($,M){
var win = window,
doc = document;
M.Category = function(options){
this.init(options);
},
M.Category.prototype = {
init : function(options){
var parentCategoriesSelector = options.parentCategoriesSelector;
this.subCategorySelector = options.subCategorySelector;
this.enterTimer = null;
this.leaveTimer = null;
this.currentIndex = null;
this.hasSubCategoryOpened = false;
this.subCategoryCache = function(){
var o = {};
return {
hasStoraged : function(i){
return !!o[i];
},
getSubCategory : function(i){
return o[i]['el'];
},
getSubCategoryHeight : function(i){
return o[i]['height'];
},
store : function(i,subEl,height){
o[i] = {
el : subEl,
height : height
}
}
};
}();
this.adjustment = options.adjustment || 0;
this.parentCategoriesList = $('#'+options.parentCategoriesListId);
this.parentCategories = $.makeArray(this.parentCategoriesList.children(parentCategoriesSelector));
this.parentCategoriesListPosition = this.parentCategoriesList.offset();
this.parentCategoriesListTop = this.parentCategoriesListPosition.top;
this.parentCategoriesList.delegate(parentCategoriesSelector,'mouseenter',$.proxy(this.showSubCategory, this));
this.parentCategoriesList.delegate(parentCategoriesSelector,'mouseleave',$.proxy(this.hideSubCategory, this));
},
/**
* ���������Ŀ�ĺ������λ�ø߶�
* @return ret ����Ŀ�����λ�ø߶�
* @param h ����Ŀ�߶�
* @param vh �Ӵ��߶�
* @param ah ��Ŀ���ɵľ���λ�ø߶�
* @param ph ������Ŀ�ľ���λ�ø߶�
* @param st ��ǰ�Ӵ��Ĺ����߶�
*/
locate : function(h,vh,ah,ph,st){
var top = 0;
if(ah >= st){
if(h <= vh-ph+st){
top = 0;
}
else if((h>vh-ph+st)&&(h<=vh-ah+st)){
top = vh-ph+st-h;
}
else{
top = ah-ph;
}
}
else if(st>ah && st<ph){
if(h <= vh-ph+st){
top = 0;
}
else if((h>vh-ph+st) && h<=vh){
top = vh-ph+st-h;
}
else{
top = st-ph;
}
}
else{
top = 0;
}
return top+this.adjustment;
},
showSubCategory : function(e){
var el = e.currentTarget,
that = this,
cache = that.subCategoryCache,
viewportHeight,
scrollTop,
subEl,
height,
elTop,
subRelativeTop,
index = that.parentCategories.indexOf(el);
if(that.currentIndex===index && that.leaveTimer){
clearTimeout(that.leaveTimer);
}
if(that.hasSubCategoryOpened && that.currentIndex===index){
return;
}
that.enterTimer = setTimeout(function(){
that.currentIndex = index;
viewportHeight = $(win).height();
scrollTop = $(doc).scrollTop();
if(cache.hasStoraged(index)){
subEl = cache.getSubCategory(index);
height = cache.getSubCategoryHeight(index);
}
else{
subEl = $(el).children('.'+that.subCategorySelector).first();
height = subEl.outerHeight();
cache.store(index,subEl,height);
}
elTop = $(el).offset().top;
subRelativeTop = that.locate(height,viewportHeight,that.parentCategoriesListTop,elTop,scrollTop);
$(el).addClass('current');
$(subEl).css('top',subRelativeTop+'px');
that.enterTimer = null;
that.hasSubCategoryOpened = true;
},300);
},
hideSubCategory : function(e){
var that = this,
el = e.currentTarget,
index = that.parentCategories.indexOf(el);
if(that.enterTimer){
clearTimeout(that.enterTimer);
}
if(!that.hasSubCategoryOpened || that.currentIndex!==index){
return;
}
that.leaveTimer = setTimeout(function(){
$(el).removeClass('current');
that.leaveTimer = null;
that.hasSubCategoryOpened = false;
},300);
}
};
})(jQuery,FE.operation.module);