Skip to content

Instantly share code, notes, and snippets.

View composite's full-sized avatar
🤡
와이 쏘 씨리우스야 씨벌로마.

Ukjin Yang composite

🤡
와이 쏘 씨리우스야 씨벌로마.
View GitHub Profile
@composite
composite / tjax.first.js
Created August 17, 2012 07:10
My first tiny ajax snippet (test)
function getAjax(url,params,method){
var xhr = XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject && new ActiveXObject("Microsoft.XMLHTTP")) || null;
var _deff = function(){this.fn={};};
_deff.prototype.text=function(fn){this.fn.text=fn;}
var get = new _deff();
xhr.onreadystatechange = function(){
if (xhr.readyState === 4) {
if('text' in get.fn&&typeof(get.fn.text)=='function') get.fn.text.call(xhr,xhr.responseText);
}
};
@composite
composite / micro.script.js
Last active January 13, 2016 00:57
Micro DynamicScript Snippet
/*
by Composite (http://blog.hazard.kr)
reference -
http://stackoverflow.com/questions/4845762/onload-handler-for-script-tag-in-internet-explorer
Usage -
getScript('http://www.domain.com/js/myscript.js','utf-8').then(function(){
myMethod('yay!');
});
@composite
composite / prepared.iframe.js
Last active October 13, 2015 23:37
My prepared iframe request for Javascript. useful for iframe streaming request or form request.
/**
* prepared iFrame for javascript
* Composite (ukjinplant at msn dot com)
* http://composite.tistory.com
* usage :
* preparedFrame('child')
* .prepare(function(){
* form.target='child';
* form.submit();
* }).load(function(){
@composite
composite / setqueue.global.js
Created December 13, 2012 06:24
queue function calling continuous, step friendly, without hanging, but less performance for lot of function calls...
function setQueue(func){
setQueue.fns.push(func);
if(!setQueue.isRun){setQueue.isRun=true;setQueue.invoke();}
} setQueue.delay=0;setQueue.fns=[];
setQueue.invoke=function(){
setTimeout(function(){
if(!setQueue.fns.length||!setQueue.isRun){setQueue.isRun=false;return;}
var fn=setQueue.fns.shift();
if(typeof(fn)=='function') fn();
setTimeout(arguments.callee,setQueue.delay);
@composite
composite / preventkey.js
Created December 14, 2012 00:15
Prevent key for input - useful for keypress event; function based
function preventKey(){
var shift=[].shift,e=window.event;
if(isNaN(+arguments[0])) e=shift.call(arguments)||e;
for(var i=0,len=arguments.length;i<len;i++){if((e.which||e.keyCode)==arguments[i]) return false;}
}
@composite
composite / number.format.js
Last active December 9, 2015 23:18
just format a number. (e,g 40000000 -> 40,000,000)
function numberFormat(n){
if(isNaN(+n)||+n<1e3) return n;
n=n+'';var s='';for(var i=n.length-1;i>=0;i--) s+=n.charAt(i);n='';
for(var i=s.length-1;i>=0;i--) n+=s.charAt(i)+(!(i%3)?',':'');
return n.replace(/,$/,'');
}
@composite
composite / doc.cewith.js
Last active December 10, 2015 23:08
document.createElementWith - Create a prepared element with JSON. this method is currently not W3C Standard, but more convenient.
/*
usege :
document.createElementWith('button',{
attr:{type:'button'},
name:'mybutton',value:'myvalue',
style:{border:'1px solid red'},
init:function(){
this.onclick=function(){
alert('my button clicked.');
};
@composite
composite / xenofw.urlencode.euckr.js
Created August 9, 2013 09:04
urlencoding EUC-KR by Song Hyo-Jin <shj at xenosi.de>
charsetencodes['euckr']={"\uac02":"%81%41","\uac03":"%81%42","\uac05":"%81%43","\uac06":"%81%44","\uac0b":"%81%45","\uac0c":"%81%46","\uac0d":"%81%47","\uac0e":"%81%48","\uac0f":"%81%49","\uac18":"%81%4A","\uac1e":"%81%4B","\uac1f":"%81%4C","\uac21":"%81%4D","\uac22":"%81%4E","\uac23":"%81%4F","\uac25":"%81%50","\uac26":"%81%51","\uac27":"%81%52","\uac28":"%81%53","\uac29":"%81%54","\uac2a":"%81%55","\uac2b":"%81%56","\uac2e":"%81%57","\uac32":"%81%58","\uac33":"%81%59","\uac34":"%81%5A","\uac35":"%81%61","\uac36":"%81%62","\uac37":"%81%63","\uac3a":"%81%64","\uac3b":"%81%65","\uac3d":"%81%66","\uac3e":"%81%67","\uac3f":"%81%68","\uac41":"%81%69","\uac42":"%81%6A","\uac43":"%81%6B","\uac44":"%81%6C","\uac45":"%81%6D","\uac46":"%81%6E","\uac47":"%81%6F","\uac48":"%81%70","\uac49":"%81%71","\uac4a":"%81%72","\uac4c":"%81%73","\uac4e":"%81%74","\uac4f":"%81%75","\uac50":"%81%76","\uac51":"%81%77","\uac52":"%81%78","\uac53":"%81%79","\uac55":"%81%7A","\uac56":"%81%81","\uac57":"%81%82","\uac59":"%81%83","\uac5a":
@composite
composite / jquery.validate.js
Created August 30, 2013 07:50
jQuery validate
(function ($) {
var spes = { checkbox: 1, radio: 1 };
$.fn.validate = function (def, fns) {
if (!this.is('form')) return this;
var form = this.get(0);
if (!arguments.length && $.isFunction(form.__VALIDFUNC)) {
return form.__VALIDFUNC.call(form);
}
if (!$.isPlainObject(def)) return this;
@composite
composite / jQuery.submit.js
Last active December 22, 2015 00:09
a jQuery plugin that have a coffee with HTML form convention.
/**
*
*
* ajax-submit 클래스 추가 시 이벤트 바인딩 (첫번째 인자가 form event 객체임에 유의.)
* <code>
* $('#form').on('ajaxbefore', function(event, jqXHR, settings)); //
* $('#form').on('ajaxcomplete', function(event, jqXHR, testStatus)); //
* $('#form').on('ajaxsuccess', function(event, responseObject, testStatus, jqXHR)); //
* $('#form').on('ajaxerror', function(event, jqXHR, testStatus, errorThrown)); //
* </code>