| 1 | // PLUGIN_INFO//{{{ |
|---|
| 2 | var PLUGIN_INFO = |
|---|
| 3 | <VimperatorPlugin> |
|---|
| 4 | <name>{NAME}</name> |
|---|
| 5 | <description>simple takahashi-method presentation tool</description> |
|---|
| 6 | <author mail="konbu.komuro@gmail.com" homepage="http://d.hatena.ne.jp/hogelog/">hogelog</author> |
|---|
| 7 | <version>0.1.1</version> |
|---|
| 8 | <minVersion>2.3pre</minVersion> |
|---|
| 9 | <maxVersion>2.3pre</maxVersion> |
|---|
| 10 | <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/takahashiPresentation.js</updateURL> |
|---|
| 11 | <date>2008/12/23 09:20:07</date> |
|---|
| 12 | <detail><![CDATA[ |
|---|
| 13 | |
|---|
| 14 | == COMMANDS == |
|---|
| 15 | presentation: |
|---|
| 16 | start presentation |
|---|
| 17 | == HOWTO == |
|---|
| 18 | open HTML file includes <pre id="page">...</pre> and <div id="text">...</div>. |
|---|
| 19 | start :presentation. |
|---|
| 20 | ]]></detail> |
|---|
| 21 | </VimperatorPlugin>; |
|---|
| 22 | //}}} |
|---|
| 23 | (function() { |
|---|
| 24 | let keys = [ |
|---|
| 25 | ['<Right>', 'next page', function() nextPage()], |
|---|
| 26 | ['<Left>', 'prev page', function() prevPage()], |
|---|
| 27 | ['^', 'first page', function() loadPage(0)], |
|---|
| 28 | ['$', 'last page', function() loadPage(pages.length-1)], |
|---|
| 29 | ['.', 'last page', function(count) loadPage(count?count-1:0), {count: true}], |
|---|
| 30 | ['q', 'stop presentation', function() stop()], |
|---|
| 31 | ]; |
|---|
| 32 | let win; |
|---|
| 33 | let doc; |
|---|
| 34 | let pages = []; |
|---|
| 35 | let curpage = 0; |
|---|
| 36 | let pre; |
|---|
| 37 | let header; |
|---|
| 38 | let fontSize = 18.0; |
|---|
| 39 | |
|---|
| 40 | function addKeys() { |
|---|
| 41 | keys.forEach(function([key, desc, action, extra]) |
|---|
| 42 | mappings.addUserMap([modes.NORMAL], [key], desc, action, extra)); |
|---|
| 43 | } |
|---|
| 44 | function fitPage() { |
|---|
| 45 | if(pre.innerHTML=='') return; |
|---|
| 46 | pre.style.display = 'inline'; |
|---|
| 47 | let parentWidth = pre.parentNode.offsetWidth; |
|---|
| 48 | let parentHeight = pre.parentNode.offsetHeight; |
|---|
| 49 | let width = pre.offsetWidth; |
|---|
| 50 | let height = pre.offsetHeight; |
|---|
| 51 | let preRatio = width/height; |
|---|
| 52 | let winRatio = parentWidth/parentHeight; |
|---|
| 53 | if(preRatio>winRatio) { |
|---|
| 54 | fontSize *= 0.9*(parentWidth-10)/width; |
|---|
| 55 | } else { |
|---|
| 56 | fontSize *= 0.9*(parentHeight-10)/height; |
|---|
| 57 | } |
|---|
| 58 | pre.style.fontSize = fontSize+'px'; |
|---|
| 59 | pre.style.display = 'block'; |
|---|
| 60 | } |
|---|
| 61 | function loadPage(page) { |
|---|
| 62 | let text = pages[page]; |
|---|
| 63 | pre.innerHTML = text; |
|---|
| 64 | if(header) { |
|---|
| 65 | header.innerHTML = (page+1)+'/'+pages.length; |
|---|
| 66 | } |
|---|
| 67 | fitPage(); |
|---|
| 68 | } |
|---|
| 69 | function nextPage() { |
|---|
| 70 | curpage = curpage>=pages.length-1 ? 0 : curpage+1; |
|---|
| 71 | loadPage(curpage); |
|---|
| 72 | } |
|---|
| 73 | function prevPage() { |
|---|
| 74 | curpage = curpage<=0 ? pages.length-1 : curpage-1; |
|---|
| 75 | loadPage(curpage); |
|---|
| 76 | } |
|---|
| 77 | function parsePages(text) { |
|---|
| 78 | return text.split('----') |
|---|
| 79 | .map(function(txt) txt.replace(/^(?:\r\n|[\r\n])|(?:\r\n|[\r\n])$/g, '')); |
|---|
| 80 | } |
|---|
| 81 | function save_setting(setting) { |
|---|
| 82 | setting.fullscreen = options.fullscreen; |
|---|
| 83 | setting.guioptions = options.guioptions; |
|---|
| 84 | // TODO: save key mapping |
|---|
| 85 | //setting.mappings = keys.map(function([key,]) { |
|---|
| 86 | // let mapping = mappings.get(modes.NORMAL, key); |
|---|
| 87 | // return [mapping.modes, key, mapping.description, mapping.action, mapping.extra]; |
|---|
| 88 | //}); |
|---|
| 89 | } |
|---|
| 90 | function load_setting(setting) { |
|---|
| 91 | options.fullscreen = setting.fullscreen; |
|---|
| 92 | options.guioptions = setting.guioptions; |
|---|
| 93 | // TODO: load key mapping |
|---|
| 94 | //setting.mappings.forEach(function([modes, key, desc, action, extra]) { |
|---|
| 95 | // mappings.addUserMap(modes, [key], desc, action, extra); |
|---|
| 96 | //}); |
|---|
| 97 | } |
|---|
| 98 | let original_setting = {}; |
|---|
| 99 | function start() { |
|---|
| 100 | save_setting(original_setting); |
|---|
| 101 | |
|---|
| 102 | options.fullscreen = true; |
|---|
| 103 | options.guioptions = ''; |
|---|
| 104 | win = window.content; |
|---|
| 105 | doc = win.document; |
|---|
| 106 | let text = util.evaluateXPath('//div[@id="text"]').snapshotItem(0); |
|---|
| 107 | pages = parsePages(text.innerHTML); |
|---|
| 108 | addKeys(); |
|---|
| 109 | |
|---|
| 110 | header = util.evaluateXPath('//*[@id="header"]').snapshotItem(0); |
|---|
| 111 | |
|---|
| 112 | pre = util.evaluateXPath('//pre[@id="page"]').snapshotItem(0); |
|---|
| 113 | pre.style.fontSize = fontSize+'px'; |
|---|
| 114 | pre.style.margin = '0px'; |
|---|
| 115 | |
|---|
| 116 | loadPage(0); |
|---|
| 117 | } |
|---|
| 118 | function stop() { |
|---|
| 119 | load_setting(original_setting); |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | commands.add(['presentation'], 'start presentation', //{{{ |
|---|
| 123 | function(args) { |
|---|
| 124 | start(); |
|---|
| 125 | }, |
|---|
| 126 | { |
|---|
| 127 | argCount: '0', |
|---|
| 128 | }); //}}} |
|---|
| 129 | |
|---|
| 130 | })(); |
|---|
| 131 | // vim: fdm=marker sw=4 ts=4 et: |
|---|