Project

General

Profile

Download (3.93 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * jq-universalviewer
3
 * Version: 1.0
4
 * URL: ${URL}
5
 * Description: jQuery wrapper for Universalviewer
6
 * Requires: universalviewer@^3.0.36 (https://github.com/UniversalViewer/universalviewer)
7
 * Author: Andreas Kohlbecker
8
 * Copyright: Copyright 2020
9
 * License: Mozilla Public License Version 1.1
10
 */
11

    
12
// Plugin closure wrapper
13
// Uses dollar, but calls jQuery to prevent conflicts with other libraries
14
// Semicolon to prevent breakage with concatenation
15
// Pass in window as local variable for efficiency (could do same for document)
16
// Pass in undefined to prevent mutation in ES3
17
;(function($, document, window, undefined) {
18
    "use strict";
19

    
20
    // Name the plugin so it's only in one place
21
    var pluginName = 'jqUniversalviewer';
22

    
23
    // Default options for the plugin
24
    var defaults = {
25
        root: undefined,
26
        configUri: undefined,
27
        manifestUri: 'http://wellcomelibrary.org/iiif/b18035723/manifest'
28
    };
29

    
30
    var urlDataProvider;
31

    
32
    // Plugin constructor
33
    // This is the boilerplate to set up the plugin to keep our actual logic in one place
34
    function Plugin(element, options) {
35
        this.element = element;
36

    
37
        // Merge the options given by the user with the defaults
38
        this.options = $.extend({}, defaults, options);
39

    
40
        // Attach data to the element
41
        this.$el      = $(element);
42
        this.$el.data(name, this);
43

    
44
        this._defaults = defaults;
45

    
46
        var meta      = this.$el.data(name + '-opts');
47
        this.opts     = $.extend(this._defaults, options, meta);
48

    
49
        this.uv = null;
50

    
51
        // Initialization code to get the ball rolling
52
        this.init();
53
    }
54

    
55
    // firebug console stub (avoids errors if firebug is not active)
56
    if (typeof console === "undefined") {
57
         console = {
58
             log: function () {
59
             }
60
         };
61
     }
62

    
63
    Plugin.prototype = {
64
        // Public functions accessible to users
65
        // Prototype methods are shared across all elements
66
        // You have access to this.options and this.element
67
        // If your plugin is complex, you can split functionality into more
68
        // methods like this one
69
        init: function() {
70
            var plugin = this;
71
               urlDataProvider = new UV.URLDataProvider();
72
               setupUV(plugin, this.element);
73
        }
74
    };
75

    
76
    $.fn[pluginName] = function(options) {
77
        // Iterate through each DOM element and return it
78
        return this.each(function() {
79
            // prevent multiple instantiations
80
            if (!$.data(this, 'plugin_' + pluginName)) {
81
                $.data(this, 'plugin_' + pluginName, new Plugin(this, options));
82
            }
83
        });
84
    };
85

    
86
    // Private function that is only called by the plugin
87
    var setupUV = function(plugin, element) {
88

    
89
        var collectionIndex = urlDataProvider.get('c');
90

    
91
        console.log("setupUV() with " + plugin.options.manifestUri);
92

    
93
        var uvdata = {
94
            root: plugin.options.root,
95
            configUri: plugin.options.configUri,
96
            iiifResourceUri: plugin.options.manifestUri,
97
            collectionIndex: (collectionIndex !== undefined) ? Number(collectionIndex) : undefined,
98
            manifestIndex: Number(urlDataProvider.get('m', 0)),
99
            sequenceIndex: Number(urlDataProvider.get('s', 0)),
100
            canvasIndex: Number(urlDataProvider.get('cv', 0)),
101
            rotation: Number(urlDataProvider.get('r', 0)),
102
            rangeId: urlDataProvider.get('rid', ''),
103
            xywh: urlDataProvider.get('xywh', ''),
104

    
105
        };
106

    
107
        plugin.uv = createUV(element, uvdata, urlDataProvider);
108
        console.log('createUV done:' + plugin.uv);
109

    
110
        plugin.uv.on('created', function() {
111
            // console.log('created');
112
            Utils.Urls.setHashParameter('manifest', plugin.options.manifestUri);
113
        });
114

    
115

    
116
        // plugin.uv.on('openseadragonExtension.open', function() {
117
        //     console.log('osd opened');
118
        // });
119
    };
120

    
121

    
122
})(jQuery, document, window);
(2-2/5)