geoblacklight 2.1.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +6 -0
- data/.gitignore +3 -1
- data/.rubocop.yml +3 -1
- data/.rubocop_todo.yml +7 -15
- data/README.md +5 -6
- data/app/assets/images/blacklight/arrow-circle-down.svg +4 -0
- data/app/assets/images/blacklight/baruch-cuny.svg +6 -0
- data/app/assets/images/blacklight/berkeley.svg +7 -0
- data/app/assets/images/blacklight/book.svg +6 -0
- data/app/assets/images/blacklight/bookmark.svg +6 -0
- data/app/assets/images/blacklight/cd-rom.svg +6 -0
- data/app/assets/images/blacklight/chicago.svg +7 -0
- data/app/assets/images/blacklight/columbia.svg +6 -0
- data/app/assets/images/blacklight/cornell.svg +8 -0
- data/app/assets/images/blacklight/dvd-rom.svg +6 -0
- data/app/assets/images/blacklight/email.svg +6 -0
- data/app/assets/images/blacklight/esri-globe.svg +34 -37
- data/app/assets/images/blacklight/geoblacklight-icons.json +2079 -0
- data/app/assets/images/blacklight/globe.svg +4 -0
- data/app/assets/images/blacklight/harvard.svg +6 -0
- data/app/assets/images/blacklight/home.svg +4 -0
- data/app/assets/images/blacklight/illinois.svg +7 -0
- data/app/assets/images/blacklight/image.svg +6 -0
- data/app/assets/images/blacklight/indiana.svg +6 -0
- data/app/assets/images/blacklight/iowa.svg +6 -0
- data/app/assets/images/blacklight/leaf.svg +6 -0
- data/app/assets/images/blacklight/lewis-clark.svg +8 -0
- data/app/assets/images/blacklight/line.svg +7 -0
- data/app/assets/images/blacklight/logo.svg +1 -0
- data/app/assets/images/blacklight/map-marker.svg +6 -0
- data/app/assets/images/blacklight/map.svg +6 -0
- data/app/assets/images/blacklight/maryland.svg +6 -0
- data/app/assets/images/blacklight/massgis.svg +6 -0
- data/app/assets/images/blacklight/metadata.svg +6 -0
- data/app/assets/images/blacklight/michigan-state.svg +7 -0
- data/app/assets/images/blacklight/michigan.svg +6 -0
- data/app/assets/images/blacklight/minnesota.svg +6 -0
- data/app/assets/images/blacklight/mit.svg +6 -0
- data/app/assets/images/blacklight/mixed.svg +8 -0
- data/app/assets/images/blacklight/multilinestring.svg +9 -0
- data/app/assets/images/blacklight/multipoint.svg +6 -0
- data/app/assets/images/blacklight/multipolygon.svg +9 -0
- data/app/assets/images/blacklight/nyu.svg +9 -0
- data/app/assets/images/blacklight/ohio-state.svg +8 -0
- data/app/assets/images/blacklight/pagelines-brands.svg +6 -0
- data/app/assets/images/blacklight/paper-map.svg +6 -0
- data/app/assets/images/blacklight/penn-state.svg +7 -0
- data/app/assets/images/blacklight/point.svg +6 -0
- data/app/assets/images/blacklight/polygon.svg +7 -0
- data/app/assets/images/blacklight/polyline.svg +9 -0
- data/app/assets/images/blacklight/princeton.svg +6 -0
- data/app/assets/images/blacklight/public.svg +6 -0
- data/app/assets/images/blacklight/purdue.svg +7 -0
- data/app/assets/images/blacklight/raster.svg +6 -0
- data/app/assets/images/blacklight/restricted.svg +6 -0
- data/app/assets/images/blacklight/sms.svg +6 -0
- data/app/assets/images/blacklight/stanford.svg +6 -0
- data/app/assets/images/blacklight/table.svg +6 -0
- data/app/assets/images/blacklight/tags.svg +4 -0
- data/app/assets/images/blacklight/texas.svg +6 -0
- data/app/assets/images/blacklight/tufts.svg +6 -0
- data/app/assets/images/blacklight/ucla.svg +6 -0
- data/app/assets/images/blacklight/uva.svg +6 -0
- data/app/assets/images/blacklight/web_services.svg +6 -0
- data/app/assets/images/blacklight/wisconsin.svg +6 -0
- data/app/assets/javascripts/geoblacklight/modules/help_text.js +7 -0
- data/app/assets/javascripts/geoblacklight/modules/item.js +1 -3
- data/app/assets/javascripts/geoblacklight/viewers/oembed.js +13 -0
- data/app/assets/stylesheets/geoblacklight/_blacklight_overrides.scss +9 -1
- data/app/assets/stylesheets/geoblacklight/modules/icon-customization.scss +49 -59
- data/app/assets/stylesheets/geoblacklight/modules/item.scss +4 -0
- data/app/assets/stylesheets/geoblacklight/modules/results.scss +22 -0
- data/app/assets/stylesheets/geoblacklight/modules/toolbar.scss +4 -0
- data/app/helpers/geoblacklight_helper.rb +91 -5
- data/app/models/concerns/geoblacklight/solr_document.rb +4 -0
- data/app/models/concerns/geoblacklight/spatial_search_behavior.rb +5 -0
- data/app/views/catalog/_data_dictionary.html.erb +3 -2
- data/app/views/catalog/_document_action.html.erb +1 -1
- data/app/views/catalog/_exports.html.erb +2 -10
- data/app/views/catalog/_home_text.html.erb +4 -4
- data/app/views/catalog/_show_default_viewer_container.html.erb +5 -0
- data/app/views/catalog/_show_header_default.html.erb +2 -4
- data/app/views/relation/_ancestors.html.erb +2 -1
- data/app/views/relation/_descendants.html.erb +2 -1
- data/app/views/shared/_header_navbar.html.erb +2 -0
- data/config/locales/geoblacklight.en.yml +88 -0
- data/geoblacklight.gemspec +1 -0
- data/lib/generators/geoblacklight/templates/geoblacklight.js +1 -1
- data/lib/generators/geoblacklight/templates/settings.yml +19 -0
- data/lib/geoblacklight/constants.rb +3 -2
- data/lib/geoblacklight/item_viewer.rb +5 -1
- data/lib/geoblacklight/metadata/base.rb +15 -10
- data/lib/geoblacklight/reference.rb +2 -1
- data/lib/geoblacklight/version.rb +1 -1
- data/package.json +4 -0
- data/schema/references.md +2 -1
- data/spec/features/exports_spec.rb +9 -0
- data/spec/features/help_text_spec.rb +8 -0
- data/spec/features/metadata_panel_spec.rb +51 -8
- data/spec/features/oembed_spec.rb +9 -0
- data/spec/features/search_results_map_spec.rb +1 -1
- data/spec/features/split_view.html.erb_spec.rb +1 -1
- data/spec/features/suppressed_records_spec.rb +14 -0
- data/spec/fixtures/fgdc/harvard-g7064-s2-1834-k3.xml +1 -0
- data/spec/fixtures/iso19139/stanford-cg357zz0321.xml +581 -0
- data/spec/fixtures/mods/fb897vt9938.mods +111 -0
- data/spec/fixtures/mods/stanford-cg357zz0321.mods +113 -0
- data/spec/fixtures/solr_documents/iiif-eastern-hemisphere.json +1 -1
- data/spec/fixtures/solr_documents/oembed.json +24 -0
- data/spec/helpers/geoblacklight_helper_spec.rb +30 -7
- data/spec/javascripts/geoblacklight_spec.js +4 -0
- data/spec/javascripts/metadata_download_button_spec.js +1 -1
- data/spec/lib/geoblacklight/metadata/base_spec.rb +18 -4
- data/spec/lib/geoblacklight/reference_spec.rb +30 -0
- data/spec/models/concerns/geoblacklight/solr_document_spec.rb +20 -0
- data/spec/spec_helper.rb +8 -5
- data/vendor/assets/javascripts/readmore.js +618 -0
- data/vendor/assets/javascripts/readmore.js.map +1 -0
- metadata +96 -3
- data/vendor/assets/javascripts/readmore.min.js +0 -11
data/spec/spec_helper.rb
CHANGED
@@ -28,16 +28,19 @@ require 'capybara/rspec'
|
|
28
28
|
require 'selenium-webdriver'
|
29
29
|
|
30
30
|
Capybara.register_driver(:headless_chrome) do |app|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
Capybara::Selenium::Driver.load_selenium
|
32
|
+
browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts|
|
33
|
+
opts.args << '--headless'
|
34
|
+
opts.args << '--disable-gpu'
|
35
|
+
opts.args << '--window-size=1280,1024'
|
36
|
+
end
|
34
37
|
http_client = Selenium::WebDriver::Remote::Http::Default.new
|
35
38
|
http_client.read_timeout = 120
|
36
39
|
http_client.open_timeout = 120
|
37
40
|
Capybara::Selenium::Driver.new(app,
|
38
41
|
browser: :chrome,
|
39
|
-
|
40
|
-
|
42
|
+
http_client: http_client,
|
43
|
+
options: browser_options)
|
41
44
|
end
|
42
45
|
|
43
46
|
Capybara.javascript_driver = :headless_chrome
|
@@ -0,0 +1,618 @@
|
|
1
|
+
/*!
|
2
|
+
* @preserve
|
3
|
+
*
|
4
|
+
* Readmore.js plugin
|
5
|
+
* Author: @jed_foster
|
6
|
+
* Project home: jedfoster.com/Readmore.js
|
7
|
+
* Version: 3.0.0-beta-1
|
8
|
+
* Licensed under the MIT license
|
9
|
+
*
|
10
|
+
* Debounce function from davidwalsh.name/javascript-debounce-function
|
11
|
+
*/
|
12
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
13
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
14
|
+
module.exports = factory();
|
15
|
+
else if(typeof define === 'function' && define.amd)
|
16
|
+
define("Readmore", [], factory);
|
17
|
+
else if(typeof exports === 'object')
|
18
|
+
exports["Readmore"] = factory();
|
19
|
+
else
|
20
|
+
root["Readmore"] = factory();
|
21
|
+
})(window, function() {
|
22
|
+
return /******/ (function(modules) { // webpackBootstrap
|
23
|
+
/******/ // The module cache
|
24
|
+
/******/ var installedModules = {};
|
25
|
+
/******/
|
26
|
+
/******/ // The require function
|
27
|
+
/******/ function __webpack_require__(moduleId) {
|
28
|
+
/******/
|
29
|
+
/******/ // Check if module is in cache
|
30
|
+
/******/ if(installedModules[moduleId]) {
|
31
|
+
/******/ return installedModules[moduleId].exports;
|
32
|
+
/******/ }
|
33
|
+
/******/ // Create a new module (and put it into the cache)
|
34
|
+
/******/ var module = installedModules[moduleId] = {
|
35
|
+
/******/ i: moduleId,
|
36
|
+
/******/ l: false,
|
37
|
+
/******/ exports: {}
|
38
|
+
/******/ };
|
39
|
+
/******/
|
40
|
+
/******/ // Execute the module function
|
41
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
42
|
+
/******/
|
43
|
+
/******/ // Flag the module as loaded
|
44
|
+
/******/ module.l = true;
|
45
|
+
/******/
|
46
|
+
/******/ // Return the exports of the module
|
47
|
+
/******/ return module.exports;
|
48
|
+
/******/ }
|
49
|
+
/******/
|
50
|
+
/******/
|
51
|
+
/******/ // expose the modules object (__webpack_modules__)
|
52
|
+
/******/ __webpack_require__.m = modules;
|
53
|
+
/******/
|
54
|
+
/******/ // expose the module cache
|
55
|
+
/******/ __webpack_require__.c = installedModules;
|
56
|
+
/******/
|
57
|
+
/******/ // define getter function for harmony exports
|
58
|
+
/******/ __webpack_require__.d = function(exports, name, getter) {
|
59
|
+
/******/ if(!__webpack_require__.o(exports, name)) {
|
60
|
+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
61
|
+
/******/ }
|
62
|
+
/******/ };
|
63
|
+
/******/
|
64
|
+
/******/ // define __esModule on exports
|
65
|
+
/******/ __webpack_require__.r = function(exports) {
|
66
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
67
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
68
|
+
/******/ }
|
69
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
70
|
+
/******/ };
|
71
|
+
/******/
|
72
|
+
/******/ // create a fake namespace object
|
73
|
+
/******/ // mode & 1: value is a module id, require it
|
74
|
+
/******/ // mode & 2: merge all properties of value into the ns
|
75
|
+
/******/ // mode & 4: return value when already ns object
|
76
|
+
/******/ // mode & 8|1: behave like require
|
77
|
+
/******/ __webpack_require__.t = function(value, mode) {
|
78
|
+
/******/ if(mode & 1) value = __webpack_require__(value);
|
79
|
+
/******/ if(mode & 8) return value;
|
80
|
+
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
81
|
+
/******/ var ns = Object.create(null);
|
82
|
+
/******/ __webpack_require__.r(ns);
|
83
|
+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
84
|
+
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
85
|
+
/******/ return ns;
|
86
|
+
/******/ };
|
87
|
+
/******/
|
88
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
89
|
+
/******/ __webpack_require__.n = function(module) {
|
90
|
+
/******/ var getter = module && module.__esModule ?
|
91
|
+
/******/ function getDefault() { return module['default']; } :
|
92
|
+
/******/ function getModuleExports() { return module; };
|
93
|
+
/******/ __webpack_require__.d(getter, 'a', getter);
|
94
|
+
/******/ return getter;
|
95
|
+
/******/ };
|
96
|
+
/******/
|
97
|
+
/******/ // Object.prototype.hasOwnProperty.call
|
98
|
+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
99
|
+
/******/
|
100
|
+
/******/ // __webpack_public_path__
|
101
|
+
/******/ __webpack_require__.p = "";
|
102
|
+
/******/
|
103
|
+
/******/
|
104
|
+
/******/ // Load entry module and return exports
|
105
|
+
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
106
|
+
/******/ })
|
107
|
+
/************************************************************************/
|
108
|
+
/******/ ({
|
109
|
+
|
110
|
+
/***/ "./node_modules/@babel/runtime/helpers/classCallCheck.js":
|
111
|
+
/*!***************************************************************!*\
|
112
|
+
!*** ./node_modules/@babel/runtime/helpers/classCallCheck.js ***!
|
113
|
+
\***************************************************************/
|
114
|
+
/*! no static exports found */
|
115
|
+
/***/ (function(module, exports) {
|
116
|
+
|
117
|
+
function _classCallCheck(instance, Constructor) {
|
118
|
+
if (!(instance instanceof Constructor)) {
|
119
|
+
throw new TypeError("Cannot call a class as a function");
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
module.exports = _classCallCheck;
|
124
|
+
|
125
|
+
/***/ }),
|
126
|
+
|
127
|
+
/***/ "./node_modules/@babel/runtime/helpers/createClass.js":
|
128
|
+
/*!************************************************************!*\
|
129
|
+
!*** ./node_modules/@babel/runtime/helpers/createClass.js ***!
|
130
|
+
\************************************************************/
|
131
|
+
/*! no static exports found */
|
132
|
+
/***/ (function(module, exports) {
|
133
|
+
|
134
|
+
function _defineProperties(target, props) {
|
135
|
+
for (var i = 0; i < props.length; i++) {
|
136
|
+
var descriptor = props[i];
|
137
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
138
|
+
descriptor.configurable = true;
|
139
|
+
if ("value" in descriptor) descriptor.writable = true;
|
140
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
145
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
146
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
147
|
+
return Constructor;
|
148
|
+
}
|
149
|
+
|
150
|
+
module.exports = _createClass;
|
151
|
+
|
152
|
+
/***/ }),
|
153
|
+
|
154
|
+
/***/ "./node_modules/@babel/runtime/helpers/typeof.js":
|
155
|
+
/*!*******************************************************!*\
|
156
|
+
!*** ./node_modules/@babel/runtime/helpers/typeof.js ***!
|
157
|
+
\*******************************************************/
|
158
|
+
/*! no static exports found */
|
159
|
+
/***/ (function(module, exports) {
|
160
|
+
|
161
|
+
function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); }
|
162
|
+
|
163
|
+
function _typeof(obj) {
|
164
|
+
if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
|
165
|
+
module.exports = _typeof = function _typeof(obj) {
|
166
|
+
return _typeof2(obj);
|
167
|
+
};
|
168
|
+
} else {
|
169
|
+
module.exports = _typeof = function _typeof(obj) {
|
170
|
+
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
|
171
|
+
};
|
172
|
+
}
|
173
|
+
|
174
|
+
return _typeof(obj);
|
175
|
+
}
|
176
|
+
|
177
|
+
module.exports = _typeof;
|
178
|
+
|
179
|
+
/***/ }),
|
180
|
+
|
181
|
+
/***/ "./src/readmore.js":
|
182
|
+
/*!*************************!*\
|
183
|
+
!*** ./src/readmore.js ***!
|
184
|
+
\*************************/
|
185
|
+
/*! exports provided: default */
|
186
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
187
|
+
|
188
|
+
"use strict";
|
189
|
+
__webpack_require__.r(__webpack_exports__);
|
190
|
+
/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "./node_modules/@babel/runtime/helpers/classCallCheck.js");
|
191
|
+
/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__);
|
192
|
+
/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "./node_modules/@babel/runtime/helpers/createClass.js");
|
193
|
+
/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__);
|
194
|
+
/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
|
195
|
+
/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_2__);
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
var uniqueIdCounter = 0;
|
200
|
+
var isCssEmbeddedFor = []; // from:https://github.com/jserz/js_piece/blob/master/DOM/ChildNode/remove()/remove().md
|
201
|
+
|
202
|
+
(function removePolyfill(arr) {
|
203
|
+
arr.forEach(function (item) {
|
204
|
+
if (Object.prototype.hasOwnProperty.call(item, 'remove')) {
|
205
|
+
return;
|
206
|
+
}
|
207
|
+
|
208
|
+
Object.defineProperty(item, 'remove', {
|
209
|
+
configurable: true,
|
210
|
+
enumerable: true,
|
211
|
+
writable: true,
|
212
|
+
value: function remove() {
|
213
|
+
if (this.parentNode !== null) {
|
214
|
+
this.parentNode.removeChild(this);
|
215
|
+
}
|
216
|
+
}
|
217
|
+
});
|
218
|
+
});
|
219
|
+
})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);
|
220
|
+
|
221
|
+
function forEach(arr, callback, scope) {
|
222
|
+
for (var i = 0; i < arr.length; i += 1) {
|
223
|
+
callback.call(scope, arr[i], i);
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
function extend() {
|
228
|
+
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
|
229
|
+
objects[_key] = arguments[_key];
|
230
|
+
}
|
231
|
+
|
232
|
+
var hasProp = {}.hasOwnProperty;
|
233
|
+
var child = objects[0];
|
234
|
+
var parent = objects[1];
|
235
|
+
|
236
|
+
if (objects.length > 2) {
|
237
|
+
var args = [];
|
238
|
+
Object.keys(objects).forEach(function (key) {
|
239
|
+
args.push(objects[key]);
|
240
|
+
});
|
241
|
+
|
242
|
+
while (args.length > 2) {
|
243
|
+
var c1 = args.shift();
|
244
|
+
var p1 = args.shift();
|
245
|
+
args.unshift(extend(c1, p1));
|
246
|
+
}
|
247
|
+
|
248
|
+
child = args.shift();
|
249
|
+
parent = args.shift();
|
250
|
+
}
|
251
|
+
|
252
|
+
if (parent) {
|
253
|
+
Object.keys(parent).forEach(function (key) {
|
254
|
+
if (hasProp.call(parent, key)) {
|
255
|
+
if (_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_2___default()(parent[key]) === 'object') {
|
256
|
+
child[key] = child[key] || {};
|
257
|
+
child[key] = extend(child[key], parent[key]);
|
258
|
+
} else {
|
259
|
+
child[key] = parent[key];
|
260
|
+
}
|
261
|
+
}
|
262
|
+
});
|
263
|
+
}
|
264
|
+
|
265
|
+
return child;
|
266
|
+
}
|
267
|
+
|
268
|
+
function debounce(func, wait, immediate) {
|
269
|
+
var timeout;
|
270
|
+
return function debouncedFunc() {
|
271
|
+
var _this = this;
|
272
|
+
|
273
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
274
|
+
args[_key2] = arguments[_key2];
|
275
|
+
}
|
276
|
+
|
277
|
+
var callNow = immediate && !timeout;
|
278
|
+
|
279
|
+
var later = function later() {
|
280
|
+
timeout = null;
|
281
|
+
if (!immediate) func.apply(_this, args);
|
282
|
+
};
|
283
|
+
|
284
|
+
clearTimeout(timeout);
|
285
|
+
timeout = setTimeout(later, wait);
|
286
|
+
if (callNow) func.apply(this, args);
|
287
|
+
};
|
288
|
+
}
|
289
|
+
|
290
|
+
function uniqueId() {
|
291
|
+
uniqueIdCounter += 1;
|
292
|
+
return "rmjs-".concat(uniqueIdCounter);
|
293
|
+
}
|
294
|
+
|
295
|
+
function setBoxHeights(element) {
|
296
|
+
element.style.height = 'auto';
|
297
|
+
var expandedHeight = parseInt(element.getBoundingClientRect().height, 10);
|
298
|
+
var cssMaxHeight = parseInt(window.getComputedStyle(element).maxHeight, 10);
|
299
|
+
var defaultHeight = parseInt(element.readmore.defaultHeight, 10); // Store our measurements.
|
300
|
+
|
301
|
+
element.readmore.expandedHeight = expandedHeight;
|
302
|
+
element.readmore.maxHeight = cssMaxHeight;
|
303
|
+
element.readmore.collapsedHeight = cssMaxHeight || element.readmore.collapsedHeight || defaultHeight;
|
304
|
+
element.style.maxHeight = 'none';
|
305
|
+
}
|
306
|
+
|
307
|
+
function createElementFromString(htmlString) {
|
308
|
+
var div = document.createElement('div');
|
309
|
+
div.innerHTML = htmlString;
|
310
|
+
return div.firstChild;
|
311
|
+
}
|
312
|
+
|
313
|
+
function embedCSS(selector, options) {
|
314
|
+
if (!isCssEmbeddedFor[selector]) {
|
315
|
+
var styles = '';
|
316
|
+
|
317
|
+
if (options.embedCSS && options.blockCSS !== '') {
|
318
|
+
styles += "".concat(selector, " + [data-readmore-toggle], ").concat(selector, "[data-readmore] {\n ").concat(options.blockCSS, "\n }");
|
319
|
+
} // Include the transition CSS even if embedCSS is false
|
320
|
+
|
321
|
+
|
322
|
+
styles += "".concat(selector, "[data-readmore] {\n transition: height ").concat(options.speed, "ms;\n overflow: hidden;\n }");
|
323
|
+
|
324
|
+
(function (d, u) {
|
325
|
+
var css = d.createElement('style');
|
326
|
+
css.type = 'text/css';
|
327
|
+
|
328
|
+
if (css.styleSheet) {
|
329
|
+
css.styleSheet.cssText = u;
|
330
|
+
} else {
|
331
|
+
css.appendChild(d.createTextNode(u));
|
332
|
+
}
|
333
|
+
|
334
|
+
d.getElementsByTagName('head')[0].appendChild(css);
|
335
|
+
})(document, styles);
|
336
|
+
|
337
|
+
isCssEmbeddedFor[selector] = true;
|
338
|
+
}
|
339
|
+
}
|
340
|
+
|
341
|
+
function buildToggle(link, element, scope) {
|
342
|
+
function clickHandler(event) {
|
343
|
+
this.toggle(element, event);
|
344
|
+
}
|
345
|
+
|
346
|
+
var text = link;
|
347
|
+
|
348
|
+
if (typeof link === 'function') {
|
349
|
+
text = link(element);
|
350
|
+
}
|
351
|
+
|
352
|
+
var toggleLink = createElementFromString(text);
|
353
|
+
toggleLink.setAttribute('data-readmore-toggle', element.id);
|
354
|
+
toggleLink.setAttribute('aria-controls', element.id);
|
355
|
+
toggleLink.addEventListener('click', clickHandler.bind(scope));
|
356
|
+
return toggleLink;
|
357
|
+
}
|
358
|
+
|
359
|
+
function isEnvironmentSupported() {
|
360
|
+
return typeof window !== 'undefined' && typeof document !== 'undefined' && !!document.querySelectorAll && !!window.addEventListener;
|
361
|
+
}
|
362
|
+
|
363
|
+
var resizeBoxes = debounce(function () {
|
364
|
+
var elements = document.querySelectorAll('[data-readmore]');
|
365
|
+
forEach(elements, function (element) {
|
366
|
+
var expanded = element.getAttribute('aria-expanded') === 'true';
|
367
|
+
setBoxHeights(element);
|
368
|
+
element.style.height = "".concat(expanded ? element.readmore.expandedHeight : element.readmore.collapsedHeight, "px");
|
369
|
+
});
|
370
|
+
}, 100);
|
371
|
+
var defaults = {
|
372
|
+
speed: 100,
|
373
|
+
collapsedHeight: 200,
|
374
|
+
heightMargin: 16,
|
375
|
+
moreLink: '<a href="#">Read More</a>',
|
376
|
+
lessLink: '<a href="#">Close</a>',
|
377
|
+
embedCSS: true,
|
378
|
+
blockCSS: 'display: block; width: 100%;',
|
379
|
+
startOpen: false,
|
380
|
+
sourceOrder: 'after',
|
381
|
+
// callbacks
|
382
|
+
blockProcessed: function blockProcessed() {},
|
383
|
+
beforeToggle: function beforeToggle() {},
|
384
|
+
afterToggle: function afterToggle() {}
|
385
|
+
};
|
386
|
+
|
387
|
+
var Readmore =
|
388
|
+
/*#__PURE__*/
|
389
|
+
function () {
|
390
|
+
function Readmore() {
|
391
|
+
var _this2 = this;
|
392
|
+
|
393
|
+
_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, Readmore);
|
394
|
+
|
395
|
+
if (!isEnvironmentSupported()) return;
|
396
|
+
|
397
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
398
|
+
args[_key3] = arguments[_key3];
|
399
|
+
}
|
400
|
+
|
401
|
+
var selector = args[0],
|
402
|
+
options = args[1];
|
403
|
+
var elements;
|
404
|
+
|
405
|
+
if (typeof selector === 'string') {
|
406
|
+
elements = document.querySelectorAll(selector);
|
407
|
+
} else if (selector.nodeName) {
|
408
|
+
elements = [selector]; // emulate a NodeList by casting a single Node as an array
|
409
|
+
} else {
|
410
|
+
elements = selector;
|
411
|
+
} // After all that, if we _still_ don't have iteratable NodeList, bail out.
|
412
|
+
|
413
|
+
|
414
|
+
if (!elements.length) return;
|
415
|
+
this.options = extend({}, defaults, options);
|
416
|
+
|
417
|
+
if (typeof selector === 'string') {
|
418
|
+
embedCSS(selector, this.options);
|
419
|
+
} else {
|
420
|
+
// Instances need distinct selectors so they don't stomp on each other.
|
421
|
+
this.instanceSelector = ".".concat(uniqueId());
|
422
|
+
embedCSS(this.instanceSelector, this.options);
|
423
|
+
} // Need to resize boxes when the page has fully loaded.
|
424
|
+
|
425
|
+
|
426
|
+
window.addEventListener('load', resizeBoxes);
|
427
|
+
window.addEventListener('resize', resizeBoxes);
|
428
|
+
this.elements = [];
|
429
|
+
forEach(elements, function (element) {
|
430
|
+
if (_this2.instanceSelector) {
|
431
|
+
element.classList.add(_this2.instanceSelector.substr(1));
|
432
|
+
}
|
433
|
+
|
434
|
+
var expanded = _this2.options.startOpen;
|
435
|
+
element.readmore = {
|
436
|
+
defaultHeight: _this2.options.collapsedHeight,
|
437
|
+
heightMargin: _this2.options.heightMargin
|
438
|
+
};
|
439
|
+
setBoxHeights(element);
|
440
|
+
var heightMargin = element.readmore.heightMargin;
|
441
|
+
|
442
|
+
if (element.getBoundingClientRect().height <= element.readmore.collapsedHeight + heightMargin) {
|
443
|
+
if (typeof _this2.options.blockProcessed === 'function') {
|
444
|
+
_this2.options.blockProcessed(element, false);
|
445
|
+
}
|
446
|
+
|
447
|
+
return;
|
448
|
+
}
|
449
|
+
|
450
|
+
element.setAttribute('data-readmore', '');
|
451
|
+
element.setAttribute('aria-expanded', expanded);
|
452
|
+
element.id = element.id || uniqueId();
|
453
|
+
var toggleLink = expanded ? _this2.options.lessLink : _this2.options.moreLink;
|
454
|
+
var toggleElement = buildToggle(toggleLink, element, _this2);
|
455
|
+
element.parentNode.insertBefore(toggleElement, _this2.options.sourceOrder === 'before' ? element : element.nextSibling);
|
456
|
+
element.style.height = "".concat(expanded ? element.readmore.expandedHeight : element.readmore.collapsedHeight, "px");
|
457
|
+
|
458
|
+
if (typeof _this2.options.blockProcessed === 'function') {
|
459
|
+
_this2.options.blockProcessed(element, true);
|
460
|
+
}
|
461
|
+
|
462
|
+
_this2.elements.push(element);
|
463
|
+
});
|
464
|
+
} // Signature when called internally by the toggleLink click handler:
|
465
|
+
// toggle(element, event)
|
466
|
+
//
|
467
|
+
// When called externally by an instance,
|
468
|
+
// e.g. readmoreDemo.toggle(document.querySelector('article:nth-of-type(1)')):
|
469
|
+
// toggle(elementOrQuerySelector)
|
470
|
+
|
471
|
+
|
472
|
+
_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(Readmore, [{
|
473
|
+
key: "toggle",
|
474
|
+
value: function toggle() {
|
475
|
+
var _this3 = this;
|
476
|
+
|
477
|
+
var el = arguments.length <= 0 ? undefined : arguments[0];
|
478
|
+
|
479
|
+
var toggleElement = function toggleElement(element) {
|
480
|
+
var trigger = document.querySelector("[aria-controls=\"".concat(element.id, "\"]"));
|
481
|
+
var expanded = element.getBoundingClientRect().height <= element.readmore.collapsedHeight;
|
482
|
+
var newHeight = expanded ? element.readmore.expandedHeight : element.readmore.collapsedHeight; // Fire beforeToggle callback
|
483
|
+
// Since we determined the new "expanded" state above we're now out of sync
|
484
|
+
// with our true current state, so we need to flip the value of `expanded`
|
485
|
+
|
486
|
+
if (typeof _this3.options.beforeToggle === 'function') {
|
487
|
+
var shouldContinueToggle = _this3.options.beforeToggle(trigger, element, !expanded); // if the beforeToggle callback returns false, stop toggling
|
488
|
+
|
489
|
+
|
490
|
+
if (shouldContinueToggle === false) {
|
491
|
+
return;
|
492
|
+
}
|
493
|
+
}
|
494
|
+
|
495
|
+
element.style.height = "".concat(newHeight, "px");
|
496
|
+
|
497
|
+
var transitionendHandler = function transitionendHandler(transitionEvent) {
|
498
|
+
// Fire afterToggle callback
|
499
|
+
if (typeof _this3.options.afterToggle === 'function') {
|
500
|
+
_this3.options.afterToggle(trigger, element, expanded);
|
501
|
+
}
|
502
|
+
|
503
|
+
transitionEvent.stopPropagation();
|
504
|
+
element.setAttribute('aria-expanded', expanded);
|
505
|
+
element.removeEventListener('transitionend', transitionendHandler, false);
|
506
|
+
};
|
507
|
+
|
508
|
+
element.addEventListener('transitionend', transitionendHandler, false);
|
509
|
+
|
510
|
+
if (_this3.options.speed < 1) {
|
511
|
+
transitionendHandler.call(_this3, {
|
512
|
+
target: element
|
513
|
+
});
|
514
|
+
}
|
515
|
+
|
516
|
+
var toggleLink = expanded ? _this3.options.lessLink : _this3.options.moreLink;
|
517
|
+
|
518
|
+
if (!toggleLink) {
|
519
|
+
trigger.remove();
|
520
|
+
} else if (trigger && trigger.parentNode) {
|
521
|
+
trigger.parentNode.replaceChild(buildToggle(toggleLink, element, _this3), trigger);
|
522
|
+
}
|
523
|
+
};
|
524
|
+
|
525
|
+
if (typeof el === 'string') {
|
526
|
+
el = document.querySelectorAll(el);
|
527
|
+
}
|
528
|
+
|
529
|
+
if (!el) {
|
530
|
+
throw new Error('Element MUST be either an HTML node or querySelector string');
|
531
|
+
}
|
532
|
+
|
533
|
+
var event = arguments.length <= 1 ? undefined : arguments[1];
|
534
|
+
|
535
|
+
if (event) {
|
536
|
+
event.preventDefault();
|
537
|
+
event.stopPropagation();
|
538
|
+
}
|
539
|
+
|
540
|
+
if (_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_2___default()(el) === 'object' && !el.nodeName) {
|
541
|
+
// element is likely a NodeList
|
542
|
+
forEach(el, toggleElement);
|
543
|
+
} else {
|
544
|
+
toggleElement(el);
|
545
|
+
}
|
546
|
+
}
|
547
|
+
}, {
|
548
|
+
key: "destroy",
|
549
|
+
value: function destroy(selector) {
|
550
|
+
var _this4 = this;
|
551
|
+
|
552
|
+
var elements;
|
553
|
+
|
554
|
+
if (!selector) {
|
555
|
+
elements = this.elements; // eslint-disable-line
|
556
|
+
} else if (typeof selector === 'string') {
|
557
|
+
elements = document.querySelectorAll(selector);
|
558
|
+
} else if (selector.nodeName) {
|
559
|
+
elements = [selector]; // emulate a NodeList by casting a single Node as an array
|
560
|
+
} else {
|
561
|
+
elements = selector;
|
562
|
+
}
|
563
|
+
|
564
|
+
forEach(elements, function (element) {
|
565
|
+
if (_this4.elements.indexOf(element) === -1) {
|
566
|
+
return;
|
567
|
+
}
|
568
|
+
|
569
|
+
_this4.elements = _this4.elements.filter(function (el) {
|
570
|
+
return el !== element;
|
571
|
+
});
|
572
|
+
|
573
|
+
if (_this4.instanceSelector) {
|
574
|
+
element.classList.remove(_this4.instanceSelector.substr(1));
|
575
|
+
}
|
576
|
+
|
577
|
+
delete element.readmore;
|
578
|
+
element.style.height = 'initial';
|
579
|
+
element.style.maxHeight = 'initial';
|
580
|
+
element.removeAttribute('data-readmore');
|
581
|
+
element.removeAttribute('aria-expanded');
|
582
|
+
var trigger = document.querySelector("[aria-controls=\"".concat(element.id, "\"]"));
|
583
|
+
|
584
|
+
if (trigger) {
|
585
|
+
trigger.remove();
|
586
|
+
}
|
587
|
+
|
588
|
+
if (element.id.indexOf('rmjs-') !== -1) {
|
589
|
+
element.removeAttribute('id');
|
590
|
+
}
|
591
|
+
});
|
592
|
+
delete this;
|
593
|
+
}
|
594
|
+
}]);
|
595
|
+
|
596
|
+
return Readmore;
|
597
|
+
}();
|
598
|
+
|
599
|
+
Readmore.VERSION = "3.0.0-beta-1";
|
600
|
+
/* harmony default export */ __webpack_exports__["default"] = (Readmore);
|
601
|
+
|
602
|
+
/***/ }),
|
603
|
+
|
604
|
+
/***/ 0:
|
605
|
+
/*!*******************************!*\
|
606
|
+
!*** multi ./src/readmore.js ***!
|
607
|
+
\*******************************/
|
608
|
+
/*! no static exports found */
|
609
|
+
/***/ (function(module, exports, __webpack_require__) {
|
610
|
+
|
611
|
+
module.exports = __webpack_require__(/*! ./src/readmore.js */"./src/readmore.js");
|
612
|
+
|
613
|
+
|
614
|
+
/***/ })
|
615
|
+
|
616
|
+
/******/ })["default"];
|
617
|
+
});
|
618
|
+
//# sourceMappingURL=readmore.js.map
|