Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRLF/LF fixes, some comment grammar/spelling fixes #328

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
2 changes: 1 addition & 1 deletion CHANGELOG.textile
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
* Fixed Safari context menu issue (#27)
* Fixed weird issue in Chrome happening when the editor was initialized when the textarea has been inserted dynamically (#15)
* Fixed issue happening with the polish keyboard layout (#16)
* Make sure that the editor iframe uses same IE document mode as it's parent
* Make sure that the editor iframe uses same IE document mode as its parent

*wysihtml5 0.3.0 RC 1* (February 5, 2012)

Expand Down
89 changes: 63 additions & 26 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
module.exports = function(grunt) {

"use strict";

var moduleAMDHeader = "\
(function (root, factory) {\n\
if(typeof define === 'function' && define.amd) {\n\
define(['wysihtml'], factory);\n\
} else if(typeof module === 'object' && module.exports) {\n\
module.exports = factory(require('wysihtml'));\n\
} else {\n\
factory(root.wysihtml);\n\
}\n\
})(this, function(wysihtml) {\n\n";

var AMDHeader = "\
(function (root, factory) {\n\
if(typeof define === 'function' && define.amd) {\n\
define(factory);\n\
} else if(typeof module === 'object' && module.exports) {\n\
module.exports = factory();\n\
} else {\n\
factory();\n\
}\n\
})(this, function() {\n\n";

var AMDFooter = "\n});\n";

// List required source files that will be built into wysihtml5x.js
var base = [
"src/wysihtml5.js",
"src/wysihtml.js",
"src/polyfills.js",
"node_modules/rangy/lib/rangy-core.js",
"node_modules/rangy/lib/rangy-textrange.js",
Expand Down Expand Up @@ -60,46 +84,22 @@ module.exports = function(grunt) {
"src/quirks/table_cells_selection.js",
"src/quirks/style_parser.js",
"src/selection/selection.js",
"src/selection/html_applier.js",
"src/commands.js",
"src/commands/bold.js",
"src/commands/createLink.js",
"src/commands/removeLink.js",
"src/commands/fontSize.js",
"src/commands/fontSizeStyle.js",
"src/commands/foreColor.js",
"src/commands/foreColorStyle.js",
"src/commands/bgColorStyle.js",
"src/commands/formatBlock.js",
"src/commands/formatCode.js",
"src/commands/formatInline.js",
"src/commands/insertBlockQuote.js",
"src/commands/insertHTML.js",
"src/commands/insertImage.js",
"src/commands/insertLineBreak.js",
"src/commands/insertOrderedList.js",
"src/commands/insertUnorderedList.js",
"src/commands/insertList.js",
"src/commands/italic.js",
"src/commands/justifyCenter.js",
"src/commands/justifyLeft.js",
"src/commands/justifyRight.js",
"src/commands/justifyFull.js",
"src/commands/alignRightStyle.js",
"src/commands/alignLeftStyle.js",
"src/commands/alignCenterStyle.js",
"src/commands/alignJustifyStyle.js",
"src/commands/redo.js",
"src/commands/underline.js",
"src/commands/undo.js",
"src/commands/createTable.js",
"src/commands/mergeTableCells.js",
"src/commands/addTableCells.js",
"src/commands/deleteTableCells.js",
"src/commands/indentList.js",
"src/commands/outdentList.js",
"src/commands/subscript.js",
"src/commands/superscript.js",
"src/undo_manager.js",
"src/views/view.js",
"src/views/composer.js",
Expand All @@ -126,6 +126,8 @@ module.exports = function(grunt) {
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
banner: AMDHeader,
footer: AMDFooter,
separator: ';',
process: function(src, filepath) {
return src.replace(/@VERSION/g, grunt.config.get('pkg.version'));
Expand Down Expand Up @@ -162,7 +164,42 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-open');

grunt.registerTask("build-modules", "Builds all extension files", function() {
var concat = {},
uglify = {};

grunt.file.expand("./src/extensions/*").forEach(function (d) {
var dir = d.split('/').pop();

if (!grunt.file.isDir(d)) {
var fnameArr = dir.split('.');
fnameArr.pop();
dir = fnameArr.join('.');
}

concat[dir] = {
options: {
banner: moduleAMDHeader,
footer: AMDFooter
},
src: grunt.file.isDir(d) ? [d + '/*.js'] : [d],
dest: 'dist/modules/wysihtml.' + dir + '.js'
};

uglify[dir] = {
files: {
['dist/modules/wysihtml.' + dir + '.min.js']: 'dist/modules/wysihtml.' + dir + '.js'
}
};

});
grunt.config.set('concat', concat);
grunt.task.run('concat');
grunt.config.set('uglify', uglify);
grunt.task.run('uglify');
});

grunt.registerTask('default', ['concat', 'uglify']);
grunt.registerTask('default', ['concat', 'uglify', 'build-modules']);
grunt.registerTask('test', ['open:test']);
};
64 changes: 64 additions & 0 deletions dist/modules/wysihtml.command_formatCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
(function (root, factory) {
if(typeof define === 'function' && define.amd) {
define(['wysihtml'], factory);
} else if(typeof module === 'object' && module.exports) {
module.exports = factory(require('wysihtml'));
} else {
factory(root.wysihtml);
}
})(this, function(wysihtml) {

/* Formats block for as a <pre><code class="classname"></code></pre> block
* Useful in conjuction for sytax highlight utility: highlight.js
*
* Usage:
*
* editorInstance.composer.commands.exec("formatCode", "language-html");
*/
wysihtml.commands.formatCode = (function() {
return {
exec: function(composer, command, classname) {
var pre = this.state(composer)[0],
code, range, selectedNodes;

if (pre) {
// caret is already within a <pre><code>...</code></pre>
composer.selection.executeAndRestore(function() {
code = pre.querySelector("code");
wysihtml.dom.replaceWithChildNodes(pre);
if (code) {
wysihtml.dom.replaceWithChildNodes(code);
}
});
} else {
// Wrap in <pre><code>...</code></pre>
range = composer.selection.getRange();
selectedNodes = range.extractContents();
pre = composer.doc.createElement("pre");
code = composer.doc.createElement("code");

if (classname) {
code.className = classname;
}

pre.appendChild(code);
code.appendChild(selectedNodes);
range.insertNode(pre);
composer.selection.selectNode(pre);
}
},

state: function(composer) {
var selectedNode = composer.selection.getSelectedNode(), node;
if (selectedNode && selectedNode.nodeName && selectedNode.nodeName == "PRE"&&
selectedNode.firstChild && selectedNode.firstChild.nodeName && selectedNode.firstChild.nodeName == "CODE") {
return [selectedNode];
} else {
node = wysihtml.dom.getParentElement(selectedNode, { query: "pre code" });
return node ? [node.parentNode] : false;
}
}
};
})();

});
1 change: 1 addition & 0 deletions dist/modules/wysihtml.command_formatCode.min.js

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

120 changes: 120 additions & 0 deletions dist/modules/wysihtml.command_insertImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
(function (root, factory) {
if(typeof define === 'function' && define.amd) {
define(['wysihtml'], factory);
} else if(typeof module === 'object' && module.exports) {
module.exports = factory(require('wysihtml'));
} else {
factory(root.wysihtml);
}
})(this, function(wysihtml) {

/**
* Inserts an <img>
* If selection is already an image link, it removes it
*
* @example
* // either ...
* wysihtml.commands.insertImage.exec(composer, "insertImage", "http://www.google.de/logo.jpg");
* // ... or ...
* wysihtml.commands.insertImage.exec(composer, "insertImage", { src: "http://www.google.de/logo.jpg", title: "foo" });
*/
wysihtml.commands.insertImage = (function() {
var NODE_NAME = "IMG";
return {
exec: function(composer, command, value) {
value = typeof(value) === "object" ? value : { src: value };

var doc = composer.doc,
image = this.state(composer),
textNode,
parent;

// If image is selected and src ie empty, set the caret before it and delete the image
if (image && !value.src) {
composer.selection.setBefore(image);
parent = image.parentNode;
parent.removeChild(image);

// and its parent <a> too if it hasn't got any other relevant child nodes
wysihtml.dom.removeEmptyTextNodes(parent);
if (parent.nodeName === "A" && !parent.firstChild) {
composer.selection.setAfter(parent);
parent.parentNode.removeChild(parent);
}

// firefox and ie sometimes don't remove the image handles, even though the image got removed
wysihtml.quirks.redraw(composer.element);
return;
}

// If image selected change attributes accordingly
if (image) {
for (var key in value) {
if (value.hasOwnProperty(key)) {
image.setAttribute(key === "className" ? "class" : key, value[key]);
}
}
return;
}

// Otherwise lets create the image
image = doc.createElement(NODE_NAME);

for (var i in value) {
image.setAttribute(i === "className" ? "class" : i, value[i]);
}

composer.selection.insertNode(image);
if (wysihtml.browser.hasProblemsSettingCaretAfterImg()) {
textNode = doc.createTextNode(wysihtml.INVISIBLE_SPACE);
composer.selection.insertNode(textNode);
composer.selection.setAfter(textNode);
} else {
composer.selection.setAfter(image);
}
},

state: function(composer) {
var doc = composer.doc,
selectedNode,
text,
imagesInSelection;

if (!wysihtml.dom.hasElementWithTagName(doc, NODE_NAME)) {
return false;
}

selectedNode = composer.selection.getSelectedNode();
if (!selectedNode) {
return false;
}

if (selectedNode.nodeName === NODE_NAME) {
// This works perfectly in IE
return selectedNode;
}

if (selectedNode.nodeType !== wysihtml.ELEMENT_NODE) {
return false;
}

text = composer.selection.getText();
text = wysihtml.lang.string(text).trim();
if (text) {
return false;
}

imagesInSelection = composer.selection.getNodes(wysihtml.ELEMENT_NODE, function(node) {
return node.nodeName === "IMG";
});

if (imagesInSelection.length !== 1) {
return false;
}

return imagesInSelection[0];
}
};
})();

});
1 change: 1 addition & 0 deletions dist/modules/wysihtml.command_insertImage.min.js

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

Loading