zoukankan      html  css  js  c++  java
  • linkbutton.js

    jquery.linkbutton.js

    /**
     * linkbutton - jQuery EasyUI
     * 
     * Licensed under the GPL:
     *   http://www.gnu.org/licenses/gpl.txt
     *
     * Copyright 2010 stworthy [ stworthy@gmail.com ] 
     */
    (function($){
    	
    	function createButton(target) {
    		var opts = $.data(target, 'linkbutton').options;
    		
    		$(target).empty();
    		$(target).addClass('l-btn');
    		if (opts.id){
    			$(target).attr('id', opts.id);
    		} else {
    			$(target).removeAttr('id');
    		}
    		if (opts.plain){
    			$(target).addClass('l-btn-plain');
    		} else {
    			$(target).removeClass('l-btn-plain');
    		}
    		
    		if (opts.text){
    			$(target).html(opts.text).wrapInner(
    					'<span class="l-btn-left">' +
    					'<span class="l-btn-text">' +
    					'</span>' +
    					'</span>'
    			);
    			if (opts.iconCls){
    				$(target).find('.l-btn-text').addClass(opts.iconCls).css('padding-left', '20px');
    			}
    		} else {
    			$(target).html(' ').wrapInner(
    					'<span class="l-btn-left">' +
    					'<span class="l-btn-text">' +
    					'<span class="l-btn-empty"></span>' +
    					'</span>' +
    					'</span>'
    			);
    			if (opts.iconCls){
    				$(target).find('.l-btn-empty').addClass(opts.iconCls);
    			}
    		}
    		
    		setDisabled(target, opts.disabled);
    	}
    	
    	function setDisabled(target, disabled){
    		var state = $.data(target, 'linkbutton');
    		if (disabled){
    			state.options.disabled = true;
    			var href = $(target).attr('href');
    			if (href){
    				state.href = href;
    				$(target).attr('href', 'javascript:void(0)');
    			}
    			var onclick = $(target).attr('onclick');
    			if (onclick) {
    				state.onclick = onclick;
    				$(target).attr('onclick', null);
    			}
    			$(target).addClass('l-btn-disabled');
    		} else {
    			state.options.disabled = false;
    			if (state.href) {
    				$(target).attr('href', state.href);
    			}
    			if (state.onclick) {
    				target.onclick = state.onclick;
    			}
    			$(target).removeClass('l-btn-disabled');
    		}
    	}
    	/**
    	 * 扩展jQuery对象的属性方法
    	 */
    	$.fn.linkbutton = function(options){
    		if (typeof options == 'string'){
    			switch(options){
    			case 'options':
    				return $.data(this[0], 'linkbutton').options;
    			case 'enable':
    				return this.each(function(){
    					setDisabled(this, false);
    				});
    			case 'disable':
    				return this.each(function(){
    					setDisabled(this, true);
    				});
    			}
    		}
    		
    		options = options || {};
    		return this.each(function(){
    			var state = $.data(this, 'linkbutton');
    			if (state){
    				$.extend(state.options, options);
    			} else {
    				var t = $(this);
    				$.data(this, 'linkbutton', {
    					options: $.extend({}, $.fn.linkbutton.defaults, {
    						id: t.attr('id'),
    						disabled: (t.attr('disabled') ? true : undefined),
    						plain: (t.attr('plain') ? t.attr('plain') == 'true' : undefined),
    						text: $.trim(t.html()),
    						iconCls: t.attr('icon')
    					}, options)
    				});
    				t.removeAttr('disabled');
    			}
    			
    			createButton(this);
    		});
    	};
    	
    	$.fn.linkbutton.defaults = {
    			id: null,
    			disabled: false,
    			plain: false,
    			text: '',
    			iconCls: null
    	};
    	
    })(jQuery);
    

      

  • 相关阅读:
    在energia中添加新的库
    KEIL3中出现的字符不对齐的情况解决办法
    VHDL硬件描述语言实现数字钟
    51单片机软件I2C驱动中的CY
    自问自答:在VB中如何实现像C++一样printf的功能
    [转][译] 分分钟学会一门语言之 Python 篇
    杂谈PID控制算法——最终篇:C语言实现51单片机中的PID算法
    Eclipse 安装与配置
    win10 环境安装 jdk 11.0.2
    解决网络问题神奇工具
  • 原文地址:https://www.cnblogs.com/Sunnor/p/5812920.html
Copyright © 2011-2022 走看看