Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dataset rather than jquery data function #1449

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions app/javascript/src/modules/css_injection.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Module injects css into head of embeded page

(function( global ) {
var Module = (function() {
const Module = (function() {

var linkHtml = '<link rel="stylesheet" href="{{stylesheetLink}}" type="text/css" />',
themeUrl = $("[data-sul-embed-theme]").data("sul-embed-theme"),
iconsUrl = $('[data-sul-icons]').data('sul-icons'),
pluginStylesheets = $('[data-plugin-styles]').data('plugin-styles') || '';
const linkHtml = '<link rel="stylesheet" href="{{stylesheetLink}}" type="text/css" />',
themeUrl = document.querySelector("[data-sul-embed-theme]").dataset.sulEmbedTheme,
iconsNode = document.querySelector('[data-sul-icons]'),
pluginStylesheets = document.querySelector('[data-plugin-styles]')?.dataset?.pluginStyles || '';

return {
appendToHead: function() {
Expand All @@ -17,8 +17,9 @@
},

injectFontIcons: function() {
if ( iconsUrl ) {
var htmlSnippet = linkHtml.replace('{{stylesheetLink}}', iconsUrl);
if ( iconsNode ) {
const iconsUrl = iconsNode.dataset.sulIcons
const htmlSnippet = linkHtml.replace('{{stylesheetLink}}', iconsUrl);
$('head').append(htmlSnippet);
}
},
Expand Down
11 changes: 6 additions & 5 deletions app/javascript/src/modules/embed_this.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@
var _this = this,
textarea = $('textarea', formContainer);
$('input[type="checkbox"], input[type="text"]', formContainer).on('change', function(){
var checked = $(this).is(':checked'),
const checked = $(this).is(':checked'),
inputType = $(this).attr('type'),
src = textarea.text().match(/src="(\S+)"/)[1],
urlAttr = '&' + $(this).data('embed-attr') + '=true';
urlAttr = `&${this.dataset.embedAttr}=true`
if(inputType === 'checkbox'){
if(checked) {
textarea.text(textarea.text().replace(urlAttr, ''));
}else{
textarea.text(textarea.text().replace(src, src + urlAttr));
}
}else{
if(oldParam = textarea.text().match('&' + $(this).data('embed-attr') + "=\\w+")) {
textarea.text(textarea.text().replace(oldParam, '&' + $(this).data('embed-attr') + '=' + $(this).val()));
const value = $(this).val()
if(oldParam = textarea.text().match(`&${this.dataset.embedAttr}=\\w+`)) {
textarea.text(textarea.text().replace(oldParam, `&${this.dataset.embedAttr}=${value}`));
}else{
textarea.text(textarea.text().replace(src, src + '&' + $(this).data('embed-attr') + '=' + $(this).val()));
textarea.text(textarea.text().replace(src, `${src}&${this.dataset.embedAttr}=${value}`));
}
}
});
Expand Down
27 changes: 18 additions & 9 deletions app/javascript/src/modules/geo_viewer.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
(function( global ) {
'use strict';
var Module = (function() {
var dataAttributes;
var map;
var $el;
const Module = (function() {
let dataAttributes;
let boundingBox;
let map;
let $el;

var isDefined = function(object) {
const isDefined = function(object) {
return typeof object !== 'undefined';
};

return {
init: function(options) {
$el = jQuery('#sul-embed-geo-map');
dataAttributes = $el.data();
const el = document.getElementById('sul-embed-geo-map')

map = L.map('sul-embed-geo-map', options).fitBounds(dataAttributes.boundingBox);
dataAttributes = el.dataset;
// dataAttributes looks like this:
// {
// "boundingBox": "[[\"-1.478794\", \"29.572742\"], [\"4.234077\", \"35.000308\"]]",
// "wmsUrl": "https://geowebservices.stanford.edu/geoserver/wms/",
// "layers": "druid:cz128vq0535"
// }
boundingBox = JSON.parse(dataAttributes.boundingBox)
$el = jQuery(el);
map = L.map('sul-embed-geo-map', options).fitBounds(boundingBox);

L.tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
maxZoom: 19,
Expand Down Expand Up @@ -74,7 +83,7 @@
Module.setupFeatureInspection();
} else {
// Restricted layers
L.rectangle(dataAttributes.boundingBox, {color: '#0000FF', weight: 4})
L.rectangle(boundingBox, {color: '#0000FF', weight: 4})
.addTo(map);
}
},
Expand Down
6 changes: 3 additions & 3 deletions app/javascript/src/modules/m3_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import cdlAuthPlugin from '../plugins/cdlAuthPlugin';

export default {
init: function() {
var $el = jQuery('#sul-embed-m3');
var data = $el.data();
const el = document.getElementById('sul-embed-m3');
const data = el.dataset;

// Determine which panel should be open
var sideBarPanel = 'info';
let sideBarPanel = 'info';
if (data.search) {
sideBarPanel = 'search';
}
Expand Down
23 changes: 11 additions & 12 deletions app/javascript/src/modules/media_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,32 @@ export default (function() {
cssClass = 'sul-i-file-video-3';
}

var activeClass = '';
let activeClass = '';
if (index === 0) {
activeClass = 'active';
}

var thumbClass = 'sul-embed-slider-thumb sul-embed-media-slider-thumb ';
var labelClass = 'sul-embed-thumb-label';
const thumbClass = 'sul-embed-slider-thumb sul-embed-media-slider-thumb ';
let labelClass = 'sul-embed-thumb-label';
const isStanfordRestricted = mediaDiv.dataset.stanfordOnly === "true"
if (isStanfordRestricted) {
labelClass += ' sul-embed-thumb-stanford-only';
}

var thumbnailIcon = '';
let thumbnailIcon = '';
const thumbnailUrl = mediaDiv.dataset.thumbnailUrl
if (thumbnailUrl !== '') {
thumbnailIcon = '<img class="sul-embed-media-square-icon" src="' + thumbnailUrl + '" />';
thumbnailIcon = `<img class="sul-embed-media-square-icon" src="${thumbnailUrl}" />`
} else {
thumbnailIcon = '<i class="' + cssClass + '"></i>';
thumbnailIcon = `<i class="${cssClass}"></i>`
}

const isLocationRestricted = mediaDiv.dataset.locationRestricted === "true"
const fileLabel = String(mediaDiv.dataset.fileLabel || '');
const duration = String(mediaDiv.dataset.duration || '');
thumbs.push(
'<li class="' + thumbClass + activeClass + '">' +
thumbnailIcon +
'<a class="' + labelClass + '" href="#">' +
`<li class="${thumbClass}${activeClass}">${thumbnailIcon}` +
`<a class="${labelClass}" href="#">` +
stanfordOnlyScreenreaderText(isStanfordRestricted) +
restrictedTextMarkup(isLocationRestricted) +
truncateWithEllipsis(fileLabel, maxFileLabelLength(isLocationRestricted)) +
Expand Down Expand Up @@ -168,12 +167,12 @@ export default (function() {
}

if(data.status === 'success') {
updateMediaSrcWithToken(mediaObject, data.token);
initializeVideoJSPlayer(mediaObject);
updateMediaSrcWithToken($mediaObject, data.token);
initializeVideoJSPlayer($mediaObject);
}

if(typeof(completeCallback) === 'function') {
completeCallback(mediaObject, data);
completeCallback($mediaObject, data);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require 'view_component/test_helpers'
require 'view_component/system_test_helpers'

Capybara.javascript_driver = :selenium_chrome_headless
Capybara.javascript_driver = :selenium_chrome#_headless

Capybara.default_max_wait_time = ENV['CI'] ? 30 : 10

Expand Down
Loading