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

cover restoring and fetch function fixed #101

Merged
merged 9 commits into from
Dec 25, 2016
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ Thumbs.db
/*.sublime-project
/*.sublime-workspace

node_modules/*
plugins/*
node_modules/*
14 changes: 9 additions & 5 deletions codex-editor.js

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

2 changes: 1 addition & 1 deletion codex-editor.js.map

Large diffs are not rendered by default.

152 changes: 151 additions & 1 deletion example.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,165 @@
<script src="./codex-editor.js?v=10"></script>
<link rel="stylesheet" href="./codex-editor.css?v=10">

<link rel="stylesheet" href="codex-editor.css">

<script src="plugins/paragraph/paragraph.js"></script>
<link rel="stylesheet" href="plugins/paragraph/paragraph.css">

<script src="plugins/header/header.js"></script>
<link rel="stylesheet" href="plugins/header/header.css">

<script src="plugins/code/code.js"></script>
<link rel="stylesheet" href="plugins/code/code.css">

<script src="plugins/link/link.js"></script>
<link rel="stylesheet" href="plugins/link/link.css">

<script src="plugins/quote/quote.js"></script>
<link rel="stylesheet" href="plugins/quote/quote.css">

<script src="plugins/list/list.js"></script>
<link rel="stylesheet" href="plugins/list/list.css">

<script src="plugins/image/image.js"></script>
<link rel="stylesheet" href="plugins/image/image.css">

<script src="plugins/instagram/instagram.js"></script>
<link rel="stylesheet" href="plugins/instagram/instagram.css">

<script src="plugins/twitter/twitter.js"></script>
<link rel="stylesheet" href="plugins/twitter/twitter.css">

<script src="plugins/paste/paste.js"></script>
<link rel="stylesheet" href="plugins/paste/paste.css">

<script>
codex.start({
textareaId : "codex_area",
tools : {
paragraph: {
type: 'paragraph',
iconClassname: 'ce-icon-paragraph',
make: paragraphTool.make,
appendCallback: null,
settings: null,
render: paragraphTool.render,
save: paragraphTool.save,
displayInToolbox: false,
enableLineBreaks: false,
allowedToPaste: true
},
paste: {
type: 'paste',
iconClassname: '',
prepare: pasteTool.prepare,
make: pasteTool.make,
appendCallback: null,
settings: null,
render: null,
save: pasteTool.save,
displayInToolbox: false,
enableLineBreaks: false,
callbacks: pasteTool.callbacks,
allowedToPaste: false
},
header: {
type: 'header',
iconClassname: 'ce-icon-header',
make: headerTool.make,
appendCallback: headerTool.appendCallback,
settings: headerTool.makeSettings(),
render: headerTool.render,
save: headerTool.save
},
code: {
type: 'code',
iconClassname: 'ce-icon-code',
make: codeTool.make,
appendCallback: null,
settings: null,
render: codeTool.render,
save: codeTool.save,
displayInToolbox: true,
enableLineBreaks: true
},
link: {
type: 'link',
iconClassname: 'ce-icon-link',
make: linkTool.makeNewBlock,
appendCallback: linkTool.appendCallback,
render: linkTool.render,
save: linkTool.save,
displayInToolbox: true,
enableLineBreaks: true
},
list: {
type: 'list',
iconClassname: 'ce-icon-list-bullet',
make: listTool.make,
appendCallback: null,
settings: listTool.makeSettings(),
render: listTool.render,
save: listTool.save,
displayInToolbox: true,
enableLineBreaks: true
},
quote: {
type: 'quote',
iconClassname: 'ce-icon-quote',
make: quoteTools.makeBlockToAppend,
appendCallback: null,
settings: quoteTools.makeSettings(),
render: quoteTools.render,
save: quoteTools.save,
displayInToolbox: true,
enableLineBreaks: true,
allowedToPaste: true
},
image: {
type: 'image',
iconClassname: 'ce-icon-picture',
make: ceImage.make,
appendCallback: ceImage.appendCallback,
settings: ceImage.makeSettings(),
render: ceImage.render,
save: ceImage.save,
isStretched: true,
displayInToolbox: true,
enableLineBreaks: false
},
instagram: {
type: 'instagram',
iconClassname: 'ce-icon-instagram',
prepare: instagramTool.prepare,
make: instagramTool.make,
appendCallback: null,
settings: null,
render: instagramTool.reneder,
save: instagramTool.save,
displayInToolbox: false,
enableLineBreaks: false,
allowedToPaste: false
},
twitter: {
type: 'twitter',
iconClassname: 'ce-icon-twitter',
prepare: twitterTool.prepare,
make: twitterTool.make,
appendCallback: null,
settings: null,
render: twitterTool.render,
save: twitterTool.save,
displayInToolbox: false,
enableLineBreaks: false,
allowedToPaste: false
}
},
data : {
items: [],
count: 0
}
});
</script>

<link rel="stylesheet" href="codex-editor.css">
</html>
5 changes: 5 additions & 0 deletions modules/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,15 @@ var content = (function(content) {
var workingBlock = codex.content.currentNode,
newBlockContent = blockData.block,
blockType = blockData.type,
cover = blockData.cover,
isStretched = blockData.stretched;

var newBlock = codex.content.composeNewBlock(newBlockContent, blockType, isStretched);

if (cover === true) {
newBlock.classList.add(codex.ui.className.BLOCK_IN_FEED_MODE);
}

if (workingBlock) {

codex.core.insertAfter(workingBlock, newBlock);
Expand Down
9 changes: 4 additions & 5 deletions modules/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ var renderer = (function(renderer) {
renderer.createBlockFromData = function (blockData) {

/** New parser */
var pluginName = blockData.type;
var pluginName = blockData.type,
cover = blockData.cover;

