|
@@ -5,269 +5,133 @@ License: https://github.com/coderedcorp/coderedcms/blob/dev/LICENSE
|
|
|
@license magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt BSD-3-Clause
|
|
|
*/
|
|
|
|
|
|
-libs = {
|
|
|
- masonry: {
|
|
|
- url: "https://cdnjs.cloudflare.com/ajax/libs/masonry/4.2.2/masonry.pkgd.min.js",
|
|
|
- integrity: "sha512-JRlcvSZAXT8+5SQQAvklXGJuxXTouyq8oIMaYERZQasB8SBDHZaUbeASsJWpk0UUrf89DP3/aefPPrlMR1h1yQ==",
|
|
|
- },
|
|
|
- modernizr: {
|
|
|
- url: "https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js",
|
|
|
- integrity: "sha256-0rguYS0qgS6L4qVzANq4kjxPLtvnp5nn2nB5G1lWRv4=",
|
|
|
- },
|
|
|
- moment: {
|
|
|
- url: "https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js",
|
|
|
- integrity: "sha256-4iQZ6BVL4qNKlQ27TExEhBN1HFPvAvAMbFavKKosSWQ="
|
|
|
- },
|
|
|
- pickerbase: {
|
|
|
- url: "https://cdnjs.cloudflare.com/ajax/libs/pickadate.js/3.6.3/compressed/picker.js",
|
|
|
- integrity: "sha256-hjN7Qqm7pjV+lms0uyeJBro1vyCH2azVGqyuWeZ6CFM=",
|
|
|
- head: '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pickadate.js/3.6.3/compressed/themes/default.css" integrity="sha256-wtVxHQXXtr975G710f51YDv94+6f6cuK49PcANcKccY=" crossorigin="anonymous" />'
|
|
|
- },
|
|
|
- pickadate: {
|
|
|
- url: "https://cdnjs.cloudflare.com/ajax/libs/pickadate.js/3.6.3/compressed/picker.date.js",
|
|
|
- integrity: "sha256-Z4OXXhjTbpFlc4Z6HqgVtVaz7Nt/3ptUKBOhxIze1eE=",
|
|
|
- head: '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pickadate.js/3.6.3/compressed/themes/default.date.css" integrity="sha256-U24A2dULD5s+Dl/tKvi5zAe+CAMKBFUaHUtLN8lRnKE=" crossorigin="anonymous" />'
|
|
|
- },
|
|
|
- pickatime: {
|
|
|
- url: "https://cdnjs.cloudflare.com/ajax/libs/pickadate.js/3.6.3/compressed/picker.time.js",
|
|
|
- integrity: "sha256-mvFcf2wocDC8U1GJdTVSmMHBn/dBLNeJjYRvBhM6gc8=",
|
|
|
- head: '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pickadate.js/3.6.3/compressed/themes/default.time.css" integrity="sha256-dtpQarv++ugnrcY7o6Gr3m7fIJFJDSx8v76jjTqEeKE=" crossorigin="anonymous" />'
|
|
|
- },
|
|
|
- fullcalendar: {
|
|
|
- url: "https://cdn.jsdelivr.net/npm/fullcalendar@5.9.0/main.min.js",
|
|
|
- integrity: "sha256-8nl2O4lMNahIAmUnxZprMxJIBiPv+SzhMuYwEuinVM0=",
|
|
|
- head: '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fullcalendar@5.9.0/main.min.css" integrity="sha256-FjyLCG3re1j4KofUTQQXmaWJw13Jdb7LQvXlkFxTDJI=" crossorigin="anonymous">'
|
|
|
- },
|
|
|
- coderedmaps: {
|
|
|
- url: "/static/coderedcms/js/codered-maps.js?v=" + cr_version,
|
|
|
- integrity: "",
|
|
|
- },
|
|
|
- coderedstreamforms: {
|
|
|
- url: "/static/coderedcms/js/codered-streamforms.js?v=" + cr_version,
|
|
|
- integrity: "",
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
+/**
|
|
|
+ * Main script which is used to detect CRX features requiring JavaScript.
|
|
|
+ *
|
|
|
+ * Loads the necessary libraries for that feature, then initializes any
|
|
|
+ * feature-specific code. This should only be used for features that might be
|
|
|
+ * site-wide (e.g. StreamField blocks that could occur anywhere). For
|
|
|
+ * functionality that is page-specific, include the JavaScript normally via a
|
|
|
+ * script tag on that page instead.
|
|
|
+ *
|
|
|
+ * This file must run with "pure" JavaScript - assume jQuery or any other
|
|
|
+ * scripts are not yet loaded.
|
|
|
+ */
|
|
|
+const libs = {
|
|
|
+ masonry: {
|
|
|
+ url: "https://cdn.jsdelivr.net/npm/masonry-layout@4.2.2/dist/masonry.pkgd.min.js",
|
|
|
+ integrity: "sha256-Nn1q/fx0H7SNLZMQ5Hw5JLaTRZp0yILA/FRexe19VdI=",
|
|
|
+ },
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * Dynamically loads a script and/or CSS from the `lib` object above.
|
|
|
+ *
|
|
|
+ * Put functionality related to the script you are loading into the `success`
|
|
|
+ * callback of the `load_script` function. Otherwise, it might not work as
|
|
|
+ * intended.
|
|
|
+ */
|
|
|
function load_script(lib, success) {
|
|
|
- // lib is an entry in `libs` above.
|
|
|
- // It is best to put functionality related to the script you are loading into the success callback of the load_script function.
|
|
|
- // Otherwise, it might not work as intended.
|
|
|
- if(lib.head) {
|
|
|
- $('head').append(lib.head);
|
|
|
- }
|
|
|
- if(lib.url){
|
|
|
- $.ajax({
|
|
|
- url: lib.url,
|
|
|
- dataType: "script",
|
|
|
- integrity: lib.integrity,
|
|
|
- crossorigin: "anonymous",
|
|
|
- success: success
|
|
|
- });
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-$(document).ready(function()
|
|
|
-{
|
|
|
-
|
|
|
- /*** AJAX Setup CSRF Setup ***/
|
|
|
- function getCookie(name) {
|
|
|
- var cookieValue = null;
|
|
|
- if (document.cookie && document.cookie !== '') {
|
|
|
- var cookies = document.cookie.split(';');
|
|
|
- for (var i = 0; i < cookies.length; i++) {
|
|
|
- var cookie = jQuery.trim(cookies[i]);
|
|
|
- // Does this cookie string begin with the name we want?
|
|
|
- if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
|
|
- cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ var head = document.getElementsByTagName("head")[0];
|
|
|
+ if (lib.head) {
|
|
|
+ // Create a temporary element and insert the `lib.head` string to form a
|
|
|
+ // child element.
|
|
|
+ var tmpEl = document.createElement("div");
|
|
|
+ tmpEl.innerHTML = lib.head;
|
|
|
+ // Append the child element to the `<head>`
|
|
|
+ head.append(tmpEl.firstElementChild);
|
|
|
+ }
|
|
|
+ if (lib.url) {
|
|
|
+ // Fetch and execute the script in the global context.
|
|
|
+ // Then call the `success` callback.
|
|
|
+ fetch(lib.url, {
|
|
|
+ integrity: lib.integrity,
|
|
|
+ referrerPolicy: "origin",
|
|
|
+ })
|
|
|
+ .then(function (response) {
|
|
|
+ return response.text();
|
|
|
+ })
|
|
|
+ .then(function (txt) {
|
|
|
+ // Eval in the global scope.
|
|
|
+ eval?.(txt);
|
|
|
+ })
|
|
|
+ .then(function () {
|
|
|
+ if (success) {
|
|
|
+ success();
|
|
|
}
|
|
|
- return cookieValue;
|
|
|
- }
|
|
|
- var csrftoken = getCookie('csrftoken');
|
|
|
-
|
|
|
- function csrfSafeMethod(method) {
|
|
|
- // these HTTP methods do not require CSRF protection
|
|
|
- return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
|
|
|
- }
|
|
|
- $.ajaxSetup({
|
|
|
- beforeSend: function(xhr, settings) {
|
|
|
- if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
|
|
|
- xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- /*** Forms ***/
|
|
|
- if ( $('form').length > 0) {
|
|
|
- load_script(libs.modernizr, function() {
|
|
|
- if ( (!Modernizr.inputtypes.date || !Modernizr.inputtypes.time) && $("input[type='date'], input[type='time']").length > 0) {
|
|
|
- load_script(libs.pickerbase, function() {
|
|
|
- $(document).trigger("base-picker-loaded");
|
|
|
- });
|
|
|
- }
|
|
|
- if(!Modernizr.inputtypes.date && $("input[type='date']").length > 0) {
|
|
|
- $(document).on("base-picker-loaded", function() {
|
|
|
- load_script(libs.pickadate, function() {
|
|
|
- // Show date picker
|
|
|
- $("input[type='date']").pickadate({
|
|
|
- format: 'mm/dd/yyyy',
|
|
|
- selectMonths: true,
|
|
|
- selectYears: true
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- if(!Modernizr.inputtypes.time && $("[type='time']").length > 0) {
|
|
|
- $(document).on("base-picker-loaded", function() {
|
|
|
- load_script(libs.pickatime, function() {
|
|
|
- // Show time picker
|
|
|
- $("input[type='time']").pickatime({
|
|
|
- format: 'h:i A',
|
|
|
- interval: 15
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- if (!Modernizr.inputtypes['datetime-local'] && $("input[type='datetime-local']").length > 0) {
|
|
|
- load_script(libs.moment, function() {
|
|
|
- // Show formatting help text
|
|
|
- $('.datetime-help').show();
|
|
|
- // Format input on blur
|
|
|
- $("[type='datetime-local']").blur(function() {
|
|
|
- var clean = $.trim($(this).val());
|
|
|
- if (clean != '') {
|
|
|
- clean = moment(clean).format("L LT");
|
|
|
- $(this).val(clean);
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /*** Calendar **/
|
|
|
- if ( $("[data-block='calendar']").length > 0){
|
|
|
- load_script(libs.fullcalendar, function(){
|
|
|
- var calendars = document.querySelectorAll("[data-block='calendar']");
|
|
|
- calendars.forEach(function(el){
|
|
|
- var pageId = el.dataset.pageId; // data-page-id
|
|
|
- var defaultDate = el.dataset.defaultDate; // data-default-date
|
|
|
- var defaultView = el.dataset.defaultView; // data-default-view
|
|
|
- var eventDisplay = el.dataset.eventDisplay; // data-event-display
|
|
|
- var timezone = el.dataset.timezone; // data-timezone
|
|
|
- var calendar = new FullCalendar.Calendar(el, {
|
|
|
- headerToolbar: {
|
|
|
- left: 'prev,next today',
|
|
|
- center: 'title',
|
|
|
- right: 'dayGridMonth,timeGridWeek,timeGridDay,listMonth'
|
|
|
- },
|
|
|
- themeSystem: 'bootstrap',
|
|
|
- bootstrapFontAwesome: false,
|
|
|
- buttonText: {
|
|
|
- 'prev': '< prev',
|
|
|
- 'next': 'next >'
|
|
|
- },
|
|
|
- initialDate: defaultDate,
|
|
|
- initialView: defaultView,
|
|
|
- fixedWeekCount: false,
|
|
|
- timeZone: timezone,
|
|
|
- eventDisplay: eventDisplay,
|
|
|
- eventSources: {
|
|
|
- url: '/ajax/calendar/events/',
|
|
|
- method: 'GET',
|
|
|
- extraParams: {
|
|
|
- 'pid': pageId
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- calendar.render();
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- if ($('#cr-map').length > 0) {
|
|
|
- load_script(libs.coderedmaps, function() {
|
|
|
- $.ajax({
|
|
|
- url: 'https://maps.googleapis.com/maps/api/js',
|
|
|
- type: "get",
|
|
|
- dataType: "script",
|
|
|
- data: {
|
|
|
- 'key': $("#cr-map").data( "key" ),
|
|
|
- 'callback': $("#cr-map").data( "callback" ),
|
|
|
- 'libraries': $("#cr-map").data( "libraries" ),
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- if ($('.stream-form-input').length > 0){
|
|
|
- load_script(libs.coderedstreamforms);
|
|
|
- }
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- /*** Lightbox ***/
|
|
|
- $('.lightbox-preview').on('click', function(event) {
|
|
|
- var orig_src = $(this).find('img').data('original-src');
|
|
|
- var orig_alt = $(this).find('img').attr('alt');
|
|
|
- var orig_ttl = $(this).find('img').attr('title');
|
|
|
- var $lightbox = $($(this).data('target'));
|
|
|
- $lightbox.find('img').attr('src', orig_src);
|
|
|
- $lightbox.find('img').attr('alt', orig_alt);
|
|
|
- $lightbox.find('img').attr('title', orig_ttl);
|
|
|
+document.addEventListener("DOMContentLoaded", function () {
|
|
|
+ /** Lightbox **/
|
|
|
+ document.querySelectorAll(".lightbox-preview").forEach(function (el) {
|
|
|
+ el.addEventListener("click", function (event) {
|
|
|
+ var el = event.currentTarget;
|
|
|
+ var orig_src = el.querySelector("img").dataset.originalSrc;
|
|
|
+ var orig_alt = el.querySelector("img").alt;
|
|
|
+ var orig_ttl = el.querySelector("img").title;
|
|
|
+ var lightbox = document.querySelector(el.dataset.bsTarget);
|
|
|
+ lightbox.querySelector("img").setAttribute("src", orig_src);
|
|
|
+ lightbox.querySelector("img").setAttribute("alt", orig_alt);
|
|
|
+ lightbox.querySelector("img").setAttribute("title", orig_ttl);
|
|
|
});
|
|
|
-
|
|
|
-
|
|
|
- /*** Content walls ***/
|
|
|
- $(".modal[data-cr-wall-showonce='true']").on('hide.bs.modal', function() {
|
|
|
- localStorage["cr_wall_" + $(this).data("cr-wall-id")] = "dismissed";
|
|
|
+ });
|
|
|
+
|
|
|
+ /** Content walls **/
|
|
|
+ document
|
|
|
+ .querySelectorAll(".modal[data-cr-wall-showonce='true']")
|
|
|
+ .forEach(function (el) {
|
|
|
+ el.addEventListener("hide.bs.modal", function () {
|
|
|
+ localStorage["cr_wall_" + el.dataset.crWallId] = "dismissed";
|
|
|
+ });
|
|
|
});
|
|
|
- $(".modal[data-cr-wall-id]").each(function() {
|
|
|
- if(localStorage["cr_wall_" + $(this).data("cr-wall-id")] === undefined) {
|
|
|
- $(this).modal('show');
|
|
|
+ document.querySelectorAll(".modal[data-cr-wall-id]").forEach(function (el) {
|
|
|
+ if (localStorage["cr_wall_" + el.dataset.crWallId] === undefined) {
|
|
|
+ const modal = new bootstrap.Modal(el);
|
|
|
+ modal.show();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ /** Tracking **/
|
|
|
+ if (typeof cr_track_clicks !== "undefined" && cr_track_clicks) {
|
|
|
+ document.querySelectorAll("a").forEach(function (el) {
|
|
|
+ el.addEventListener("click", function (event) {
|
|
|
+ var el = event.currentTarget;
|
|
|
+ gtag_data = {
|
|
|
+ event_category: "Link",
|
|
|
+ event_label: el.textContent.trim().substring(0, 30),
|
|
|
+ };
|
|
|
+ if (el.dataset.gaEventCategory) {
|
|
|
+ gtag_data["event_category"] = el.dataset.gaEventCategory;
|
|
|
}
|
|
|
+ if (el.dataset.gaEventLabel) {
|
|
|
+ gtag_data["event_label"] = el.dataset.gaEventLabel;
|
|
|
+ }
|
|
|
+ gtag("event", "click", gtag_data);
|
|
|
+ });
|
|
|
});
|
|
|
+ }
|
|
|
+
|
|
|
+ /** Link handling **/
|
|
|
+ if (typeof cr_external_new_tab !== "undefined" && cr_external_new_tab) {
|
|
|
+ document.querySelectorAll("a").forEach(function (el) {
|
|
|
+ var href = el.href.trim();
|
|
|
+ if (
|
|
|
+ !href.startsWith(cr_site_url) &&
|
|
|
+ !href.startsWith("/") &&
|
|
|
+ !href.startsWith("#") &&
|
|
|
+ !href.startsWith("?")
|
|
|
+ ) {
|
|
|
+ el.setAttribute("target", "_blank");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- /*** Tracking ***/
|
|
|
- if(typeof cr_track_clicks !== 'undefined' && cr_track_clicks) {
|
|
|
- $('a').on('click', function(){
|
|
|
- gtag_data = {
|
|
|
- "event_category": "Link",
|
|
|
- "event_label": $(this).text().trim().substring(0, 30)
|
|
|
- };
|
|
|
- if ($(this).data('ga-event-category')) {
|
|
|
- gtag_data['event_category'] = $(this).data('ga-event-category');
|
|
|
- }
|
|
|
- if ($(this).data('ga-event-label')) {
|
|
|
- gtag_data['event_label'] = $(this).data('ga-event-label');
|
|
|
- }
|
|
|
- gtag('event', 'click', gtag_data);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /*** Link handling ***/
|
|
|
- if(typeof cr_external_new_tab !== 'undefined' && cr_external_new_tab) {
|
|
|
- $('a').each(function() {
|
|
|
- var href = $(this).prop('href').trim();
|
|
|
- if(
|
|
|
- !href.startsWith(cr_site_url) &&
|
|
|
- !href.startsWith('/') &&
|
|
|
- !href.startsWith('#') &&
|
|
|
- !href.startsWith('?')
|
|
|
- ) {
|
|
|
- $(this).prop('target', '_blank');
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /*** Masonry ***/
|
|
|
- if ($('[data-masonry]').length > 0){
|
|
|
- load_script(libs.masonry);
|
|
|
- }
|
|
|
-
|
|
|
+ /** Masonry **/
|
|
|
+ if (document.querySelectorAll("[data-masonry]").length > 0) {
|
|
|
+ load_script(libs.masonry);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
/* @license-end */
|