Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
dcb1f32
Merge pull request #2 from marzhaev/parse-library
marzhaev Jan 14, 2019
7208576
added the template validate function
BitBravo Jan 15, 2019
ed7cc8e
updated the template validation function
BitBravo Jan 15, 2019
453039b
added media validate function
BitBravo Jan 15, 2019
8b642b6
Update Regex for template pattern recognition
BitBravo Jan 15, 2019
3eed8ea
real image type checking
BitBravo Jan 16, 2019
5267cce
fixed the url empty issue
BitBravo Jan 16, 2019
47a20b1
fixed some issue in element updating
BitBravo Jan 16, 2019
fb117dc
video validate function
BitBravo Jan 16, 2019
a0d26c4
youtube, Vimeo video validation
BitBravo Jan 17, 2019
d58768c
Embed library updated
BitBravo Jan 17, 2019
39be508
firebase configuration
BitBravo Jan 17, 2019
705de33
some updates
BitBravo Jan 18, 2019
7e8b932
fixed the DOM fetching issue
BitBravo Jan 18, 2019
b7f309f
Merge branch 'master' into parse-library
BitBravo Jan 22, 2019
78f4207
Merge pull request #4 from marzhaev/parse-library
BitBravo Jan 22, 2019
5c42db7
Update README.md
BitBravo Jan 22, 2019
396625a
Update README.md
BitBravo Jan 22, 2019
9f008dd
Update README.md
BitBravo Jan 22, 2019
ff57343
merge commit
BitBravo Jan 23, 2019
0702d21
video tag updated
BitBravo Jan 23, 2019
229ff55
Merge pull request #5 from marzhaev/parse-library
BitBravo Jan 24, 2019
ce5cbde
file upload request implemented
BitBravo Jan 25, 2019
5b0c0cd
fixed empty submit issue
BitBravo Jan 25, 2019
fdffd5c
iframe issue for online image
BitBravo Jan 25, 2019
a1ac4e3
video section fixed
BitBravo Jan 25, 2019
a03e0aa
cursor functions implement(get, set, update)
BitBravo Jan 28, 2019
2930b1a
drag&drop implemented
BitBravo Jan 30, 2019
19cd123
fixed upload error
BitBravo Jan 30, 2019
3aa09dd
fixed the duplicate request when drag-dropping.
BitBravo Jan 31, 2019
d1ccb6a
fixed input element initialization
BitBravo Jan 31, 2019
cbb373d
updated port config
BitBravo Jan 31, 2019
fb255e1
Merge pull request #6 from marzhaev/parse-library
BitBravo Jan 31, 2019
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
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# This is a HTML code editor.
This is a customize MediumEditor with the additional features than other Edit.
User can generate all html contents by using special pattern.

- How to create img elements
Live URL: https://medium-editor-3379b.firebaseapp.com
- How to create img and video elements

[![title](image_path)]
```[![image caption](image_path)]```

```[@[video caption](video url)]```

