JavaScript - JSLoader.js

 

/**
 * js动态加载器
 * @class ScriptLoader.prototype
 * @extends Ext.Window
 * @author nb
 * @version 20110812
 */


ScriptLoader = function() {
 this.timeout = 30;
 this.scripts = [];
 this.disableCaching = false;
 this.loadMask = null;
};
ScriptLoader.prototype = {
 showMask : function() {
  if (!this.loadMask) {
   this.loadMask = new Ext.LoadMask(Ext.getBody());
   this.loadMask.show();
  }
 },
 hideMask : function() {
  if (this.loadMask) {
   this.loadMask.hide();
   this.loadMask = null;
  }
 },
 processSuccess : function(response) {
  this.scripts[response.argument.url] = true;
  window.execScript ? window.execScript(response.responseText) : window
    .eval(response.responseText);
  if (response.argument.options.scripts.length == 0) {
   this.hideMask();
  }
  if (typeof response.argument.callback == 'function') {
   response.argument.callback.call(response.argument.scope);
  }
 },
 processFailure : function(response) {
  this.hideMask();
  Ext.MessageBox.show( {
   title : '提示',
   msg : '抱歉,加载失败! 错误代码:#1527',
   closable : false,
   icon : Ext.MessageBox.ERROR,
   minWidth : 200
  });
  setTimeout(function() {
   Ext.MessageBox.hide();
  }, 3000);
 },
 load : function(url, callback) {
  var cfg, callerScope;
  if (typeof url == 'object') { // must be config object   
  cfg = url;
  url = cfg.url;
  callback = callback || cfg.callback;
  callerScope = cfg.scope;
  if (typeof cfg.timeout != 'undefined') {
   this.timeout = cfg.timeout;
  }
  if (typeof cfg.disableCaching != 'undefined') {
   this.disableCaching = cfg.disableCaching;
  }
 }
 if (this.scripts[url]) {
  if (typeof callback == 'function') {
   callback.call(callerScope || window);
  }
  return null;
 }
 this.showMask();
 Ext.Ajax.request( {
  url : url,
  success : this.processSuccess,
  failure : this.processFailure,
  scope : this,
  timeout : (this.timeout * 1000),
  disableCaching : this.disableCaching,
  argument : {
   'url' : url,
   'scope' : callerScope || window,
   'callback' : callback,
   'options' : cfg
  }
 });
}
};


ScriptLoaderMgr = function() {
 this.loader = new ScriptLoader();
 this.load = function(o) {
  if (!Ext.isArray(o.scripts)) {
   o.scripts = [ o.scripts ];
  }
  o.url = o.scripts.shift();
  if (o.scripts.length == 0) {
   this.loader.load(o);
  } else {
   o.scope = this;
   this.loader.load(o, function() {
    this.load(o);
   });
  }
 };
};


JSLoader = new ScriptLoaderMgr();


//使用方式
//JSLoader.load({   
//    scripts: ["1.js", "2.js", "3.js"], //地址数据,用到几个传几个地址  
//    callback: function() {
//  //加载成功后的一系列操作,此函数可以去除
//    }
//});

$(_tt).datagrid({ collapsible : true, rownumbers : true, remoteSort : false, nowrap : true, fitColumns : false, singleSelect : false, fit : true, striped : true, pagination : true, pageSize : pageSize, pageList : pageList, queryParams : getParams(), iconCls : 'icon-edit', idField : 'ID', url : _url_list, frozenColumns : [ [ { field : 'ck', checkbox : true }, { title : $.pde.message['common.button.operate'], field : 'viewFile', width : 70, sortable : false, align : 'center', formatter : function(value, rec, index) { var a = '<a href="javascript:void(0)" style="border:none;" onclick="$.pde.jsLoader.datagridClick('filemanager', ' + rec.ID + ')">'; a += '<img src="' + _path + 'js/jquery/themes/icons/pdeIcon/file-management.png" class="pdeGridImg" title="' + $.pde.message['p9.common.archives.manager.menu.fileManager'] + '" style="height:15px;"/>'; a += '</a>'; var b = '<a href="javascript:void(0)" style="border:none;" onclick="$.pde.jsLoader.call('js/p9/amc/library/commonEntry.js', 'viewBox', ' + rec.ID + ')">'; b += '<img src="' + _path + 'js/jquery/themes/icons/pdeIcon/view.png" class="pdeGridImg" title="' + $.pde.message['p9.amc.AmsArchivesManager.jsp.itemDetail'] + '" style="height:15px;"/>'; b += '</a>'; return a + b; } }, { title : 'ID', field : 'ID', width : 30, sortable : false, hidden : true } ] ], columns : getColumnsByFields(_listFields), onLoadSuccess : function() { var amsResource = $.pde.power.resource; $.pde.power.getPower({ url : _path + amsResource.url + '/' + amsResource.amsInterfaceFileManager + '/' + _fonds_id, menu : '#functionMenu' }); }, onDblClickRow : function(rowIndex, rowData) { $.pde.jsLoader.call('js/p9/amc/library/commonEntry.js', 'viewBox', rowData.ID); } }); $.pde.jsLoader.call('js/p9/amc/library/commonGroup.js', 'customGroupView2', undefined);翻译一下这段代码的意思
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值