seajs实现js模块化,功能是提供一组工具供前台开发调用(jquery)

define(function(require, exports, module) {
	var $ =  require('jquery');
	var menu = require('menu');
	var tab = require('tab');
	var util = require('util');
	var container = require('container');	
	var content = require('content');
	var history = require('history');
	var alert = require('alert');
        var sound = require('sound');
	var dialog =  require('dialog');
	exports.ui = {
		dialogKey: 0,
		dialogs: {},
                sounds:{},
	 	init:function(){
	 		new menu($('.menu'),$('.menu_2'));
		},
		error:function(title,infor,timeout){
			var _a=new alert(title,infor,timeout);
			_a.oError();
			return _a;
		},
		warning:function(title,infor,timeout){
			var _a=new alert(title,infor,timeout);
			_a.oWarn();
			return _a;
		},
		success:function(title,infor,timeout){
			var _a=new alert(title,infor,timeout);
			_a.init();
			return _a;
		},
		alert:function(title,infor,timeout){
			var _a=new alert(title,infor,timeout);
			_a.init();
			return _a;
		},
		dialog:function(name,title,options){
			var dialogK = new dialog(name,title,options);
			this.dialogs[name] = dialogK;

		},
		getDialog:function(domId) {
			for(var i in this.dialogs){
				if(this.dialogs[i].domId ==domId){
					return this.dialogs[i];
				}
			}
		},
		container:function(options,id){
			history.add(id);
			if(history.getifsuccess()){
			   new container(options).init();
			}else{
				new container(options).open();
			}
		},
                sound:function(src,path){
                    new sound(src,path).say();
                },
		history:function(){
			return history.gethistoryjson();
		}
	}
});

//单个类实现
define(function(require,exports,module){
/*alert*/
var $ = require('jquery');
module.exports = Alert;
	function Alert(title,infor,timeout){
		timeout=timeout||3000;
		this.title = title || '';
		this.infor = infor || '';
		this.id="alert_"+(new Date()).getTime();
		this.obj = $('<div class="oAlert" id="'+this.id+'"><div class="clear oAlert_title"><h5>'+ this.title +'</h5><em ></em></div><p class="oAlert_infor" >'+ this.infor +'</p></div>');
		setTimeout("$('#"+this.id+" em').click();",timeout);
	}
	Alert.prototype.init = function(){
		var _this = this;	
		$('.body').append(_this.obj);
		binding(this.id);
	}
	Alert.prototype.close = function(){
		this.obj.find("em").click();
	}
})


//调用方法
$F.ui.dialog("purchase","添加内容",{url:'/purchases/add',onclose:function(data){
   //生成提示条
   $F.ui.alert("操作提示",data.message);
});

你可能感兴趣的:(jquery)