Sha256: 307b1a1002dec1d923e5ea6afa21b1f13ef519e75d21a28e73d4c45c4539cfff

Contents?: true

Size: 1.29 KB

Versions: 11

Compression:

Stored size: 1.29 KB

Contents

/*jshint browser: true, nomen: false, eqnull: true, es5:true, trailing:true */

(function () {
  "use strict";
  var work_form = $("form[data-behavior='work-form']"),
      Autocomplete = require('hyrax/autocomplete'),
      LinkedData = require('hyrax/autocomplete/linked_data');

  function patch_autocomplete() {
    var method = Autocomplete.prototype.setup;
    if (!window._autocomplete_patched) {
      Autocomplete.prototype.setup = function (element, fieldName, url) {
        // defer to original method for relevant BasicMetadata fields:
        var defer = ['based_near', 'language', 'work'],
            autourl = element.attr('data-autocomplete-url'),
            declared = (element.attr('data-autocomplete') === fieldName),
            ld = (declared && autourl && autourl.indexOf('authorities') !== -1),
            additionalField = element.context === undefined;
        if (additionalField || (ld && defer.indexOf(fieldName) == -1)) {
          new LinkedData(element, url);
          console.log('Using patched autocomplete for field', fieldName);
        } else {
          method(element, fieldName, url);
        }
      };
      window._autocomplete_patched = true;
    }
  }

  if (work_form.length && work_form.attr('id').indexOf('newspaper_') != -1) {
    patch_autocomplete();
  }
}());

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
iiif_print-3.0.3 app/assets/javascripts/iiif_print/autocomplete_fix.js
iiif_print-3.0.2 app/assets/javascripts/iiif_print/autocomplete_fix.js
iiif_print-3.0.1 app/assets/javascripts/iiif_print/autocomplete_fix.js
iiif_print-3.0.0 app/assets/javascripts/iiif_print/autocomplete_fix.js
iiif_print-2.0.1 app/assets/javascripts/iiif_print/autocomplete_fix.js
iiif_print-2.0.0 app/assets/javascripts/iiif_print/autocomplete_fix.js
iiif_print-1.1.0 app/assets/javascripts/iiif_print/autocomplete_fix.js
iiif_print-1.0.0 app/assets/javascripts/iiif_print/autocomplete_fix.js
newspaper_works-1.0.1 app/assets/javascripts/newspaper_works/autocomplete_fix.js
newspaper_works-1.0.0 app/assets/javascripts/newspaper_works/autocomplete_fix.js
newspaper_works-0.1.0 app/assets/javascripts/newspaper_works/autocomplete_fix.js