Skip to content

Instantly share code, notes, and snippets.

@zzuhan
zzuhan / ajax.js
Created October 24, 2012 16:36
simple ajax
$('#loading').ajaxStart(function () {
$(this).show();
});
$('#loading').ajaxStop(function () {
$(this).hide();
});
$('#send').click(function () {
@zzuhan
zzuhan / drag.js
Last active December 26, 2015 03:19
code_structure simple module
function drag(o){
var params = {
startLeft: 0,
startTop: 0,
_x:
_y:
isDrag: false
};
params.startLeft = o.currentLeft;
@zzuhan
zzuhan / slideshow.js
Last active December 26, 2015 03:19
code_structure singleton
var slideshow = {
context: false,
tabs: false,
timeout: 1000,
slideSpeed: 1000,
tabSpeed: 300,
fx: 'scrollLeft'
init: function () {
this.context = $('#slideshow');
@zzuhan
zzuhan / timer.js
Created October 21, 2013 15:14
code_structure single var
$('#timer').focus(function(){
// turn on timer
startTimer();
}).blur(function(){
// turn off timer
endTimer();
});
var lastValue = "",
@zzuhan
zzuhan / check.js
Created October 29, 2013 01:37
check helpers function
// ECMAScript 5
function isEmpty(obj){
return Object.getOwnPropertyNames(obj).length === 0;
}
function isEmpty(obj){
return Object.keys(obj).length === 0;
}
// compitable
@zzuhan
zzuhan / uniqueid.js
Created November 3, 2013 15:20
create unique cid learn from underscore.js
var uniqueId = function () {
var idCounter = 0;
return function(prefix){
var id = ++idCounter + '';
return prefix ? prefix + id : id;
}
}();
var cid = uniqueId(); // 1
@zzuhan
zzuhan / get-global.js
Created November 23, 2013 02:31
Get global object in any js runtime environment.
(function(){
var global = this;
})();
@zzuhan
zzuhan / exports.js
Last active December 29, 2015 03:49
helper func for exports lib
//
// 适用于node.js,不依赖于其它js,仅是一个库
(function(){
var global = this;
var libName = function () {
}
if(typeof module !== 'undefined') {
@zzuhan
zzuhan / sublime_open_browser.py
Created December 3, 2013 09:20
sublime open_browser command
import sublime, sublime_plugin
import webbrowser
class OpenBrowserCommand(sublime_plugin.TextCommand):
def run(self, edit):
# self.view.insert(edit, 0, "Hello, World!")
url = self.view.file_name();
webbrowser.open_new(url);
@zzuhan
zzuhan / prevent-multi-submit-2.js
Last active December 30, 2015 08:29
防止按钮被多次点击功能的封装
function isInProgress(){
return $submit.prop('disabled') === true;
}
function markInProgress(){
$submit.prop('disabled', true);
}
function markProgressDone(){
$submit.prop('disabled', false);
}