From 6f96bb02f06cb49127cf0cc1f15d1197bdd6582a Mon Sep 17 00:00:00 2001 From: teramako Date: Sun, 30 Nov 2008 14:29:29 +0000 Subject: new release git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@25469 d0d07461-0603-4401-acd4-de1884942a52 --- toggler.js | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 toggler.js (limited to 'toggler.js') diff --git a/toggler.js b/toggler.js new file mode 100644 index 0000000..d874c85 --- /dev/null +++ b/toggler.js @@ -0,0 +1,142 @@ +/* + * ==VimperatorPlugin== + * @name toggler + * @version 0.1 + * @author teramako + * ==/VimperatorPlugin== + * + * 何かしらの設定をクルクル変更したい人へ + * + * まず、最初に以下の例ように.vimperatorrcに定義する +js < :toggle go + * などとやっておくとボタン一つでクルクル替わる + */ +liberator.plugins.toggler = (function(){ + +var settings = {}; +function Toggler(name, cmds){ + if (!cmds || cmds.length < 2) throw new Error("arguments are not enough"); + this.name = name; + this.cmds = cmds; + this.index = 0; +} +Toggler.prototype = { + next: function(notUpdate){ + let index = this.index + 1; + if (index >= this.cmds.length) index = 0; + if (!notUpdate) this.index = index; + return this.cmds[index]; + }, + previous: function(notUpdate){ + let index = this.index - 1; + if (index < 0) index = this.cmds.length -1; + if (!notUpdate) this.index = index; + return this.cmds[this.index]; + }, + list: function(){ + var data = []; + for (var i = 0; i