diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..5b40d15 --- /dev/null +++ b/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + "es2015" + ] +} diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..ebe8686 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,70 @@ +{ + "env": { + "browser": true, + "es6": true + }, + + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, + + "globals": { + "tinymce": true + }, + + "rules": { + "camelcase": 0, + "strict": 0, + "eqeqeq": 0, + "no-underscore-dangle": 0, + "consistent-return": 0, + "no-shadow": 0, + "no-use-before-define": 0, + "brace-style": [2, "1tbs"], + "guard-for-in": 0, + "no-floating-decimal": 2, + "no-nested-ternary": 2, + "radix": 2, + "wrap-iife": [2, "inside"], + "consistent-this": [2, "self"], + "no-bitwise": 2, + "max-depth": [1, 8], + "max-statements": [2, 150], + "max-len": [1, 140, 4], + "eol-last": 0, + "quotes": 0, + "no-trailing-spaces": 2, + "comma-spacing": [2, {"before": false, "after": true}], + "comma-dangle": ["error", "never"], + "space-in-parens": [2, "never"], + "space-infix-ops": [2, {"int32Hint": false}], + "space-before-function-paren": ["error", { + "anonymous": "always", + "named": "never", + "asyncArrow": "ignore" + }], + "object-curly-spacing": ["error", "always"], + "no-mixed-spaces-and-tabs": "error", + "keyword-spacing": 2, + "space-unary-ops": [1, { "words": true, "nonwords": false }], + "space-before-blocks": [2, "always"], + "no-multiple-empty-lines": [1, {"max": 2}], + "operator-linebreak": [2, "after"], + "semi": [2, "always"], + "indent": ["error", 2, {"SwitchCase": 1}], + "curly": [2, "all"], + "dot-notation": [2, {"allowKeywords": false}], + "no-else-return": 0, + "no-eval": 2, + "no-implied-eval": 2, + "no-loop-func": 2, + "no-multi-str": 2, + "no-multi-spaces": 2, + "no-sequences": 2, + "no-new": 2, + "no-caller": 2 + }, + + "extends": "eslint:recommended" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..07205fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules +*.log +dist +.DS_Store +yarn.lock diff --git a/README.md b/README.md new file mode 100644 index 0000000..cc22e26 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# tinymceEmoji TinyMCE Plugin + +Welcome stranger! This is a repo containing the tinymceEmoji TinyMCE plugin. + +## The development server + +By running the `npm start` command you start the development server and open a browser window with an instance of TinyMCE with your plugin added to it. This window will reload automatically whenever a change is detected in the `index.html` file in the `static` folder or in one of the JavaScript files in the `src` directory. + +## The production build + +By running the `npm run build` command Webpack will create a `dist` directory with a child directory with the name of your plugin (tinymce-emoji) containing three files: + +* `plugin.js` - the bundled plugin +* `plugin.min.js` - the bundles, uglified and minified plugin +* `LICENSE` - a file explaining the license of your plugin (copied over from `src/LICENSE`) diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js new file mode 100644 index 0000000..8a8f8ec --- /dev/null +++ b/config/webpack.config.dev.js @@ -0,0 +1,20 @@ +var HtmlWebpackPlugin = require('html-webpack-plugin') + +module.exports = { + entry: './src/index.js', + module: { + rules: [ + { + test: /\.js$/, + exclude: /node_modules/, + use: 'babel-loader' + } + ] + }, + plugins: [ + new HtmlWebpackPlugin({ + inject: true, + template: './static/index.html' + }) + ] +} diff --git a/config/webpack.config.prod.js b/config/webpack.config.prod.js new file mode 100644 index 0000000..0c638d1 --- /dev/null +++ b/config/webpack.config.prod.js @@ -0,0 +1,37 @@ +const path = require('path') +const webpack = require('webpack') +const CopyWebpackPlugin = require('copy-webpack-plugin') + +const pluginName = 'tinymce-emoji' + +module.exports = { + entry: { + 'plugin': './src/index.js', + 'plugin.min': './src/index.js' + }, + output: { + path: path.join(__dirname, '../dist', pluginName), + filename: '[name].js' + }, + module: { + rules: [ + { + test: /\.js$/, + exclude: /node_modules/, + use: 'babel-loader' + } + ] + }, + plugins: [ + new webpack.optimize.UglifyJsPlugin({ + include: /\.min\.js$/, + minimize: true + }), + new CopyWebpackPlugin([ + { + from: path.join(__dirname, '../src/LICENSE'), + to: path.join(__dirname, '../dist', pluginName) + } + ]) + ] +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..9654200 --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "tinymce-emoji", + "version": "0.0.1", + "description": "tinymceEmoji TinyMCE plugin repo", + "scripts": { + "start": "webpack-dev-server --config config/webpack.config.dev.js --progress --open --inline", + "lint": "eslint 'src/**/*.js'", + "build": "webpack --config config/webpack.config.prod.js --progress" + }, + "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" + }, + "dependencies": { + "lodash": "^4.17.4" + }, + "license": "MIT" +} diff --git a/src/LICENSE b/src/LICENSE new file mode 100644 index 0000000..3d26aae --- /dev/null +++ b/src/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 Josh Johnson (geekjosh.co.uk) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..9170685 --- /dev/null +++ b/src/index.js @@ -0,0 +1,3 @@ +import plugin from './plugin'; + +tinymce.PluginManager.add('tinymceEmoji', plugin); diff --git a/src/plugin.js b/src/plugin.js new file mode 100644 index 0000000..d1f2216 --- /dev/null +++ b/src/plugin.js @@ -0,0 +1,24 @@ +import _ from 'lodash'; + +const plugin = (editor) => { + editor.addButton('tinymceEmoji', { + text: 'tinymceEmoji', + icon: false, + onclick: () => { + // Open window + editor.windowManager.open({ + title: 'tinymceEmoji plugin', + body: [ + { type: 'textbox', name: 'title' } + ], + onsubmit(e) { + // Insert content when the window form is submitted + const kebabbyString = _.kebabCase(e.data.title); + editor.insertContent(kebabbyString); + } + }); + } + }); +}; + +export default plugin; diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..c6d5cf2 --- /dev/null +++ b/static/index.html @@ -0,0 +1,16 @@ + + + + + + + + + +