ZeroClipboard 소스 읽기 - 1.$요소 찾기

1288 단어 ZeroClipboard
ZeroClipboard 소스 읽기 - 1.$요소 찾기
 
	$: function(thingy) {
		// simple DOM lookup utility function
		// dom 
		if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
		if (!thingy.addClass) {
			// extend element with a few useful methods
			thingy.hide = function() { this.style.display = 'none'; };
			thingy.show = function() { this.style.display = ''; };
			thingy.addClass = function(name) 
                       { this.removeClass(name); this.className += ' ' + name; };
			thingy.removeClass = function(name) {
				// name , splice 
				var classes = this.className.split(/\s+/);
				var idx = -1;
				for (var k = 0; k < classes.length; k++) {
					if (classes[k] == name) { idx = k; k = classes.length; }
				}
				if (idx > -1) {
					classes.splice( idx, 1 );
					this.className = classes.join(' ');
				}
				return this;
			};
			thingy.hasClass = function(name) {
				//  !!(0,null,"",undefinied) 
				return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
			};
		}
		return thingy;
	},

좋은 웹페이지 즐겨찾기