博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mootools_使用MooTools执行/撤消功能
阅读量:2512 次
发布时间:2019-05-11

本文共 2588 字,大约阅读时间需要 8 分钟。

mootools

We all know that do/undo functionality is a God send for word processing apps. I've used those terms so often that I think of JavaScript actions in terms of "do" an "undo." I've put together a proof of concept Do/Undo class with MooTools.

我们都知道,做/撤消功能是文字处理应用程序的上帝之选。 我经常使用这些术语,以至于我将JavaScript动作理解为“执行”和“撤消”。 我已经用MooTools组合了概念验证Do / Undo类。

MooTools类 (The MooTools Class)

(function($){		this.DoUndo = new Class({				//initialization		initialize: function() {			this.registry = {};		},				//register something you'd do		register: function(key,doo,undo,arguments) {			this.registry[key] = {				'doo': doo || $empty,				'undo': undo || $empty,				'args': arguments			};		},				//do it!		doo: function(key) {			return this.registry[key]['doo'](this.registry[key]['args']);		},				undo: function(key) {			return this.registry[key]['undo'](this.registry[key]['args']);		}	});		})(document.id);

Once you've created your class instance you need to register your do's/undo's by providing a key, do function, undo function, and your arguments. From then on out you just call doo and undo methods, providing the key of course, to make it happen.

创建类实例后,您需要通过提供键,do函数,undo函数和参数来注册do / undo。 从那时起,您只需调用doo和undo方法即可,当然要提供实现它的关键。

样本用法 (The Sample Usage)

//usagewindow.addEvent('domready',function(){	//instance	var dooer = new DoUndo();	//set up an do/undo command	dooer.register('toggle-submit',function(submit) {		submit.fade('out');	},function(submit) {		submit.fade('in');	},$('submit'));	//use	$('hider').addEvent('click',function() { dooer.doo('toggle-submit'); });	$('shower').addEvent('click',function() { dooer.undo('toggle-submit'); });});

This do/undo does simple show/hide of a button.

执行/撤消操作简单地显示/隐藏按钮。

货物 (The Goods)

  • I like the terminology: do and undo, just like every word processing application you use.

    我喜欢这样的术语:执行和撤消操作,就像您使用的每个文字处理应用程序一样。
  • I like the syntax: short and sweet.

    我喜欢这样的语法:简短而甜美。

坏处 (The Bads)

  • This was a total "proof of concept" class and I'll admit my execution isn't very refined.

    这是一个完全的“概念验证”类,我承认我的执行不是很完善。
  • The method names may need to be changed on account of "do" being a reserved word.

    由于“ do”是保留字,可能需要更改方法名称。
  • This structure only allows for one "undo", so to speak. I wonder if it would enhance this solution to have an internal variable which would keep track of undos.

    可以这么说,这种结构只允许一个“撤消”。 我想知道它是否可以增强此解决方案的内部变量来跟踪撤消。

What are your thoughts? Dead end? Good start? I'm a ball of emotions with this. One second I think it's great, the next second I don't know how useful it would be.

你觉得呢?你有没有什么想法? 死路? 好的开始? 我对此很感动。 我认为一秒钟很棒,下一秒钟我不知道它会有多大用处。

翻译自:

mootools

转载地址:http://akpwd.baihongyu.com/

你可能感兴趣的文章
N皇后问题
查看>>
七大基本排序算法之冒泡排序
查看>>
java第七次作业
查看>>
破解思科路由器密码
查看>>
JVM介绍
查看>>
字符串的常用方法
查看>>
Docker: 快速搭建LNMP网站平台
查看>>
web开发之Servlet 二
查看>>
JAVA提高十:ArrayList 深入分析
查看>>
人工智能入门(六):SVM
查看>>
6.用CXF编写基于Spring的WebService
查看>>
Commands in Powershell
查看>>
bzoj2748 [HAOI2012]音量调节 背包
查看>>
【bzoj2301】[HAOI2011]Problem b 莫比乌斯反演
查看>>
STL
查看>>
浅谈SQL Server中的事务日志(三)----在简单恢复模式下日志的角色
查看>>
ArrayList 源码分析
查看>>
文本超出内容区域后用三个省略号代替
查看>>
不高兴的津津
查看>>
(转) exp1-3://一次有趣的XSS漏洞挖掘分析(3)最终篇
查看>>