Example:
```[![Houses](http://sfeizigroup.com/wp-content/uploads/2017/05/slide-5.jpg)]```
[![Houses](http://sfeizigroup.com/wp-content/uploads/2017/05/slide-5.jpg)]

![url parse](./asserts/img/a.png)
```[@[video caption](video url)]```

## Main features

Expand All @@ -28,4 +31,4 @@ User can generate all html contents by using special pattern.
$ cd vikids_editor

$ npm install


13 changes: 13 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let express = require('express')
let path = require('path')

let app = express()
const port = 3000;
app.use(express.static(path.join(__dirname, '/')));


app.get('/', (req, res) => {
res.sendFile('index.html', {root: __dirname })
})

app.listen(port, () => { console.log('You app running on', port) })
2 changes: 1 addition & 1 deletion assests/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ var editor = new MediumEditor('.editable', {

$(function () {
$('.editable').mediumInsert({
editor: editor
editor: editor,
});
});
141 changes: 109 additions & 32 deletions assests/js/lib/embed/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
this.$el = $(el);
this.templates = window.MediumInsert.Templates;
this.extend = new Extend();
this.targetEl = ''
this.targetEl = '',
this.ctTime = null;

if (options) {
// Fix #142
Expand Down Expand Up @@ -113,6 +114,7 @@
this.$el
.on('dragover drop', function (e) {
e.preventDefault();
$.proxy(that, 'dragDropAction')(e)
})
.on('keyup click', $.proxy(this, 'toggleButtons'))
.on('selectstart mousedown', '.medium-insert, .medium-insert-buttons', $.proxy(this, 'disableSelection'))
Expand Down Expand Up @@ -297,6 +299,10 @@
that.$el[addonName](options);
that.options.addons[addon] = that.$el.data('plugin_' + addonName).options;
});

this.$el.append(this.templates['src/js/templates/images-fileupload.hbs']());
this.$el.find('input:file').hide();
this.$el.data('plugin_' + pluginName + ucfirst('images'))['add'](true);
};

/**
Expand Down Expand Up @@ -521,7 +527,6 @@
*/

Core.prototype.toggleAddons = function () {
console.log('insert new medias (core->toglleAddons)')
if (this.$el.find('.medium-insert-buttons').attr('data-active-addon') === 'images') {
this.$el.find('.medium-insert-buttons').find('button[data-addon="images"]').click();
return;
Expand Down Expand Up @@ -552,13 +557,35 @@
*/

Core.prototype.addonAction = function (e) {
console.log('select any media type here', e.currentTarget)
var $a = $(e.currentTarget),
addon = $a.data('addon'),
action = $a.data('action');
this.$el.data('plugin_' + pluginName + ucfirst(addon))[action]();
};


/**
* Call drag-drop's action
*
* @param {Event} e
* @return {void}
*/

Core.prototype.dragDropAction = function (e) {

const targetElement = e.target;
if(e.type === 'drop') {
this.$el.find('.medium-insert-active').removeClass('medium-insert-active');
this.$el.find('.medium-insert-embeds-active').removeClass('medium-insert-embeds-active');
e.target.click();

const newMediaDiv = document.createElement("div")
newMediaDiv.className = 'medium-insert-active'
targetElement.after(newMediaDiv);
}
};


/**
* Move caret at the beginning of the empty paragraph
*
Expand Down Expand Up @@ -702,11 +729,10 @@
*/

Core.prototype.embedMedia = function(data, that, result) {
console.log('Validate Response successflully ===>', result, data)

if(result === 'success' && data.type === 'img') {
that.createEmptyMediaDiv(data, "medium-insert-active")
that.$el.data('plugin_' + pluginName + ucfirst('images'))['uploadAdd'](data, {});

that.$el.data('plugin_' + pluginName + ucfirst('images'))['showImageByURL'](data);
}

if(result === 'success' && data.type === 'mov') {
Expand Down Expand Up @@ -811,9 +837,6 @@
const altText = matches[2]
const filePath = matches[3];

console.log('template validate')
console.log(`PatternType => ${mediaType}, AltText => ${altText}, FilePath => ${filePath}`)

// check if the current file is valid media file
const fileURLValidate= this.checkMediaUrlParse(mediaType, filePath)
if (fileURLValidate) {
Expand Down Expand Up @@ -841,20 +864,80 @@
})();
};

Core.prototype.getCursorPosition = function (element) {
element = element || document.querySelector('.editable')
var caretOffset = 0;
var preCaretRange = '';
var doc = element.ownerDocument || element.document;
var win = doc.defaultView || doc.parentWindow;
var sel;
if (typeof win.getSelection != "undefined") {
sel = win.getSelection();
if (sel.rangeCount > 0) {
var range = win.getSelection().getRangeAt(0);
preCaretRange = range.cloneRange();
preCaretRange.selectNodeContents(element);
preCaretRange.setEnd(range.endContainer, range.endOffset);
caretOffset = preCaretRange.toString().length;
}
} else if ( (sel = doc.selection) && sel.type != "Control") {
var textRange = sel.createRange();
var preCaretTextRange = doc.body.createTextRange();
preCaretTextRange.moveToElementText(element);
preCaretTextRange.setEndPoint("EndToEnd", textRange);
caretOffset = preCaretTextRange.text.length;
}

return {point: caretOffset, text: preCaretRange.toString()}
}

Core.prototype.getAllTextnodes = function (el) {
el = el || document.querySelector('.editable')
var n, a=[], walk=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null,false);
while(n=walk.nextNode()) a.push(n);
return a;
}

Core.prototype.getCursorData = function (el, position){
el = el || document.querySelector('.editable')
var node, nodes = this.getAllTextnodes(el);
for(var n = 0; n < nodes.length; n++) {
if (position > nodes[n].nodeValue.length && nodes[n+1]) {
// remove amount from the position, go to next node
position -= nodes[n].nodeValue.length;
} else {
node = nodes[n];
break;
}
}
// you'll need the node and the position (offset) to set the caret
return { node: node, position: position };
}

Core.prototype.setCursorPosition = function (d) {
var sel = window.getSelection(),
range = document.createRange();
range.setStart(d.node, d.position);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
}

Core.prototype.checkInputMediaToolbar = function () {
const cPoint = this.getCursorPosition();
const cPointDetail = this.getCursorData(null, cPoint.point);

// cPointDetail.node.parentElement.replaceChild('<h2>New heading</h2>');

}

Core.prototype.checkCustomPattern = function () {
var an = window.getSelection().anchorNode;
this.targetEl = $(an.parentElement);


// var $place1 = this.$el.find('.medium-insert-images');
// var $place2 = this.$el.find('.medium-insert-embeds-active');
// console.log(this.$el)
// console.log($place1)
// console.log($place2)

this.checkInputMediaToolbar();
// Parsed element data || false
const templateValidate = this.checkTemplateValidate();
console.log('template validate', templateValidate)
if (templateValidate) {
const mediaTyepe = templateValidate.type;
const mediaPath = templateValidate.url;
Expand All @@ -869,23 +952,17 @@

}
}

Core.prototype.simulateKeydown = function (el, keycode, isCtrl, isAlt, isShift) {
var e = new KeyboardEvent( "keydown", { bubbles:true, cancelable:true, char:String.fromCharCode(keycode), key:String.fromCharCode(keycode), shiftKey:isShift, ctrlKey:isCtrl, altKey:isAlt } );
Object.defineProperty(e, 'keyCode', {get : function() { return this.keyCodeVal; } });
e.keyCodeVal = keycode;
el.dispatchEvent(e);
}


Core.prototype.capturePattern = function () {
if(ctTime) {
window.clearTimeout(ctTime)
ctTime = null
} else {
ctTime = window.setTimeout(() => {
if(this.ctTime) {
window.clearTimeout(this.ctTime)
this.ctTime = null
}

this.ctTime = window.setTimeout(() => {
this.checkCustomPattern();
}, 100);
}
}, 500);

}

/** Plugin initialization */
Expand Down
25 changes: 13 additions & 12 deletions assests/js/lib/embed/embeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
label: '<span class="fa fa-align-right"></span>'
// added: function ($el) {},
// removed: function ($el) {}
}
},
},
actions: {
remove: {
Expand All @@ -42,6 +42,11 @@
parseOnPaste: false
};


function ucfirst(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}

/**
* Embeds object
*
Expand All @@ -56,7 +61,6 @@

function Embeds(el, options) {

console.log('emped ===> @@@@@@@@@@@@@@')
this.el = el;
this.$el = $(el);
this.templates = window.MediumInsert.Templates;
Expand Down Expand Up @@ -177,7 +181,6 @@
*/

Embeds.prototype.add = function () {
console.log('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@')
var $place = this.$el.find('.medium-insert-active');

// Fix #132
Expand Down Expand Up @@ -267,9 +270,6 @@
*/

Embeds.prototype.processLink = function (e) {
// console.log(this.core.capturePattern)
console.log('------------ Embded ProcessLink ---------------')

var $place = this.$el.find('.medium-insert-embeds-active'),
url;

Expand Down Expand Up @@ -331,7 +331,6 @@
Embeds.prototype.oembed = function (url, pasted, altText) {
console.log('Embded->Oembed 335 ===>', url, pasted)
var that = this;

$.support.cors = true;

$.ajax({
Expand All @@ -344,14 +343,15 @@
},
success: function (data) {
var html = data && data.html;
console.log('response data ===>', html)

if (that.options.storeMeta) {
html += '<div class="medium-insert-embeds-meta"><script type="text/json">' + JSON.stringify(data) + '</script></div>';
}

if (data && !html && data.type === 'photo' && data.url) {
if (data && data.type.match(/(photo|rich)/) && data.url) {
that.$el.data('plugin_' + pluginName + ucfirst('images'))['showImageByURL']({type: 'image', url: data.url}, {});
html = '<img src="' + data.url + '" alt="">';
return;
}

if (!html) {
Expand Down Expand Up @@ -432,10 +432,12 @@
*/

Embeds.prototype.embed = function (html, pastedUrl, altText) {
var $place = this.$el.find('.medium-insert-embeds-active'),
var $place = this.$el.find('.medium-insert-embeds-active').length? this.$el.find('.medium-insert-embeds-active') : this.$el.find('.medium-insert-active'),
$div, that;
that = this;

$place.attr('class', 'medium-insert-embeds-active');

if (!html) {
alert('Incorrect URL format specified');
return false;
Expand All @@ -461,7 +463,6 @@
$place.after(this.templates['src/js/templates/embeds-wrapper.hbs']({
html: html
}));

$place.text($place.text().replace(pastedUrl, ''));
} else {
if(altText) {
Expand Down Expand Up @@ -728,7 +729,7 @@

$lis.find('button').each(function () {
var className = 'medium-insert-embeds-' + $(this).data('action');

console.log(className)
if ($(this).hasClass('medium-editor-button-active')) {
$embed.addClass(className);

Expand Down
Loading