⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 14.06 - directory lookup example.js

📁 JS设计模式源代码
💻 JS
字号:
/* Directory interface. */var Directory = new Interface('Directory', ['showPage']);/* PersonnelDirectory class, the Real Subject */var PersonnelDirectory = function(parent) { // implements Directory  this.xhrHandler = XhrManager.createXhrHandler();  this.parent = parent;  this.data = null;  this.currentPage = null;  var that = this;  var callback = {    success: that._configure,    failure: function() {       throw new Error('PersonnelDirectory: failure in data retrieval.');     }  }  xhrHandler.request('GET', 'directoryData.php', callback); };PersonnelDirectory.prototype = {  _configure: function(responseText) {    this.data = eval('(' + reponseText + ')');    ...    this.currentPage = 'a';  },  showPage: function(page) {    $('page-' + this.currentPage).style.display = 'none';    $('page-' + page).style.display = 'block';    this.currentPage = page;  }};/* DirectoryProxy class, just the outline. */var DirectoryProxy = function(parent) { // implements Directory};DirectoryProxy.prototype = {  showPage: function(page) {      }};/* DirectoryProxy class, as a useless proxy. */var DirectoryProxy = function(parent) { // implements Directory  this.directory = new PersonnelDirectory(parent);};DirectoryProxy.prototype = {  showPage: function(page) {    return this.directory.showPage(page);  }};/* DirectoryProxy class, as a virtual proxy. */var DirectoryProxy = function(parent) { // implements Directory  this.parent = parent;  this.directory = null;  var that = this;  addEvent(parent, 'mouseover', that._initialize); // Initialization trigger.};DirectoryProxy.prototype = {  _initialize: function() {    this.directory = new PersonnelDirectory(this.parent);  },  showPage: function(page) {    return this.directory.showPage(page);  }};/* DirectoryProxy class, with loading message. */var DirectoryProxy = function(parent) { // implements Directory  this.parent = parent;  this.directory = null;  this.warning = null;  this.interval = null;  this.initialized = false;  var that = this;  addEvent(parent, 'mouseover', that._initialize); // Initialization trigger.};DirectoryProxy.prototype = {  _initialize: function() {    this.warning = document.createElement('div');    this.parent.appendChild(this.warning);    this.warning.innerHTML = 'The company directory is loading...';    this.directory = new PersonnelDirectory(this.parent);    var that = this;    this.interval = setInterval(that._checkInitialization, 100);  },  _checkInitialization: function() {    if(this.directory.currentPage != null) {      clearInterval(this.interval);      this.initialized = true;      this.parent.removeChild(this.warning);    }  },  showPage: function(page) {    if(!this.initialized) {      return;    }    return this.directory.showPage(page);  }};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -