Skip to content

Instantly share code, notes, and snippets.

View think2011's full-sized avatar
🏠
Working from home

曾浩 think2011

🏠
Working from home
View GitHub Profile
@think2011
think2011 / limit-max.js
Created May 21, 2015 04:12
directive 限制输入的最大数,最小数无法设置,因为删除时无法判断
var app = angular.module('limit-max', []);
/**
* 限制输入的最大数,最小数无法设置,因为删除时无法判断
* @example
* <input ng-model="xx" type="number" limit-max="100">
*/
app.directive('limitMax', function() {
return {
restrict : 'A',
@think2011
think2011 / ng-tools.js
Last active August 29, 2015 14:22
ng-tools
(function() {
var app = angular.module('tools', []);
/**
* syncCheckboxModalToArray
* @$scope
* @modal string
* @array string
*/
app.factory('syncCheckboxModalToArray', function() {
@think2011
think2011 / fnInterval.js
Last active August 29, 2015 14:23
间隔执行fn
fnInterval(5, 1000, function (index) {
console.log(index);
});
/**
* 间隔执行fn
* @param {number} time 次数
* @param {number} delay 间隔毫秒
* @param {Function} fn fn(index) index从1开始
*/
@think2011
think2011 / setViewPort.js
Last active August 29, 2015 14:23
设置窗口宽度
setViewPort(640);
/**
* 设置窗口宽度
* @param width
*/
function setViewPort(width) {
var scale = window.screen.width / width,
isAndroid = /Android (\d+\.\d+)/.test(navigator.userAgent);
@think2011
think2011 / Function.prototype.after&before.js
Created July 30, 2015 07:12
装饰者模式,after | before
Function.prototype.after = function (fn) {
var that = this;
return function () {
var ret = that.apply(this, arguments);
fn.apply(this, arguments);
return ret;
};
@think2011
think2011 / ToggleMenu.js
Created August 6, 2015 05:41
生成一个手风琴菜单
/**
* 生成一个手风琴菜单
* @param $mainDom
* @param items
* @constructor
*/
function ToggleMenu ($mainDom, items) {
this.$mainDom = $mainDom;
this.items = items;
@think2011
think2011 / getJsDir.js
Last active October 27, 2015 02:26
获取js所在路径
function getJsDir (src) {
var script = null;
if (src) {
script = [].filter.call(document.scripts, function (v) {
return v.src.indexOf(src) !== -1;
})[0];
} else {
script = document.scripts[document.scripts.length - 1];
}
@think2011
think2011 / onerror.js
Last active August 31, 2015 03:27
从全局捕获错误
/**
* 从全局捕获错误
* @param errMsg
* @param scriptURI
* @param lineNumber
* @param columnNumber
* @param errorObj
* @return
*/
window.onerror = function (errMsg, scriptURI, lineNumber, columnNumber, errorObj) {
@think2011
think2011 / 触发事件.js
Created September 11, 2015 17:59
触发事件
/**
* 触发事件
* @param element
* @param event
* @returns {boolean}
*/
function fireEvent (element, event) {
var evt;
if (document.createEventObject) {
@think2011
think2011 / toInt.js
Last active October 22, 2015 10:07
转换为整数
/**
* 转换为整数
* @returns {this}
*/
Number.prototype.toInt = function () {
return isNaN(this) ? 0 : parseInt(this);
};