Skip to content

Commit

Permalink
initial v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
agusmakmun committed Dec 29, 2016
1 parent e496ef0 commit bbd48c6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist/
*.egg-info/
*.pypirc
*.pyc
*note
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
draceditor
------------
draceditor |pypi version|
------------------------------

.. image:: https://img.shields.io/pypi/v/draceditor.svg?style=flat-square
.. |pypi version|
image:: https://img.shields.io/pypi/v/draceditor.svg?style=flat-square
:target: https://pypi.python.org/pypi/draceditor
.. image:: https://img.shields.io/badge/license-GNUGPLv3-blue.svg?style=flat-square
Expand All @@ -16,6 +17,5 @@ draceditor
.. image:: https://img.shields.io/pypi/dm/draceditor.svg?style=flat-square
:target: https://pypi.python.org/pypi/draceditor

-------------------

**Django Markdown Editor** build for Dracos Linux https://dracos-linux.org *(Under Development Mode)*
**DracEditor** is Django Markdown Editor build for Dracos Linux https://dracos-linux.org *(Under Development Mode)*
72 changes: 72 additions & 0 deletions draceditor/static/js/draceditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,84 @@
});
};

/**
* The state of CodeMirror at the given position.
* https://github.com/lepture/editor
*/
var getState = function(cm, pos) {
pos = pos || cm.getCursor('start');
var stat = cm.getTokenAt(pos);
if (!stat.type) return {};

var types = stat.type.split(' ');

var ret = {}, data, text;
for (var i = 0; i < types.length; i++) {
data = types[i];
if (data === 'strong') {
ret.bold = true;
} else if (data === 'variable-2') {
text = cm.getLine(pos.line);
if (/^\s*\d+\.\s/.test(text)) {
ret['ordered-list'] = true;
} else {
ret['unordered-list'] = true;
}
} else if (data === 'atom') {
ret.quote = true;
} else if (data === 'em') {
ret.italic = true;
}
}
return ret;
}

var replaceSelection = function(cm, active, start, end) {
var text;
var startPoint = cm.getCursor('start');
var endPoint = cm.getCursor('end');
if (active) {
text = cm.getLine(startPoint.line);
start = text.slice(0, startPoint.ch);
end = text.slice(startPoint.ch);
cm.setLine(startPoint.line, start + end);
} else {
text = cm.getSelection();
cm.replaceSelection(start + text + end);

startPoint.ch += start.length;
endPoint.ch += start.length;
}
cm.setSelection(startPoint, endPoint);
cm.focus();
}

var onKeyUpEvent = function(e) {
console.log(e);
onMention();
onEmoji();
}

var timeout;
var update = function(e) {
console.log(e);
onMention();
console.log(e.getValue());
//clearTimeout(timeout);
//timeout = setTimeout(getMarkdown, 1000);
};

var editor;
setTimeout(function(){
//$('.CodeMirror').attr({'contentEditable': 'true'});
editor = $('.CodeMirror')[0].CodeMirror;
editor.on('change', update);
editor.on('keyup', function(cm, e) {
console.log(cm, e);
onMention();
});
}, 500);

var draceditor = $(this);
var dracEditor = $(this).find('.draceditor');
dracEditor.on('keydown.draceditor', onKeyUpEvent);
Expand Down

0 comments on commit bbd48c6

Please sign in to comment.