Skip to content

Instantly share code, notes, and snippets.

@houoop
houoop / image type filter
Created November 21, 2012 10:26
js:image-upload-type-filter
if (!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(ths.value)) {
alert("你选择的不是图片文件");
ths.value = "";
return false;
}
@houoop
houoop / knockout-array-filter.js
Created January 9, 2013 05:14
Knockout Array Filter
var match = ko.utils.arrayFirst(self.dialogboxArray(), function(item) {
return newMessage.target === item.name;
});
@houoop
houoop / observable-filter.js
Created January 9, 2013 09:17
observableArray filter prototype extend
ko.observableArray.fn.filterByProperty = function(propName, matchValue) {
return ko.computed(function() {
var allItems = this(), matchingItems = [];
for (var i = 0; i < allItems.length; i++) {
var current = allItems[i];
if (ko.utils.unwrapObservable(current[propName]) === matchValue)
matchingItems.push(current);
}
return matchingItems;
}, this);
@houoop
houoop / knock-paging-extend.js
Created January 9, 2013 10:20
knockout paging extend
ko.extenders.paging = function (target, pageSize) {
var _pageSize = ko.observable(pageSize || 10), // default pageSize to 10
_currentPage = ko.observable(1); // default current page to 1
target.pageSize = ko.computed({
read: _pageSize,
write: function (newValue) {
if (newValue > 0) {
_pageSize(newValue);
}
<!--[if lte IE 7]>
<![endif]-->
@houoop
houoop / css-ellipsis.css
Created January 26, 2013 07:09
CSS 超出文字变省略号
width: 200px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
@houoop
houoop / array dedupe
Created March 21, 2013 05:33
JS数组去重
Array.prototype.dedupe=function () {
var hash={},result=[],
hasown=Object.prototype.hasOwnProperty;
for (var i = this.length - 1; i >= 0; i--) {
if(!hasown.call(hash,this[i])){
hash[this[i]]=1;
result.push(this[i]);
}
};
return result;
@houoop
houoop / uuid.js
Created March 29, 2013 03:08
uuid generater
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
Sublime Text 2 - Default shortcuts cheatsheet (PC keyboard)
-----------------
General
-----------------
* Go to file (CTRL + P)
* Go to project (CTRL + ALT + P)
* Go to methods (CTRL + R)
* Go to line (CTRL + G)
* Toggle side bar (CTRL + KB)
@houoop
houoop / js-event-bind.js
Created April 27, 2013 09:41
js event bind
bind: window.dispatchEvent ? function(el, type, fn, phase) {
el.addEventListener(type, fn, !!phase);
return fn;
} : function(el, type, fn) {
el.attachEvent && el.attachEvent("on" + type, fn);
return fn;
}