Skip to content
Snippets Groups Projects
Select Git revision
  • 287e7ef2216809e73c2f7320d91345f3a2a0127f
  • mui5-annotation-on-video-stable default
  • get_setter_canvasSizeInformations
  • fix-error-div-into-p
  • annotation-on-video-v2
  • detached
  • annotation-on-video-r17
  • mui5
  • mui5-react-18
  • jacob-test
  • annotation-on-video protected
  • master
  • test-antoinev1
  • 20-fetch-thumbnail-on-annotation
  • add-research-field
  • Save
  • add-plugin
  • 14-wip-no-seek-to
  • 14-bug-on-video-time-control
  • 9_wip_videotests
  • _upgrade_material_ui
  • latest-tetras-16
  • v3.3.0
  • v3.2.0
  • v3.1.1
  • v3.1.0
  • v3.0.0
  • v3.0.0-rc.7
  • v3.0.0-rc.6
  • v3.0.0-rc.5
  • v3.0.0-rc.4
  • v3.0.0-rc.3
  • v3.0.0-rc.2
  • v3.0.0-rc.1
  • v3.0.0-beta.10
  • v3.0.0-beta.9
  • v3.0.0-beta.8
  • v3.0.0-beta.7
  • v3.0.0-beta.6
  • v3.0.0-beta.5
  • v3.0.0-beta.3
41 results

manifestsPanel.js

Blame
  • manifestsPanel.js 6.89 KiB
    (function($) {
    
        $.ManifestsPanel = function(options) {
    
            jQuery.extend(true, this, {
                element:                    null,
                listItems:                  null,
                appendTo:                   null,
                manifestListItems:          [],
                manifestListElement:        null,
                manifestLoadStatusIndicator: null,
                resultsWidth:               0,
                state:                      null,
                eventEmitter:               null
            }, options);
    
            var _this = this;
            _this.init();
            
        };
    
        $.ManifestsPanel.prototype = {
    
            init: function() {
                this.element = jQuery(this.template({
                    showURLBox : this.state.getStateProperty('showAddFromURLBox')
                })).appendTo(this.appendTo);
                this.manifestListElement = this.element.find('ul');
                
                //this code gives us the max width of the results area, used to determine how many preview images to show
                //cloning the element and adjusting the display and visibility means it won't break the normal flow
                var clone = this.element.clone().css("visibility","hidden").css("display", "block").appendTo(this.appendTo);
                this.resultsWidth = clone.find('.select-results').outerWidth();
                this.controlsHeight = clone.find('.manifest-panel-controls').outerHeight();
                this.paddingListElement = this.controlsHeight;
                this.manifestListElement.css("padding-bottom", this.paddingListElement);
                clone.remove();
                
                // this.manifestLoadStatusIndicator = new $.ManifestLoadStatusIndicator({
                //   manifests: this.parent.manifests,
                //   appendTo: this.element.find('.select-results')
                // });
                this.bindEvents();
                this.listenForActions();
            },
    
            listenForActions: function() {
              var _this = this;
    
              // handle subscribed events
              _this.eventEmitter.subscribe('manifestsPanelVisible.set', function(_, stateValue) {
                _this.onPanelVisible(_, stateValue);
              });
    
              _this.eventEmitter.subscribe('manifestReceived', function(event, newManifest) {
                _this.onManifestReceived(event, newManifest);
              });
              
              _this.eventEmitter.subscribe('collectionReceived', function(event, newCollection) {
                _this.onCollectionReceived(event, newCollection);
              });
            },
    
            bindEvents: function() {
                var _this = this;
    
                // handle interface events
                this.element.find('form#url-load-form').on('submit', function(event) {
                  event.preventDefault();
                  _this.addManifestUrl(jQuery(this).find('input').val());
                });
    
                this.element.find('.remove-object-option').on('click', function(event) {
                  _this.togglePanel(event);
                });
    
                // Filter manifests based on user input
                this.element.find('#manifest-search').on('keyup input', function(event) {
                  _this.filterManifests(this.value);
                });
    
                this.element.find('#manifest-search-form').on('submit', function(event) {
                  event.preventDefault();
                });
    
                jQuery(window).resize($.throttle(function() {
                  _this.resizePanel();
                }, 50, true));
            },
            
            hide: function() {
                var _this = this;
                jQuery(this.element).hide({effect: "fade", duration: 160, easing: "easeOutCubic"});
            },
    
            show: function() {
                var _this = this;
                jQuery(this.element).show({effect: "fade", duration: 160, easing: "easeInCubic"});
            },
            
            addManifestUrl: function(url) {
              var _this = this;
              _this.eventEmitter.publish('ADD_MANIFEST_FROM_URL', [url, "(Added from URL)"]);
            },
            
            togglePanel: function(event) {
              var _this = this;
              _this.eventEmitter.publish('TOGGLE_LOAD_WINDOW');
            },
            
            filterManifests: function(value) {
              var _this = this;
              if (value.length > 0) {
                 _this.element.find('.items-listing li').show().filter(function() {
                    return jQuery(this).text().toLowerCase().indexOf(value.toLowerCase()) === -1;
                 }).hide();
              } else {
                 _this.element.find('.items-listing li').show();
              }
            },
    
            resizePanel: function() {
              var _this = this;
              var clone = _this.element.clone().css("visibility","hidden").css("display", "block").appendTo(_this.appendTo);
              _this.resultsWidth = clone.find('.select-results').outerWidth();
              clone.remove();
              _this.eventEmitter.publish("manifestPanelWidthChanged", _this.resultsWidth);
            },
            
            onPanelVisible: function(_, stateValue) {
              var _this = this;
              if (stateValue) { _this.show(); return; }
               _this.hide();
            },
    
            onManifestReceived: function(event, newManifest) {
              var _this = this;
              _this.manifestListItems.push(new $.ManifestListItem({ 
                manifest: newManifest, 
                resultsWidth: _this.resultsWidth, 
                state: _this.state,
                eventEmitter: _this.eventEmitter,
                appendTo: _this.manifestListElement }));
              _this.element.find('#manifest-search').keyup();
            },
            
            onCollectionReceived: function(event, newCollection) {
              var _this = this;
              jQuery.each(newCollection.getManifestUris(), function(_, v) {
                _this.eventEmitter.publish('ADD_MANIFEST_FROM_URL', [v, newCollection.location]);
              });
            },
    
            template: $.Handlebars.compile([
              '<div id="manifest-select-menu">',
              '<div class="container">',
                '<div class="manifest-panel-controls">',
                  '<a class="remove-object-option"><i class="fa fa-times fa-lg fa-fw"></i>{{t "close"}}</a>',
                  '<div id="load-controls">',
                    '{{#if showURLBox}}',
                      '<form action="" id="url-load-form">',
                        '<label for="url-loader">{{t "addNewObject"}}:</label>',
                        '<input type="text" id="url-loader" name="url-load" placeholder="http://...">',
                        '<input type="submit" value="{{t "load"}}">',
                      '</form>',
                    '{{/if}}',
                    '<form action="" id="manifest-search-form">',
                      '<label for="manifest-search">{{t "filterObjects"}}:</label>',
                      '<input id="manifest-search" type="text" name="manifest-filter">',
                    '</form>',
                  '</div>',
                '</div>',
                  '<div class="select-results">',
                    '<ul class="items-listing">',
                    '</ul>',
                  '</div>',
              '</div>',
              '</div>'
            ].join(''))
        };
    
    }(Mirador));