/** Get first key of object that stores plugin name */
// for (var pluginName in blockData) break;
Expand All @@ -148,17 +149,15 @@ var renderer = (function(renderer) {
/** New Parser */
var block = codex.tools[pluginName].render(blockData.data);

/** Fire the render method with data */
// var block = codex.tools[pluginName].render(blockData[pluginName]);

/** is first-level block stretched */
var stretched = codex.tools[pluginName].isStretched || false;

/** Retrun type and block */
return {
type : pluginName,
block : block,
stretched : stretched
stretched : stretched,
cover : cover
};

};
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
},
"author": "Codex Team",
"license": "ISC",
"dependencies": {},
"dependencies": {
"whatwg-fetch": "^2.0.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему не в dev?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

плагины же без сборки. fetch используется в плагине link, поэтому подумал, что к ядру это не относится. Разработчик может написать свой аякс, либо пользоваться нашим API.

},
"devDependencies": {
"babel-core": "^6.21.0",
"babel-loader": "^6.2.10",
Expand Down
25 changes: 25 additions & 0 deletions plugins/code/code.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.ce-code {
display: block;
border: 1px solid #ebeef3;
border-radius: 3px;
background: #fdfdff !important;

margin: 1em 0 !important;
padding: .5em .8em;
box-sizing: border-box;
white-space: pre-wrap;

font-family: 'monospace', 'monaco', 'consolas', 'courier';
line-height: 1.5em;
color: #325179;
font-size: .8em;
}


/**
* CodeX Editor styles overlay
* @todo change for ce-tool-wrapper__code
*/
.ce_block[data-type="code"]{
padding: 1em 0 !important;
}
54 changes: 54 additions & 0 deletions plugins/code/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Code Plugin\
* Creates code tag and adds content to this tag
*/
var codeTool = {

baseClass : "ce-code",

/**
* Make initial header block
* @param {object} JSON with block data
* @return {Element} element to append
*/
make : function (data) {

var tag = document.createElement('code');

tag.classList.add(codeTool.baseClass);

if (data && data.text) {
tag.innerHTML = data.text;
}

tag.contentEditable = true;

return tag;

},

/**
* Method to render HTML block from JSON
*/
render : function (data) {

return codeTool.make(data);

},

/**
* Method to extract JSON data from HTML block
*/
save : function (blockContent){

var data = {
text : null,
};

data.text = blockContent.innerHTML;

return data;

}

};
Loading