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);
    

      

  • 相关阅读:
    安装APK失败,错误代码:INSTALL_FAILED_INVALID_APK 解决方案
    android保持服务不休眠(持续运行)以及唤醒屏幕的方法
    判断Android 当前版本是否为debug版本
    Android 使用WebView加载含有Canvas的页面截屏处理
    喜大普奔,微软Microsoft JDBC Driver For SQL Server已发布到maven中央仓库
    系统架构设计理论与原则、负载均衡及高可用系统设计速记
    Sharing A Powerful Tool For Application Auto Monitor
    Sharing A Powerful Tool For Calculate Code Lines
    关于GC和析构函数的一个趣题
    垃圾回收机制GC知识再总结兼谈如何用好GC
  • 原文地址:https://www.cnblogs.com/Sunnor/p/5812920.html
Copyright © 2011-2022 走看看