From 2212c51b5a0121bddd443fb20837c46038ea672d Mon Sep 17 00:00:00 2001 From: massimobrero Date: Tue, 12 Nov 2013 16:00:23 +0100 Subject: [PATCH 1/4] Created new extension : 'extended-toolbar.js' --- src/extended-toolbar.js | 226 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 src/extended-toolbar.js diff --git a/src/extended-toolbar.js b/src/extended-toolbar.js new file mode 100644 index 0000000..fa067fa --- /dev/null +++ b/src/extended-toolbar.js @@ -0,0 +1,226 @@ +/* + IIPMooViewer 2.0 - Extended Toolbar Extension + IIPImage Javascript Viewer + + Copyright (c) 2013 Massimo Brero + + --------------------------------------------------------------------------- + This file is part of IIPMooViewer 2.0 (hereinafter referred to as 'this program'). + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + --------------------------------------------------------------------------- + +*/ + +/** Extends IIPMooViewer with a modular toolbar to provide user-friendly access to most options. +* @param {String} toolbarId : id of the HTML 'div' of the toolbar. +* @param {String} position : choice is 'inside' or 'outside'. Default is 'inside'. +* Specifies if the toolbar appears +* inside the viewer (= on top of it), or +* outside the viewer (=next/above of it, depending on the orientation). +* @param {String} orientation : choice is 'vertical' or 'horizontal'. +* @param {String[]} buttons : Array of strings +*/ +IIPMooViewer.implement({ + createExtendedToolbar: function(toolbarId, position, orientation, buttons){ + var _thisIIP = this; // local reference to 'this' + // Get a reference to the original toolbar - an HTML div must exists + var toolbar = document.getElementById(toolbarId); + + if ( (typeof(toolbar)==='undefined') || (toolbar == null) ) { + var msg = "IIPMooViewer Extended Toolbar creation error :\nNo element ID given to IIPMooViewer createExtendedToolbar\(\) or\nInvalide id.\nThe toolbar will not be available."; + alert( msg ); + return; + } + + position = position || 'inside'; + if (typeof(orientation)==='undefined') orientation = 'horizontal'; + if (typeof(buttons)==='undefined') buttons = ['rotateanticlockwise', 'rotateclockwise', 'toggleNavigationWindow', 'getRegionalURL', 'zoomIn', 'zoomOut', 'reset', 'toggleFullscreen']; + + // To suppress duplicate entries, keeping only the first occurence. + buttons = buttons.filter(function(elem, pos) { + return buttons.indexOf(elem) == pos; + }) + + /* Create the extended toolbar buttons for every valid array entry. + * Non existing options (malformed array entries) or meaningless buttons + * (i.e. toggleAnnotations if the annotation extension is not loaded) + * are ignored and therefor not created. + */ + for (var i=0;i