mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-30 15:42:41 +01:00
Standardised JS vars and imports/exports
This commit is contained in:
parent
573357a08c
commit
08c4b9ac7c
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import 'moment/locale/en-gb';
|
import 'moment/locale/en-gb';
|
||||||
|
import editorOptions from "./pages/page-form";
|
||||||
|
|
||||||
moment.locale('en-gb');
|
moment.locale('en-gb');
|
||||||
|
|
||||||
export default function (ngApp, events) {
|
export default function (ngApp, events) {
|
||||||
@ -23,14 +25,14 @@ export default function (ngApp, events) {
|
|||||||
$scope.searching = false;
|
$scope.searching = false;
|
||||||
$scope.searchTerm = '';
|
$scope.searchTerm = '';
|
||||||
|
|
||||||
var page = 0;
|
let page = 0;
|
||||||
var previousClickTime = 0;
|
let previousClickTime = 0;
|
||||||
var previousClickImage = 0;
|
let previousClickImage = 0;
|
||||||
var dataLoaded = false;
|
let dataLoaded = false;
|
||||||
var callback = false;
|
let callback = false;
|
||||||
|
|
||||||
var preSearchImages = [];
|
let preSearchImages = [];
|
||||||
var preSearchHasMore = false;
|
let preSearchHasMore = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by dropzone to get the endpoint to upload to.
|
* Used by dropzone to get the endpoint to upload to.
|
||||||
@ -79,9 +81,9 @@ export default function (ngApp, events) {
|
|||||||
* @param image
|
* @param image
|
||||||
*/
|
*/
|
||||||
$scope.imageSelect = function (image) {
|
$scope.imageSelect = function (image) {
|
||||||
var dblClickTime = 300;
|
let dblClickTime = 300;
|
||||||
var currentTime = Date.now();
|
let currentTime = Date.now();
|
||||||
var timeDiff = currentTime - previousClickTime;
|
let timeDiff = currentTime - previousClickTime;
|
||||||
|
|
||||||
if (timeDiff < dblClickTime && image.id === previousClickImage) {
|
if (timeDiff < dblClickTime && image.id === previousClickImage) {
|
||||||
// If double click
|
// If double click
|
||||||
@ -137,19 +139,19 @@ export default function (ngApp, events) {
|
|||||||
$('#image-manager').find('.overlay').fadeOut(240);
|
$('#image-manager').find('.overlay').fadeOut(240);
|
||||||
};
|
};
|
||||||
|
|
||||||
var baseUrl = window.baseUrl('/images/' + $scope.imageType + '/all/');
|
let baseUrl = window.baseUrl('/images/' + $scope.imageType + '/all/');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the list image data from the server.
|
* Fetch the list image data from the server.
|
||||||
*/
|
*/
|
||||||
function fetchData() {
|
function fetchData() {
|
||||||
var url = baseUrl + page + '?';
|
let url = baseUrl + page + '?';
|
||||||
var components = {};
|
let components = {};
|
||||||
if ($scope.uploadedTo) components['page_id'] = $scope.uploadedTo;
|
if ($scope.uploadedTo) components['page_id'] = $scope.uploadedTo;
|
||||||
if ($scope.searching) components['term'] = $scope.searchTerm;
|
if ($scope.searching) components['term'] = $scope.searchTerm;
|
||||||
|
|
||||||
|
|
||||||
var urlQueryString = Object.keys(components).map((key) => {
|
let urlQueryString = Object.keys(components).map((key) => {
|
||||||
return key + '=' + encodeURIComponent(components[key]);
|
return key + '=' + encodeURIComponent(components[key]);
|
||||||
}).join('&');
|
}).join('&');
|
||||||
url += urlQueryString;
|
url += urlQueryString;
|
||||||
@ -205,13 +207,13 @@ export default function (ngApp, events) {
|
|||||||
*/
|
*/
|
||||||
$scope.saveImageDetails = function (event) {
|
$scope.saveImageDetails = function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var url = window.baseUrl('/images/update/' + $scope.selectedImage.id);
|
let url = window.baseUrl('/images/update/' + $scope.selectedImage.id);
|
||||||
$http.put(url, this.selectedImage).then(response => {
|
$http.put(url, this.selectedImage).then(response => {
|
||||||
events.emit('success', 'Image details updated');
|
events.emit('success', 'Image details updated');
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
if (response.status === 422) {
|
if (response.status === 422) {
|
||||||
var errors = response.data;
|
let errors = response.data;
|
||||||
var message = '';
|
let message = '';
|
||||||
Object.keys(errors).forEach((key) => {
|
Object.keys(errors).forEach((key) => {
|
||||||
message += errors[key].join('\n');
|
message += errors[key].join('\n');
|
||||||
});
|
});
|
||||||
@ -230,8 +232,8 @@ export default function (ngApp, events) {
|
|||||||
*/
|
*/
|
||||||
$scope.deleteImage = function (event) {
|
$scope.deleteImage = function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var force = $scope.dependantPages !== false;
|
let force = $scope.dependantPages !== false;
|
||||||
var url = window.baseUrl('/images/' + $scope.selectedImage.id);
|
let url = window.baseUrl('/images/' + $scope.selectedImage.id);
|
||||||
if (force) url += '?force=true';
|
if (force) url += '?force=true';
|
||||||
$http.delete(url).then((response) => {
|
$http.delete(url).then((response) => {
|
||||||
$scope.images.splice($scope.images.indexOf($scope.selectedImage), 1);
|
$scope.images.splice($scope.images.indexOf($scope.selectedImage), 1);
|
||||||
@ -266,11 +268,11 @@ export default function (ngApp, events) {
|
|||||||
|
|
||||||
$scope.searchBook = function (e) {
|
$scope.searchBook = function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var term = $scope.searchTerm;
|
let term = $scope.searchTerm;
|
||||||
if (term.length == 0) return;
|
if (term.length == 0) return;
|
||||||
$scope.searching = true;
|
$scope.searching = true;
|
||||||
$scope.searchResults = '';
|
$scope.searchResults = '';
|
||||||
var searchUrl = window.baseUrl('/search/book/' + $attrs.bookId);
|
let searchUrl = window.baseUrl('/search/book/' + $attrs.bookId);
|
||||||
searchUrl += '?term=' + encodeURIComponent(term);
|
searchUrl += '?term=' + encodeURIComponent(term);
|
||||||
$http.get(searchUrl).then((response) => {
|
$http.get(searchUrl).then((response) => {
|
||||||
$scope.searchResults = $sce.trustAsHtml(response.data);
|
$scope.searchResults = $sce.trustAsHtml(response.data);
|
||||||
@ -294,13 +296,13 @@ export default function (ngApp, events) {
|
|||||||
ngApp.controller('PageEditController', ['$scope', '$http', '$attrs', '$interval', '$timeout', '$sce',
|
ngApp.controller('PageEditController', ['$scope', '$http', '$attrs', '$interval', '$timeout', '$sce',
|
||||||
function ($scope, $http, $attrs, $interval, $timeout, $sce) {
|
function ($scope, $http, $attrs, $interval, $timeout, $sce) {
|
||||||
|
|
||||||
$scope.editorOptions = require('./pages/page-form');
|
$scope.editorOptions = editorOptions();
|
||||||
$scope.editContent = '';
|
$scope.editContent = '';
|
||||||
$scope.draftText = '';
|
$scope.draftText = '';
|
||||||
var pageId = Number($attrs.pageId);
|
let pageId = Number($attrs.pageId);
|
||||||
var isEdit = pageId !== 0;
|
let isEdit = pageId !== 0;
|
||||||
var autosaveFrequency = 30; // AutoSave interval in seconds.
|
let autosaveFrequency = 30; // AutoSave interval in seconds.
|
||||||
var isMarkdown = $attrs.editorType === 'markdown';
|
let isMarkdown = $attrs.editorType === 'markdown';
|
||||||
$scope.draftsEnabled = $attrs.draftsEnabled === 'true';
|
$scope.draftsEnabled = $attrs.draftsEnabled === 'true';
|
||||||
$scope.isUpdateDraft = Number($attrs.pageUpdateDraft) === 1;
|
$scope.isUpdateDraft = Number($attrs.pageUpdateDraft) === 1;
|
||||||
$scope.isNewPageDraft = Number($attrs.pageNewDraft) === 1;
|
$scope.isNewPageDraft = Number($attrs.pageNewDraft) === 1;
|
||||||
@ -312,9 +314,9 @@ export default function (ngApp, events) {
|
|||||||
$scope.draftText = 'Editing Page'
|
$scope.draftText = 'Editing Page'
|
||||||
}
|
}
|
||||||
|
|
||||||
var autoSave = false;
|
let autoSave = false;
|
||||||
|
|
||||||
var currentContent = {
|
let currentContent = {
|
||||||
title: false,
|
title: false,
|
||||||
html: false
|
html: false
|
||||||
};
|
};
|
||||||
@ -351,8 +353,8 @@ export default function (ngApp, events) {
|
|||||||
autoSave = $interval(() => {
|
autoSave = $interval(() => {
|
||||||
// Return if manually saved recently to prevent bombarding the server
|
// Return if manually saved recently to prevent bombarding the server
|
||||||
if (Date.now() - lastSave < (1000*autosaveFrequency)/2) return;
|
if (Date.now() - lastSave < (1000*autosaveFrequency)/2) return;
|
||||||
var newTitle = $('#name').val();
|
let newTitle = $('#name').val();
|
||||||
var newHtml = $scope.editContent;
|
let newHtml = $scope.editContent;
|
||||||
|
|
||||||
if (newTitle !== currentContent.title || newHtml !== currentContent.html) {
|
if (newTitle !== currentContent.title || newHtml !== currentContent.html) {
|
||||||
currentContent.html = newHtml;
|
currentContent.html = newHtml;
|
||||||
@ -369,7 +371,7 @@ export default function (ngApp, events) {
|
|||||||
*/
|
*/
|
||||||
function saveDraft() {
|
function saveDraft() {
|
||||||
if (!$scope.draftsEnabled) return;
|
if (!$scope.draftsEnabled) return;
|
||||||
var data = {
|
let data = {
|
||||||
name: $('#name').val(),
|
name: $('#name').val(),
|
||||||
html: isMarkdown ? $sce.getTrustedHtml($scope.displayContent) : $scope.editContent
|
html: isMarkdown ? $sce.getTrustedHtml($scope.displayContent) : $scope.editContent
|
||||||
};
|
};
|
||||||
@ -379,7 +381,7 @@ export default function (ngApp, events) {
|
|||||||
let url = window.baseUrl('/ajax/page/' + pageId + '/save-draft');
|
let url = window.baseUrl('/ajax/page/' + pageId + '/save-draft');
|
||||||
$http.put(url, data).then(responseData => {
|
$http.put(url, data).then(responseData => {
|
||||||
draftErroring = false;
|
draftErroring = false;
|
||||||
var updateTime = moment.utc(moment.unix(responseData.data.timestamp)).toDate();
|
let updateTime = moment.utc(moment.unix(responseData.data.timestamp)).toDate();
|
||||||
$scope.draftText = responseData.data.message + moment(updateTime).format('HH:mm');
|
$scope.draftText = responseData.data.message + moment(updateTime).format('HH:mm');
|
||||||
if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true;
|
if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true;
|
||||||
showDraftSaveNotification();
|
showDraftSaveNotification();
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const DropZone = require('dropzone');
|
import DropZone from "dropzone";
|
||||||
const markdown = require('marked');
|
import markdown from "marked";
|
||||||
|
|
||||||
module.exports = function (ngApp, events) {
|
export default function (ngApp, events) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle Switches
|
* Toggle Switches
|
||||||
@ -190,14 +190,14 @@ module.exports = function (ngApp, events) {
|
|||||||
},
|
},
|
||||||
link: function (scope, element, attrs) {
|
link: function (scope, element, attrs) {
|
||||||
if (attrs.placeholder) element[0].querySelector('.dz-message').textContent = attrs.placeholder;
|
if (attrs.placeholder) element[0].querySelector('.dz-message').textContent = attrs.placeholder;
|
||||||
var dropZone = new DropZone(element[0].querySelector('.dropzone-container'), {
|
let dropZone = new DropZone(element[0].querySelector('.dropzone-container'), {
|
||||||
url: scope.uploadUrl,
|
url: scope.uploadUrl,
|
||||||
init: function () {
|
init: function () {
|
||||||
var dz = this;
|
let dz = this;
|
||||||
dz.on('sending', function (file, xhr, data) {
|
dz.on('sending', function (file, xhr, data) {
|
||||||
var token = window.document.querySelector('meta[name=token]').getAttribute('content');
|
let token = window.document.querySelector('meta[name=token]').getAttribute('content');
|
||||||
data.append('_token', token);
|
data.append('_token', token);
|
||||||
var uploadedTo = typeof scope.uploadedTo === 'undefined' ? 0 : scope.uploadedTo;
|
let uploadedTo = typeof scope.uploadedTo === 'undefined' ? 0 : scope.uploadedTo;
|
||||||
data.append('uploaded_to', uploadedTo);
|
data.append('uploaded_to', uploadedTo);
|
||||||
});
|
});
|
||||||
if (typeof scope.eventSuccess !== 'undefined') dz.on('success', scope.eventSuccess);
|
if (typeof scope.eventSuccess !== 'undefined') dz.on('success', scope.eventSuccess);
|
||||||
@ -273,7 +273,7 @@ module.exports = function (ngApp, events) {
|
|||||||
|
|
||||||
function tinyMceSetup(editor) {
|
function tinyMceSetup(editor) {
|
||||||
editor.on('ExecCommand change NodeChange ObjectResized', (e) => {
|
editor.on('ExecCommand change NodeChange ObjectResized', (e) => {
|
||||||
var content = editor.getContent();
|
let content = editor.getContent();
|
||||||
$timeout(() => {
|
$timeout(() => {
|
||||||
scope.mceModel = content;
|
scope.mceModel = content;
|
||||||
});
|
});
|
||||||
@ -301,9 +301,9 @@ module.exports = function (ngApp, events) {
|
|||||||
// Custom tinyMCE plugins
|
// Custom tinyMCE plugins
|
||||||
tinymce.PluginManager.add('customhr', function (editor) {
|
tinymce.PluginManager.add('customhr', function (editor) {
|
||||||
editor.addCommand('InsertHorizontalRule', function () {
|
editor.addCommand('InsertHorizontalRule', function () {
|
||||||
var hrElem = document.createElement('hr');
|
let hrElem = document.createElement('hr');
|
||||||
var cNode = editor.selection.getNode();
|
let cNode = editor.selection.getNode();
|
||||||
var parentNode = cNode.parentNode;
|
let parentNode = cNode.parentNode;
|
||||||
parentNode.insertBefore(hrElem, cNode);
|
parentNode.insertBefore(hrElem, cNode);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -474,9 +474,9 @@ module.exports = function (ngApp, events) {
|
|||||||
function editorPaste(e) {
|
function editorPaste(e) {
|
||||||
e = e.originalEvent;
|
e = e.originalEvent;
|
||||||
if (!e.clipboardData) return
|
if (!e.clipboardData) return
|
||||||
var items = e.clipboardData.items;
|
let items = e.clipboardData.items;
|
||||||
if (!items) return;
|
if (!items) return;
|
||||||
for (var i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
uploadImage(items[i].getAsFile());
|
uploadImage(items[i].getAsFile());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -498,12 +498,12 @@ module.exports = function (ngApp, events) {
|
|||||||
// Handle image upload and add image into markdown content
|
// Handle image upload and add image into markdown content
|
||||||
function uploadImage(file) {
|
function uploadImage(file) {
|
||||||
if (file.type.indexOf('image') !== 0) return;
|
if (file.type.indexOf('image') !== 0) return;
|
||||||
var formData = new FormData();
|
let formData = new FormData();
|
||||||
var ext = 'png';
|
let ext = 'png';
|
||||||
var xhr = new XMLHttpRequest();
|
let xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
if (file.name) {
|
if (file.name) {
|
||||||
var fileNameMatches = file.name.match(/\.(.+)$/);
|
let fileNameMatches = file.name.match(/\.(.+)$/);
|
||||||
if (fileNameMatches) {
|
if (fileNameMatches) {
|
||||||
ext = fileNameMatches[1];
|
ext = fileNameMatches[1];
|
||||||
}
|
}
|
||||||
@ -531,7 +531,7 @@ module.exports = function (ngApp, events) {
|
|||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
let selectStart = input[0].selectionStart;
|
let selectStart = input[0].selectionStart;
|
||||||
if (xhr.status === 200 || xhr.status === 201) {
|
if (xhr.status === 200 || xhr.status === 201) {
|
||||||
var result = JSON.parse(xhr.responseText);
|
let result = JSON.parse(xhr.responseText);
|
||||||
input[0].value = input[0].value.replace(placeholderImage, result.thumbs.display);
|
input[0].value = input[0].value.replace(placeholderImage, result.thumbs.display);
|
||||||
input.change();
|
input.change();
|
||||||
} else {
|
} else {
|
||||||
@ -732,14 +732,13 @@ module.exports = function (ngApp, events) {
|
|||||||
// Build suggestions
|
// Build suggestions
|
||||||
$suggestionBox[0].innerHTML = '';
|
$suggestionBox[0].innerHTML = '';
|
||||||
for (let i = 0; i < suggestions.length; i++) {
|
for (let i = 0; i < suggestions.length; i++) {
|
||||||
var suggestion = document.createElement('li');
|
let suggestion = document.createElement('li');
|
||||||
suggestion.textContent = suggestions[i];
|
suggestion.textContent = suggestions[i];
|
||||||
suggestion.onclick = suggestionClick;
|
suggestion.onclick = suggestionClick;
|
||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
suggestion.className = 'active'
|
suggestion.className = 'active';
|
||||||
active = 0;
|
active = 0;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
$suggestionBox[0].appendChild(suggestion);
|
$suggestionBox[0].appendChild(suggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -748,12 +747,11 @@ module.exports = function (ngApp, events) {
|
|||||||
|
|
||||||
// Suggestion click event
|
// Suggestion click event
|
||||||
function suggestionClick(event) {
|
function suggestionClick(event) {
|
||||||
let text = this.textContent;
|
currentInput[0].value = this.textContent;
|
||||||
currentInput[0].value = text;
|
|
||||||
currentInput.focus();
|
currentInput.focus();
|
||||||
$suggestionBox.hide();
|
$suggestionBox.hide();
|
||||||
isShowing = false;
|
isShowing = false;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Get suggestions & cache
|
// Get suggestions & cache
|
||||||
function getSuggestions(input, url) {
|
function getSuggestions(input, url) {
|
||||||
@ -843,7 +841,7 @@ module.exports = function (ngApp, events) {
|
|||||||
const input = element.find('[entity-selector-input]').first();
|
const input = element.find('[entity-selector-input]').first();
|
||||||
|
|
||||||
// Detect double click events
|
// Detect double click events
|
||||||
var lastClick = 0;
|
let lastClick = 0;
|
||||||
function isDoubleClick() {
|
function isDoubleClick() {
|
||||||
let now = Date.now();
|
let now = Date.now();
|
||||||
let answer = now - lastClick < 300;
|
let answer = now - lastClick < 300;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// AngularJS - Create application and load components
|
// AngularJS - Create application and load components
|
||||||
var angular = require('angular');
|
import angular from "angular";
|
||||||
var ngResource = require('angular-resource');
|
import "angular-resource";
|
||||||
var ngAnimate = require('angular-animate');
|
import "angular-animate";
|
||||||
var ngSanitize = require('angular-sanitize');
|
import "angular-sanitize";
|
||||||
require('angular-ui-sortable');
|
import "angular-ui-sortable";
|
||||||
|
|
||||||
// Url retrieval function
|
// Url retrieval function
|
||||||
window.baseUrl = function(path) {
|
window.baseUrl = function(path) {
|
||||||
@ -15,7 +15,7 @@ window.baseUrl = function(path) {
|
|||||||
return basePath + '/' + path;
|
return basePath + '/' + path;
|
||||||
};
|
};
|
||||||
|
|
||||||
var ngApp = angular.module('bookStack', ['ngResource', 'ngAnimate', 'ngSanitize', 'ui.sortable']);
|
let ngApp = angular.module('bookStack', ['ngResource', 'ngAnimate', 'ngSanitize', 'ui.sortable']);
|
||||||
|
|
||||||
// Global Event System
|
// Global Event System
|
||||||
class EventManager {
|
class EventManager {
|
||||||
@ -25,9 +25,9 @@ class EventManager {
|
|||||||
|
|
||||||
emit(eventName, eventData) {
|
emit(eventName, eventData) {
|
||||||
if (typeof this.listeners[eventName] === 'undefined') return this;
|
if (typeof this.listeners[eventName] === 'undefined') return this;
|
||||||
var eventsToStart = this.listeners[eventName];
|
let eventsToStart = this.listeners[eventName];
|
||||||
for (let i = 0; i < eventsToStart.length; i++) {
|
for (let i = 0; i < eventsToStart.length; i++) {
|
||||||
var event = eventsToStart[i];
|
let event = eventsToStart[i];
|
||||||
event(eventData);
|
event(eventData);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@ -72,10 +72,10 @@ jQuery.expr[":"].contains = $.expr.createPseudo(function (arg) {
|
|||||||
// Global jQuery Elements
|
// Global jQuery Elements
|
||||||
$(function () {
|
$(function () {
|
||||||
|
|
||||||
var notifications = $('.notification');
|
let notifications = $('.notification');
|
||||||
var successNotification = notifications.filter('.pos');
|
let successNotification = notifications.filter('.pos');
|
||||||
var errorNotification = notifications.filter('.neg');
|
let errorNotification = notifications.filter('.neg');
|
||||||
var warningNotification = notifications.filter('.warning');
|
let warningNotification = notifications.filter('.warning');
|
||||||
// Notification Events
|
// Notification Events
|
||||||
window.Events.listen('success', function (text) {
|
window.Events.listen('success', function (text) {
|
||||||
successNotification.hide();
|
successNotification.hide();
|
||||||
@ -109,9 +109,9 @@ $(function () {
|
|||||||
$('#back-to-top').click(function() {
|
$('#back-to-top').click(function() {
|
||||||
$('#header').smoothScrollTo();
|
$('#header').smoothScrollTo();
|
||||||
});
|
});
|
||||||
var scrollTopShowing = false;
|
let scrollTopShowing = false;
|
||||||
var scrollTop = document.getElementById('back-to-top');
|
let scrollTop = document.getElementById('back-to-top');
|
||||||
var scrollTopBreakpoint = 1200;
|
let scrollTopBreakpoint = 1200;
|
||||||
window.addEventListener('scroll', function() {
|
window.addEventListener('scroll', function() {
|
||||||
let scrollTopPos = document.documentElement.scrollTop || document.body.scrollTop || 0;
|
let scrollTopPos = document.documentElement.scrollTop || document.body.scrollTop || 0;
|
||||||
if (!scrollTopShowing && scrollTopPos > scrollTopBreakpoint) {
|
if (!scrollTopShowing && scrollTopPos > scrollTopBreakpoint) {
|
||||||
@ -159,4 +159,4 @@ $(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Page specific items
|
// Page specific items
|
||||||
require('./pages/page-show');
|
import "./pages/page-show";
|
||||||
|
@ -60,108 +60,108 @@ function registerEditorShortcuts(editor) {
|
|||||||
editor.addShortcut('meta+shift+E', '', ['FormatBlock', false, 'code']);
|
editor.addShortcut('meta+shift+E', '', ['FormatBlock', false, 'code']);
|
||||||
}
|
}
|
||||||
|
|
||||||
var mceOptions = module.exports = {
|
export default function() {
|
||||||
selector: '#html-editor',
|
let settings = {
|
||||||
content_css: [
|
selector: '#html-editor',
|
||||||
window.baseUrl('/css/styles.css'),
|
content_css: [
|
||||||
window.baseUrl('/libs/material-design-iconic-font/css/material-design-iconic-font.min.css')
|
window.baseUrl('/css/styles.css'),
|
||||||
],
|
window.baseUrl('/libs/material-design-iconic-font/css/material-design-iconic-font.min.css')
|
||||||
body_class: 'page-content',
|
],
|
||||||
relative_urls: false,
|
body_class: 'page-content',
|
||||||
remove_script_host: false,
|
relative_urls: false,
|
||||||
document_base_url: window.baseUrl('/'),
|
remove_script_host: false,
|
||||||
statusbar: false,
|
document_base_url: window.baseUrl('/'),
|
||||||
menubar: false,
|
statusbar: false,
|
||||||
paste_data_images: false,
|
menubar: false,
|
||||||
extended_valid_elements: 'pre[*]',
|
paste_data_images: false,
|
||||||
automatic_uploads: false,
|
extended_valid_elements: 'pre[*]',
|
||||||
valid_children: "-div[p|pre|h1|h2|h3|h4|h5|h6|blockquote]",
|
automatic_uploads: false,
|
||||||
plugins: "image table textcolor paste link fullscreen imagetools code customhr autosave lists",
|
valid_children: "-div[p|pre|h1|h2|h3|h4|h5|h6|blockquote]",
|
||||||
imagetools_toolbar: 'imageoptions',
|
plugins: "image table textcolor paste link fullscreen imagetools code customhr autosave lists",
|
||||||
toolbar: "undo redo | styleselect | bold italic underline strikethrough superscript subscript | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table image-insert link hr | removeformat code fullscreen",
|
imagetools_toolbar: 'imageoptions',
|
||||||
content_style: "body {padding-left: 15px !important; padding-right: 15px !important; margin:0!important; margin-left:auto!important;margin-right:auto!important;}",
|
toolbar: "undo redo | styleselect | bold italic underline strikethrough superscript subscript | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table image-insert link hr | removeformat code fullscreen",
|
||||||
style_formats: [
|
content_style: "body {padding-left: 15px !important; padding-right: 15px !important; margin:0!important; margin-left:auto!important;margin-right:auto!important;}",
|
||||||
{title: "Header Large", format: "h2"},
|
style_formats: [
|
||||||
{title: "Header Medium", format: "h3"},
|
{title: "Header Large", format: "h2"},
|
||||||
{title: "Header Small", format: "h4"},
|
{title: "Header Medium", format: "h3"},
|
||||||
{title: "Header Tiny", format: "h5"},
|
{title: "Header Small", format: "h4"},
|
||||||
{title: "Paragraph", format: "p", exact: true, classes: ''},
|
{title: "Header Tiny", format: "h5"},
|
||||||
{title: "Blockquote", format: "blockquote"},
|
{title: "Paragraph", format: "p", exact: true, classes: ''},
|
||||||
{title: "Code Block", icon: "code", format: "pre"},
|
{title: "Blockquote", format: "blockquote"},
|
||||||
{title: "Inline Code", icon: "code", inline: "code"},
|
{title: "Code Block", icon: "code", format: "pre"},
|
||||||
{title: "Callouts", items: [
|
{title: "Inline Code", icon: "code", inline: "code"},
|
||||||
{title: "Success", block: 'p', exact: true, attributes : {'class' : 'callout success'}},
|
{title: "Callouts", items: [
|
||||||
{title: "Info", block: 'p', exact: true, attributes : {'class' : 'callout info'}},
|
{title: "Success", block: 'p', exact: true, attributes : {'class' : 'callout success'}},
|
||||||
{title: "Warning", block: 'p', exact: true, attributes : {'class' : 'callout warning'}},
|
{title: "Info", block: 'p', exact: true, attributes : {'class' : 'callout info'}},
|
||||||
{title: "Danger", block: 'p', exact: true, attributes : {'class' : 'callout danger'}}
|
{title: "Warning", block: 'p', exact: true, attributes : {'class' : 'callout warning'}},
|
||||||
]}
|
{title: "Danger", block: 'p', exact: true, attributes : {'class' : 'callout danger'}}
|
||||||
],
|
]}
|
||||||
style_formats_merge: false,
|
],
|
||||||
formats: {
|
style_formats_merge: false,
|
||||||
alignleft: {selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'align-left'},
|
formats: {
|
||||||
aligncenter: {selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'align-center'},
|
alignleft: {selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'align-left'},
|
||||||
alignright: {selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'align-right'},
|
aligncenter: {selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'align-center'},
|
||||||
},
|
alignright: {selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'align-right'},
|
||||||
file_browser_callback: function (field_name, url, type, win) {
|
},
|
||||||
|
file_browser_callback: function (field_name, url, type, win) {
|
||||||
|
|
||||||
if (type === 'file') {
|
if (type === 'file') {
|
||||||
window.showEntityLinkSelector(function(entity) {
|
window.showEntityLinkSelector(function(entity) {
|
||||||
let originalField = win.document.getElementById(field_name);
|
let originalField = win.document.getElementById(field_name);
|
||||||
originalField.value = entity.link;
|
originalField.value = entity.link;
|
||||||
$(originalField).closest('.mce-form').find('input').eq(2).val(entity.name);
|
$(originalField).closest('.mce-form').find('input').eq(2).val(entity.name);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'image') {
|
if (type === 'image') {
|
||||||
// Show image manager
|
// Show image manager
|
||||||
window.ImageManager.showExternal(function (image) {
|
window.ImageManager.showExternal(function (image) {
|
||||||
|
|
||||||
// Set popover link input to image url then fire change event
|
// Set popover link input to image url then fire change event
|
||||||
// to ensure the new value sticks
|
// to ensure the new value sticks
|
||||||
win.document.getElementById(field_name).value = image.url;
|
win.document.getElementById(field_name).value = image.url;
|
||||||
if ("createEvent" in document) {
|
if ("createEvent" in document) {
|
||||||
let evt = document.createEvent("HTMLEvents");
|
let evt = document.createEvent("HTMLEvents");
|
||||||
evt.initEvent("change", false, true);
|
evt.initEvent("change", false, true);
|
||||||
win.document.getElementById(field_name).dispatchEvent(evt);
|
win.document.getElementById(field_name).dispatchEvent(evt);
|
||||||
} else {
|
} else {
|
||||||
win.document.getElementById(field_name).fireEvent("onchange");
|
win.document.getElementById(field_name).fireEvent("onchange");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace the actively selected content with the linked image
|
// Replace the actively selected content with the linked image
|
||||||
let html = `<a href="${image.url}" target="_blank">`;
|
let html = `<a href="${image.url}" target="_blank">`;
|
||||||
html += `<img src="${image.thumbs.display}" alt="${image.name}">`;
|
html += `<img src="${image.thumbs.display}" alt="${image.name}">`;
|
||||||
html += '</a>';
|
html += '</a>';
|
||||||
win.tinyMCE.activeEditor.execCommand('mceInsertContent', false, html);
|
win.tinyMCE.activeEditor.execCommand('mceInsertContent', false, html);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
paste_preprocess: function (plugin, args) {
|
paste_preprocess: function (plugin, args) {
|
||||||
let content = args.content;
|
let content = args.content;
|
||||||
if (content.indexOf('<img src="file://') !== -1) {
|
if (content.indexOf('<img src="file://') !== -1) {
|
||||||
args.content = '';
|
args.content = '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
extraSetups: [],
|
extraSetups: [],
|
||||||
setup: function (editor) {
|
setup: function (editor) {
|
||||||
|
|
||||||
// Run additional setup actions
|
// Run additional setup actions
|
||||||
// Used by the angular side of things
|
// Used by the angular side of things
|
||||||
for (let i = 0; i < mceOptions.extraSetups.length; i++) {
|
for (let i = 0; i < settings.extraSetups.length; i++) {
|
||||||
mceOptions.extraSetups[i](editor);
|
settings.extraSetups[i](editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
registerEditorShortcuts(editor);
|
registerEditorShortcuts(editor);
|
||||||
|
|
||||||
(function () {
|
let wrap;
|
||||||
var wrap;
|
|
||||||
|
|
||||||
function hasTextContent(node) {
|
function hasTextContent(node) {
|
||||||
return node && !!( node.textContent || node.innerText );
|
return node && !!( node.textContent || node.innerText );
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.on('dragstart', function () {
|
editor.on('dragstart', function () {
|
||||||
var node = editor.selection.getNode();
|
let node = editor.selection.getNode();
|
||||||
|
|
||||||
if (node.nodeName !== 'IMG') return;
|
if (node.nodeName !== 'IMG') return;
|
||||||
wrap = editor.dom.getParent(node, '.mceTemp');
|
wrap = editor.dom.getParent(node, '.mceTemp');
|
||||||
@ -172,7 +172,7 @@ var mceOptions = module.exports = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
editor.on('drop', function (event) {
|
editor.on('drop', function (event) {
|
||||||
var dom = editor.dom,
|
let dom = editor.dom,
|
||||||
rng = tinymce.dom.RangeUtils.getCaretRangeFromPoint(event.clientX, event.clientY, editor.getDoc());
|
rng = tinymce.dom.RangeUtils.getCaretRangeFromPoint(event.clientX, event.clientY, editor.getDoc());
|
||||||
|
|
||||||
// Don't allow anything to be dropped in a captioned image.
|
// Don't allow anything to be dropped in a captioned image.
|
||||||
@ -190,26 +190,27 @@ var mceOptions = module.exports = {
|
|||||||
|
|
||||||
wrap = null;
|
wrap = null;
|
||||||
});
|
});
|
||||||
})();
|
|
||||||
|
|
||||||
// Custom Image picker button
|
// Custom Image picker button
|
||||||
editor.addButton('image-insert', {
|
editor.addButton('image-insert', {
|
||||||
title: 'My title',
|
title: 'My title',
|
||||||
icon: 'image',
|
icon: 'image',
|
||||||
tooltip: 'Insert an image',
|
tooltip: 'Insert an image',
|
||||||
onclick: function () {
|
onclick: function () {
|
||||||
window.ImageManager.showExternal(function (image) {
|
window.ImageManager.showExternal(function (image) {
|
||||||
let html = `<a href="${image.url}" target="_blank">`;
|
let html = `<a href="${image.url}" target="_blank">`;
|
||||||
html += `<img src="${image.thumbs.display}" alt="${image.name}">`;
|
html += `<img src="${image.thumbs.display}" alt="${image.name}">`;
|
||||||
html += '</a>';
|
html += '</a>';
|
||||||
editor.execCommand('mceInsertContent', false, html);
|
editor.execCommand('mceInsertContent', false, html);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Paste image-uploads
|
// Paste image-uploads
|
||||||
editor.on('paste', function(event) {
|
editor.on('paste', function(event) {
|
||||||
editorPaste(event, editor);
|
editorPaste(event, editor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
return settings;
|
||||||
|
}
|
@ -1,16 +1,13 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
// Configure ZeroClipboard
|
// Configure ZeroClipboard
|
||||||
var zeroClipBoard = require('zeroclipboard');
|
import zeroClipBoard from "zeroclipboard";
|
||||||
zeroClipBoard.config({
|
|
||||||
swfPath: window.baseUrl('/ZeroClipboard.swf')
|
|
||||||
});
|
|
||||||
|
|
||||||
window.setupPageShow = module.exports = function (pageId) {
|
export default window.setupPageShow = function (pageId) {
|
||||||
|
|
||||||
// Set up pointer
|
// Set up pointer
|
||||||
var $pointer = $('#pointer').detach();
|
let $pointer = $('#pointer').detach();
|
||||||
var $pointerInner = $pointer.children('div.pointer').first();
|
let $pointerInner = $pointer.children('div.pointer').first();
|
||||||
var isSelection = false;
|
let isSelection = false;
|
||||||
|
|
||||||
// Select all contents on input click
|
// Select all contents on input click
|
||||||
$pointer.on('click', 'input', function (e) {
|
$pointer.on('click', 'input', function (e) {
|
||||||
@ -19,6 +16,9 @@ window.setupPageShow = module.exports = function (pageId) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Set up copy-to-clipboard
|
// Set up copy-to-clipboard
|
||||||
|
zeroClipBoard.config({
|
||||||
|
swfPath: window.baseUrl('/ZeroClipboard.swf')
|
||||||
|
});
|
||||||
new zeroClipBoard($pointer.find('button').first()[0]);
|
new zeroClipBoard($pointer.find('button').first()[0]);
|
||||||
|
|
||||||
// Hide pointer when clicking away
|
// Hide pointer when clicking away
|
||||||
@ -31,11 +31,11 @@ window.setupPageShow = module.exports = function (pageId) {
|
|||||||
// Show pointer when selecting a single block of tagged content
|
// Show pointer when selecting a single block of tagged content
|
||||||
$('.page-content [id^="bkmrk"]').on('mouseup keyup', function (e) {
|
$('.page-content [id^="bkmrk"]').on('mouseup keyup', function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
var selection = window.getSelection();
|
let selection = window.getSelection();
|
||||||
if (selection.toString().length === 0) return;
|
if (selection.toString().length === 0) return;
|
||||||
|
|
||||||
// Show pointer and set link
|
// Show pointer and set link
|
||||||
var $elem = $(this);
|
let $elem = $(this);
|
||||||
let link = window.baseUrl('/link/' + pageId + '#' + $elem.attr('id'));
|
let link = window.baseUrl('/link/' + pageId + '#' + $elem.attr('id'));
|
||||||
if (link.indexOf('http') !== 0) link = window.location.protocol + "//" + window.location.host + link;
|
if (link.indexOf('http') !== 0) link = window.location.protocol + "//" + window.location.host + link;
|
||||||
$pointer.find('input').val(link);
|
$pointer.find('input').val(link);
|
||||||
@ -44,9 +44,9 @@ window.setupPageShow = module.exports = function (pageId) {
|
|||||||
$pointer.show();
|
$pointer.show();
|
||||||
|
|
||||||
// Set pointer to sit near mouse-up position
|
// Set pointer to sit near mouse-up position
|
||||||
var pointerLeftOffset = (e.pageX - $elem.offset().left - ($pointerInner.width() / 2));
|
let pointerLeftOffset = (e.pageX - $elem.offset().left - ($pointerInner.width() / 2));
|
||||||
if (pointerLeftOffset < 0) pointerLeftOffset = 0;
|
if (pointerLeftOffset < 0) pointerLeftOffset = 0;
|
||||||
var pointerLeftOffsetPercent = (pointerLeftOffset / $elem.width()) * 100;
|
let pointerLeftOffsetPercent = (pointerLeftOffset / $elem.width()) * 100;
|
||||||
$pointerInner.css('left', pointerLeftOffsetPercent + '%');
|
$pointerInner.css('left', pointerLeftOffsetPercent + '%');
|
||||||
|
|
||||||
isSelection = true;
|
isSelection = true;
|
||||||
@ -57,7 +57,7 @@ window.setupPageShow = module.exports = function (pageId) {
|
|||||||
|
|
||||||
// Go to, and highlight if necessary, the specified text.
|
// Go to, and highlight if necessary, the specified text.
|
||||||
function goToText(text) {
|
function goToText(text) {
|
||||||
var idElem = $('.page-content #' + text).first();
|
let idElem = $('.page-content #' + text).first();
|
||||||
if (idElem.length !== 0) {
|
if (idElem.length !== 0) {
|
||||||
idElem.smoothScrollTo();
|
idElem.smoothScrollTo();
|
||||||
idElem.css('background-color', 'rgba(244, 249, 54, 0.25)');
|
idElem.css('background-color', 'rgba(244, 249, 54, 0.25)');
|
||||||
@ -68,19 +68,19 @@ window.setupPageShow = module.exports = function (pageId) {
|
|||||||
|
|
||||||
// Check the hash on load
|
// Check the hash on load
|
||||||
if (window.location.hash) {
|
if (window.location.hash) {
|
||||||
var text = window.location.hash.replace(/\%20/g, ' ').substr(1);
|
let text = window.location.hash.replace(/\%20/g, ' ').substr(1);
|
||||||
goToText(text);
|
goToText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the book-tree sidebar stick in view on scroll
|
// Make the book-tree sidebar stick in view on scroll
|
||||||
var $window = $(window);
|
let $window = $(window);
|
||||||
var $bookTree = $(".book-tree");
|
let $bookTree = $(".book-tree");
|
||||||
var $bookTreeParent = $bookTree.parent();
|
let $bookTreeParent = $bookTree.parent();
|
||||||
// Check the page is scrollable and the content is taller than the tree
|
// Check the page is scrollable and the content is taller than the tree
|
||||||
var pageScrollable = ($(document).height() > $window.height()) && ($bookTree.height() < $('.page-content').height());
|
let pageScrollable = ($(document).height() > $window.height()) && ($bookTree.height() < $('.page-content').height());
|
||||||
// Get current tree's width and header height
|
// Get current tree's width and header height
|
||||||
var headerHeight = $("#header").height() + $(".toolbar").height();
|
let headerHeight = $("#header").height() + $(".toolbar").height();
|
||||||
var isFixed = $window.scrollTop() > headerHeight;
|
let isFixed = $window.scrollTop() > headerHeight;
|
||||||
// Function to fix the tree as a sidebar
|
// Function to fix the tree as a sidebar
|
||||||
function stickTree() {
|
function stickTree() {
|
||||||
$bookTree.width($bookTreeParent.width() + 15);
|
$bookTree.width($bookTreeParent.width() + 15);
|
||||||
@ -95,7 +95,7 @@ window.setupPageShow = module.exports = function (pageId) {
|
|||||||
}
|
}
|
||||||
// Checks if the tree stickiness state should change
|
// Checks if the tree stickiness state should change
|
||||||
function checkTreeStickiness(skipCheck) {
|
function checkTreeStickiness(skipCheck) {
|
||||||
var shouldBeFixed = $window.scrollTop() > headerHeight;
|
let shouldBeFixed = $window.scrollTop() > headerHeight;
|
||||||
if (shouldBeFixed && (!isFixed || skipCheck)) {
|
if (shouldBeFixed && (!isFixed || skipCheck)) {
|
||||||
stickTree();
|
stickTree();
|
||||||
} else if (!shouldBeFixed && (isFixed || skipCheck)) {
|
} else if (!shouldBeFixed && (isFixed || skipCheck)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user