Permalink
Browse files

Implements summernote-lite toolbar and editor.

 - move bootstrap 3 modules to bs3 folder.
  • Loading branch information...
1 parent 65b94ee commit 05cdecce08dbaf06b691be3d2e816619d7a2d52a @hackerwins hackerwins committed Aug 27, 2015
View
@@ -1,3 +1,3 @@
-src/js/intro.js
-src/js/outro.js
+src/js/**/intro.js
+src/js/**/outro.js
test/libs/**/*
View
@@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
+ <link rel="stylesheet" href="../dist/summernote.css">
<title>summernote-lite</title>
</head>
<body>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,4 +1,4 @@
-define('summernote/core/async', function () {
+define(function () {
/**
* @class core.async
*
@@ -1,7 +1,7 @@
define([
- 'summernote/core/func',
- 'summernote/core/list',
- 'summernote/core/agent'
+ 'summernote/lite/core/func',
+ 'summernote/lite/core/list',
+ 'summernote/lite/core/agent'
], function (func, list, agent) {
var NBSP_CHAR = String.fromCharCode(160);
@@ -1,4 +1,4 @@
-define('summernote/core/func', function () {
+define(function () {
/**
* @class core.func
*
@@ -1,6 +1,6 @@
define([
- 'summernote/core/list',
- 'summernote/core/func'
+ 'summernote/lite/core/list',
+ 'summernote/lite/core/func'
], function (list, func) {
/**
* @class core.key
@@ -1,4 +1,4 @@
-define(['summernote/core/func'], function (func) {
+define(['summernote/lite/core/func'], function (func) {
/**
* @class core.list
*
@@ -1,8 +1,8 @@
define([
- 'summernote/core/agent',
- 'summernote/core/func',
- 'summernote/core/list',
- 'summernote/core/dom'
+ 'summernote/lite/core/agent',
+ 'summernote/lite/core/func',
+ 'summernote/lite/core/list',
+ 'summernote/lite/core/dom'
], function (agent, func, list, dom) {
var range = (function () {
@@ -1,8 +1,8 @@
define([
- 'summernote/core/list',
- 'summernote/core/func',
- 'summernote/core/dom',
- 'summernote/core/range'
+ 'summernote/lite/core/list',
+ 'summernote/lite/core/func',
+ 'summernote/lite/core/dom',
+ 'summernote/lite/core/range'
], function (list, func, dom, range) {
/**
@@ -1,4 +1,4 @@
-define(['summernote/core/range'], function (range) {
+define(['summernote/lite/core/range'], function (range) {
/**
* @class editing.History
*
@@ -1,8 +1,8 @@
define([
- 'summernote/core/agent',
- 'summernote/core/func',
- 'summernote/core/list',
- 'summernote/core/dom'
+ 'summernote/lite/core/agent',
+ 'summernote/lite/core/func',
+ 'summernote/lite/core/list',
+ 'summernote/lite/core/dom'
], function (agent, func, list, dom) {
/**
* @class editing.Style
@@ -1,5 +1,7 @@
define([
- 'summernote/core/dom', 'summernote/core/range', 'summernote/core/list'
+ 'summernote/lite/core/dom',
+ 'summernote/lite/core/range',
+ 'summernote/lite/core/list'
], function (dom, range, list) {
/**
* @class editing.Table
@@ -1,7 +1,7 @@
define([
- 'summernote/core/dom',
- 'summernote/core/range',
- 'summernote/editing/Bullet'
+ 'summernote/lite/core/dom',
+ 'summernote/lite/core/range',
+ 'summernote/lite/editing/Bullet'
], function (dom, range, Bullet) {
/**
@@ -1,5 +1,5 @@
/**
- * Super simple wysiwyg editor on Bootstrap v@VERSION
+ * Super simple wysiwyg editor v@VERSION
* http://summernote.org/
*
* summernote.js
@@ -1,47 +1,72 @@
define([
- 'summernote/core/agent',
- 'summernote/core/func',
- 'summernote/core/list',
- 'summernote/core/dom',
- 'summernote/core/range',
- 'summernote/core/async',
- 'summernote/editing/History',
- 'summernote/editing/Style',
- 'summernote/editing/Typing',
- 'summernote/editing/Table',
- 'summernote/editing/Bullet'
-], function (agent, func, list, dom, range, async,
- History, Style, Typing, Table, Bullet) {
+ 'summernote/lite/core/agent',
+ 'summernote/lite/core/func',
+ 'summernote/lite/core/list',
+ 'summernote/lite/core/key',
+ 'summernote/lite/core/dom',
+ 'summernote/lite/core/range',
+ 'summernote/lite/core/async',
+ 'summernote/lite/editing/History',
+ 'summernote/lite/editing/Style',
+ 'summernote/lite/editing/Typing',
+ 'summernote/lite/editing/Table',
+ 'summernote/lite/editing/Bullet'
+], function (
+ agent, func, list, key, dom, range, async,
+ History, Style, Typing, Table, Bullet
+) {
var KEY_BOGUS = 'bogus';
/**
* @class Editor
* @param {Summernote} summernote
- * @param {jQuery} $editable
*/
- var Editor = function (summernote, $editable) {
+ var Editor = function (summernote) {
var self = this;
+ var $editable = summernote.layoutInfo.editable;
+
var style = new Style();
var table = new Table();
var typing = new Typing();
var bullet = new Bullet();
var history = new History($editable);
this.initialize = function () {
- $editable.on('keydown', function (e) {
- if (e.keyCode === 13) {
- e.preventDefault();
- self.insertParagraph();
- }
- });
+ var keyMap = summernote.options.keyMap[agent.isMac ? 'mac' : 'pc'];
+ this.bindKeyMap(keyMap, summernote.options);
};
this.destroy = function () {
$editable.off('keydown');
};
+ this.bindKeyMap = function (keyMap, options) {
+ $editable.on('keydown', function (event) {
+ var keys = [];
+
+ if (event.metaKey) { keys.push('CMD'); }
+ if (event.ctrlKey && !event.altKey) { keys.push('CTRL'); }
+ if (event.shiftKey) { keys.push('SHIFT'); }
+
+ var keyName = key.nameFromCode[event.keyCode];
+ if (keyName) {
+ keys.push(keyName);
+ }
+
+ var eventName = keyMap[keys.join('+')];
+ if (eventName) {
+ if (self[eventName]) {
+ self[eventName](options);
+ event.preventDefault();
+ }
+ } else if (key.isEdit(event.keyCode)) {
+ self.afterCommand($editable);
+ }
+ });
+ };
+
/**
* @method createRange
*
@@ -180,16 +205,14 @@ define([
* @method tab
*
* handle tab key
- *
- * @param {Object} options
*/
- this.tab = function (options) {
+ this.tab = function () {
var rng = this.createRange();
if (rng.isCollapsed() && rng.isOnCell()) {
table.tab(rng);
} else {
beforeCommand();
- typing.insertTab($editable, rng, options.tabsize);
+ typing.insertTab($editable, rng, summernote.options.tabSize);
afterCommand();
}
};
@@ -432,21 +455,18 @@ define([
* create link (command)
*
* @param {Object} linkInfo
- * @param {Object} options
*/
- this.createLink = function (linkInfo, options) {
+ this.createLink = function (linkInfo) {
var linkUrl = linkInfo.url;
var linkText = linkInfo.text;
var isNewWindow = linkInfo.isNewWindow;
var rng = linkInfo.range || this.createRange();
var isTextChanged = rng.toString() !== linkText;
- options = options || dom.makeLayoutInfo($editable).editor().data('options');
-
beforeCommand();
- if (options.onCreateLink) {
- linkUrl = options.onCreateLink(linkUrl);
+ if (summernote.options.onCreateLink) {
+ linkUrl = summernote.options.onCreateLink(linkUrl);
}
var anchors = [];
@@ -662,8 +682,6 @@ define([
this.isEmpty = function () {
return dom.isEmpty($editable[0]) || dom.emptyPara === $editable.html();
};
-
- this.initialize();
};
return Editor;
@@ -0,0 +1,32 @@
+define([
+ 'summernote/lite/renderer'
+], function (renderer) {
+
+ var Toolbar = function (summernote) {
+ var self = this;
+
+ var $toolbar = summernote.layoutInfo.toolbar;
+
+ this.initialize = function () {
+ var $bold = renderer.button({
+ name: 'bold'
+ }).build().click(function () {
+ summernote.invoke('editor.bold');
+ });
+
+ var $italic = renderer.button({
+ name: 'italic'
+ }).build().click(function () {
+ summernote.invoke('editor.italic');
+ });
+
+ $toolbar.append($bold).append($italic);
+ };
+
+ this.destory = function () {
+ $toolbar.children().remove();
+ };
+ };
+
+ return Toolbar;
+});
File renamed without changes.
@@ -0,0 +1,42 @@
+define(function () {
+
+ var Builder = function (markup, children, options) {
+ this.build = function ($parent) {
+ var $node = $(markup);
+ if (options && options.name) {
+ $node.text(options.name);
+ }
+
+ if ($parent) {
+ $parent.append($node);
+ }
+
+ if (children) {
+ children.forEach(function (child) {
+ child.build($node);
+ });
+ }
+
+ return $node;
+ };
+ };
+
+ var createBuilder = function (markup) {
+ return function () {
+ var children = $.isArray(arguments[0]) ? arguments[0] : [];
+ var options = typeof arguments[1] === 'object' ? arguments[1] : arguments[0];
+ return new Builder(markup, children, options);
+ };
+ };
+
+ var renderer = {
+ editor: createBuilder('<div class="note-editor"></div>'),
+ toolbar: createBuilder('<div class="note-toolbar"></div>'),
+ editingArea: createBuilder('<div class="note-editingArea"></div>'),
+ codable: createBuilder('<div class="note-codable"></div>'),
+ editable: createBuilder('<div class="note-editable" contentEditable="true"></div>'),
+ button: createBuilder('<button class="note-btn"></button>')
+ };
+
+ return renderer;
+});
Oops, something went wrong.

0 comments on commit 05cdecc

Please sign in to comment.