Skip to content

Commit

Permalink
supports TinyMCE 5
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtnovack committed May 24, 2019
1 parent 9c62770 commit 4f541fb
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 116 deletions.
5 changes: 0 additions & 5 deletions .babelrc

This file was deleted.

15 changes: 10 additions & 5 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
var HtmlWebpackPlugin = require('html-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: './src/index.js',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
Expand All @@ -17,4 +22,4 @@ module.exports = {
template: './static/index.html'
})
]
}
};
43 changes: 30 additions & 13 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const path = require('path')
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

const pluginName = 'stickytoolbar'
const pluginName = 'stickytoolbar';

module.exports = {
entry: {
Expand All @@ -16,22 +17,38 @@ module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
include: /\.min\.js$/,
minimize: true
}),
new CopyWebpackPlugin([
{
from: path.join(__dirname, '../src/LICENSE'),
to: path.join(__dirname, '../dist', pluginName)
}
])
]
}
],
optimization: {
minimizer: [
new UglifyJsPlugin({
test: /\.min\.js$/,
cache: true,
parallel: true,
uglifyOptions: {
compress: false,
ecma: 5,
mangle: true
},
sourceMap: true
})
]
}
};
134 changes: 76 additions & 58 deletions dist/stickytoolbar/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,35 @@
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
Expand All @@ -62,65 +79,78 @@
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);


Object.defineProperty(exports, "__esModule", {
value: true
});
var plugin = function plugin(editor) {
// CONCATENATED MODULE: ./src/plugin.js
var plugin_plugin = function plugin(editor) {
var offset = editor.settings.sticky_offset ? editor.settings.sticky_offset : 0;

editor.on('init', function () {
setTimeout(function () {
setSticky();
}, 0);
});
window.addEventListener('resize', function () {
setSticky();
});

window.addEventListener('scroll', function () {
setSticky();
});

function setSticky() {
var container = editor.getContainer();
var toolbars = container.querySelectorAll('.tox-menubar, .tox-toolbar');
var toolbarHeights = 0;
toolbars.forEach(function (toolbar) {
toolbarHeights += toolbar.offsetHeight;
});

if (!editor.inline && container && container.offsetParent) {

var statusbar = '';

if (editor.settings.statusbar !== false) {
statusbar = container.querySelector('.mce-statusbar');
statusbar = container.querySelector('.tox-statusbar');
}

var topPart = container.querySelector('.mce-top-part');

if (isSticky()) {
container.style.paddingTop = topPart.offsetHeight + 'px';
container.style.paddingTop = "".concat(toolbarHeights, "px");

if (isAtBottom()) {
topPart.style.top = null;
topPart.style.width = '100%';
topPart.style.position = 'absolute';
topPart.style.bottom = statusbar ? statusbar.offsetHeight + 'px' : 0;
var nextToolbarHeight = 0;
var toolbarsArray = [].slice.call(toolbars).reverse();
toolbarsArray.forEach(function (toolbar) {
toolbar.style.top = null;
toolbar.style.width = '100%';
toolbar.style.position = 'absolute';
toolbar.style.bottom = statusbar ? "".concat(statusbar.offsetHeight + nextToolbarHeight, "px") : 0;
toolbar.style.zIndex = 1;
nextToolbarHeight = toolbar.offsetHeight;
});
} else {
topPart.style.bottom = null;
topPart.style.top = offset + 'px';
topPart.style.position = 'fixed';
topPart.style.width = container.clientWidth + 'px';
var prevToolbarHeight = 0;
toolbars.forEach(function (toolbar) {
toolbar.style.bottom = null;
toolbar.style.top = "".concat(offset + prevToolbarHeight, "px");
toolbar.style.position = 'fixed';
toolbar.style.width = "".concat(container.clientWidth, "px");
toolbar.style.zIndex = 1;
prevToolbarHeight = toolbar.offsetHeight;
});
}
} else {
container.style.paddingTop = 0;

topPart.style.position = 'relative';
topPart.style.top = null;
topPart.style.width = null;
topPart.style.borderBottom = null;
toolbars.forEach(function (toolbar) {
toolbar.style = null;
});
}
}
}
Expand All @@ -137,15 +167,15 @@ var plugin = function plugin(editor) {

function isAtBottom() {
var container = editor.getContainer();

var editorPosition = container.getBoundingClientRect().top,
statusbar = container.querySelector('.mce-statusbar'),
topPart = container.querySelector('.mce-top-part');

var statusbarHeight = statusbar ? statusbar.offsetHeight : 0,
topPartHeight = topPart ? topPart.offsetHeight : 0;

var stickyHeight = -(container.offsetHeight - topPartHeight - statusbarHeight);
statusbar = container.querySelector('.tox-statusbar'),
toolbars = container.querySelectorAll('.tox-menubar, .tox-toolbar');
var statusbarHeight = statusbar ? statusbar.offsetHeight : 0;
var toolbarHeights = 0;
toolbars.forEach(function (toolbar) {
toolbarHeights += toolbar.offsetHeight;
});
var stickyHeight = -(container.offsetHeight - toolbarHeights - statusbarHeight);

if (editorPosition < stickyHeight + offset) {
return true;
Expand All @@ -155,22 +185,10 @@ var plugin = function plugin(editor) {
}
};

exports.default = plugin;

/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";


var _plugin = __webpack_require__(0);

var _plugin2 = _interopRequireDefault(_plugin);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* harmony default export */ var src_plugin = (plugin_plugin);
// CONCATENATED MODULE: ./src/index.js

tinymce.PluginManager.add('stickytoolbar', _plugin2.default);
tinymce.PluginManager.add('stickytoolbar', src_plugin);

/***/ })
/******/ ]);
2 changes: 1 addition & 1 deletion dist/stickytoolbar/plugin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
},
"author": "",
"devDependencies": {
"babel-core": "^6.21.0",
"babel-loader": "^6.2.10",
"babel-preset-es2015": "^6.18.0",
"copy-webpack-plugin": "^4.0.1",
"eslint": "^3.12.2",
"eslint-config-standard": "^6.2.1",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"html-webpack-plugin": "^2.26.0",
"webpack": "^2.2.0",
"webpack-dev-server": "^1.16.2"
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"babel-loader": "^8.0.6",
"copy-webpack-plugin": "^5.0.3",
"eslint": "^5.16.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"html-webpack-plugin": "^3.2.0",
"uglifyjs-webpack-plugin": "^2.1.3",
"webpack": "^4.32.2",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "^3.4.1"
},
"license": "MIT"
}
Loading

0 comments on commit 4f541fb

Please sign in to comment.