Skip to content

Instantly share code, notes, and snippets.

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

曾浩 think2011

🏠
Working from home
  • Guangzhou, China
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / PollAjax.js
Last active August 29, 2015 14:19
PollAjax
/**
* 轮询ajax请求
* @param fn
* @param [delay = 500]
* @constructor
* @example
* var pa = new PollAjax(function (continueNext, done) {
$.get('../')
.done(function (data) {
if (data.success) {
@think2011
think2011 / Watermark.js
Created April 11, 2015 09:41
给图片加水印
/**
* 给图片打文字水印
* @param img Object||String
* @param opt
* @constructor
*/
function Watermark(img, opt) {
this.opt = opt;
@think2011
think2011 / close.js
Last active August 29, 2015 14:18
关闭窗口
window.closeWindow = function () {
window.open('', '_self', '');
window.close();
};