Skip to content

Commit

Permalink
RAJE V0.2.1 + executables "pull request #78"
Browse files Browse the repository at this point in the history
Merge pull request #78 from essepuntato/raje
  • Loading branch information
gspinaci authored Apr 1, 2017
2 parents 4329751 + e2cb091 commit 30521b0
Show file tree
Hide file tree
Showing 15 changed files with 448 additions and 137 deletions.
8 changes: 6 additions & 2 deletions sources/raje/app/css/rash-inline.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ img.avatar{
span.affiliation.placeholder{
color:#999
}

/*
pre{
position: relative
}
Expand All @@ -109,4 +109,8 @@ pre::after{
padding: 10px 20px;
background-color: rgba('0,0,0,.5');
content: "enter = new line"
}
}
figure > pref::after{
display: none
}*/
11 changes: 11 additions & 0 deletions sources/raje/app/js/editor/1_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ jQuery.fn.extend({
setEditState()
})

$(this).bind('dragover drop', function (event) {
event.preventDefault();
return false;
});

/**
* Get when call event to disable or activate toolbar elements
*/
Expand Down Expand Up @@ -180,6 +185,12 @@ window.handleFormulaBox = function () {
window[id].showModal();
};

window.handleListingBox = function () {
var id = 'table_' + ($(this).findNumber(listingbox_selector) + 1);
window[id] = new rashEditor.Listing(id);
window[id].add();
};

$(document).ready(function () {

/* START .rash_inline */
Expand Down
2 changes: 1 addition & 1 deletion sources/raje/app/js/editor/2_caret.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ caret = {
},

checkIfInHeading: function () {
return $(window.getSelection().anchorNode).parents('h1,h2,h3').length;
return $(window.getSelection().anchorNode).parents('h1,h2,h3,h4,h5,h6').length;
},

checkIfBorder: function () {
Expand Down
11 changes: 11 additions & 0 deletions sources/raje/app/js/editor/3_const.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ const ZERO_SPACE = '​';
const ONE_SPACE = ' ';

const messageDealer = 'div#messageDealer';

Array.prototype.indexOfContent = function (searchTerm) {
let index = -1;
for (var i = 0, len = this.length; i < len; i++) {
if (this[i].content == searchTerm) {
index = i;
break;
}
}
return index
}
64 changes: 57 additions & 7 deletions sources/raje/app/js/editor/4_raje.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@ rashEditor = {

let title = $(sel.anchorNode).parents('h1')

if (!$('h1.title small').length)
document.execCommand("insertHTML", false, `<br/><small>${ZERO_SPACE}</small>`)
if (!title.find('small').length) {
title.append(`<br/><small>${ZERO_SPACE}</small>`)
caret.moveStart(title.find('small'))
caret.move('character', 1)
}
}
},

Expand Down Expand Up @@ -331,6 +334,18 @@ rashEditor = {
referenceables.append(formulas)
}

if ($(`${rash_inline_selector} ${listingbox_selector}`).length) {

let formulas = $(this.createCollapsable('Listings'))

$(`${rash_inline_selector} figure:has(pre)`).each(function () {
let text = $(this).find('figcaption').text()
formulas.find('#listListings').append(`<a data-type="role" data-ref="${$(this).attr('id')}" class="list-group-item">${text}</a>`)
})

referenceables.append(formulas)
}

let references = $(this.createCollapsable('References'))

references.find('#listReferences').append(`<a data-type="addBiblioentry" class="list-group-item">+ add new bibliographic reference</a>`)
Expand Down Expand Up @@ -384,11 +399,14 @@ rashEditor = {
if (sel.isCollapsed) {
document.execCommand("insertHTML", false, string);
caret.moveStart($(`${element}[data-pointer]`))
$(`${element}[data-pointer]`).removeAttr('data-pointer')

caret.move('character', 1)

if (isFormula) {
caret.move('character', 2)
}

$(`${element}[data-pointer]`).removeAttr('data-pointer')
}
else {
var range = sel.getRangeAt(0);
Expand Down Expand Up @@ -659,8 +677,13 @@ rashEditor = {

} else {

if (!node)
node = $('section[role="doc-endnotes"]>section:last-child')
if (!node) {
if ($('section[role="doc-endnotes"]>section').length)
node = $('section[role="doc-endnotes"]>section:last-child')
else
node = $('section[role="doc-endnotes"]>h1')
}


let getNextEndnote = function () {
let max = -1
Expand Down Expand Up @@ -899,8 +922,19 @@ rashEditor = {
if (undefined !== this.selection) {
rangy.restoreSelection(this.selection);

let paragraph = $(rangy.getSelection().anchorNode).parents('p').first()

let string

if (paragraph.text().length != 0) {
string = `<p><figure id="${this.id}"><p class="rash-math">\`\`${asciiFormula}\`\`</p></figure></p>`
rashEditor.insertParagraph(paragraph[0])
}
else
string = `<figure id="${this.id}"><p class="rash-math">\`\`${asciiFormula}\`\`</p></figure>`

// render formula
document.execCommand("insertHTML", false, "<figure id=\"" + this.id + "\"><p class=\"rash-math\">\`\`" + asciiFormula + "\`\`</p></figure>");
document.execCommand("insertHTML", false, string);
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);

//get mathml
Expand All @@ -910,9 +944,25 @@ rashEditor = {
captions()
formulas()
refreshReferences()

caret.moveAfterNode($(`figure#${this.id} > p > span.cgen`)[0])
}
};
}
},

Listing: function (id) {
this.selection;
this.id = id;

this.add = function () {
let sel = rangy.getSelection()
let string = '<br>'
if (sel && !sel.isCollapsed)
string = sel.toString()
document.execCommand("insertHTML", false, `<figure id="${this.id}"><pre>${ZERO_SPACE}<code>${string}</code></pre><figcaption>Caption of the <code>listing</code>.</figcaption></figure>`);
captions()
}
},

/* END boxes */
};
48 changes: 33 additions & 15 deletions sources/raje/app/js/editor/5_shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rashEditor.
init = function () {

// paste only text, without style
$(rash_inline_selector)[0].addEventListener("paste", function (e) {
$(document)[0].addEventListener("paste", function (e) {

e.preventDefault();

Expand All @@ -34,6 +34,7 @@ rashEditor.
return false
});


Mousetrap.bind('space', function (event) {
var sel = rangy.getSelection()

Expand All @@ -42,17 +43,12 @@ rashEditor.

var parent = {
reference: $(node).parents('a[href]:has(span.cgen),a[href]:has(sup.cgen)').last(),
endnote: $(node).parents('section[role="doc-endnote"]').last()
}

if (!parent.endnote.length) {
if (parent.reference.length) {
rashEditor.exitInline(parent.reference)
return false
}
if (parent.reference.length) {
rashEditor.exitInline(parent.reference)
return false
}
else
return true
}
})

Expand Down Expand Up @@ -103,6 +99,9 @@ rashEditor.
//cross reference
reference: $(node).parents('a[href]:has(span.cgen),a[href]:has(sup.cgen)').last(),

//headings
headings: $(node).parents('h1, h2, h3, h4, h5, h6').first(),

//inlines
crossRef: $(node).parents('a.cgen').last(),
code_inline: $(node).parents('code').last(),
Expand All @@ -129,17 +128,22 @@ rashEditor.

// header
if (parent.subtitle.length) {
caret.getNextElement(parent.title)
if (parent.subtitle.text().length == 1) {
caret.getNextElement(parent.title)
parent.subtitle.prev('br').remove()
parent.subtitle.remove()
}
else
caret.getNextElement(parent.title)
return false

} else if (parent.title.length) {
caret.getNextElement(parent.title)
//rashEditor.header.insertSubTitle()
//caret.getNextElement(parent.title)
rashEditor.header.insertSubTitle()
return false

} else if (parent.author.name.length) {
caret.getNextElement(parent.author.name)
//sel.move('character', 1)
return false

} else if (parent.author.email.length) {
Expand Down Expand Up @@ -184,6 +188,13 @@ rashEditor.
rashEditor.exitInline(parent.reference)
}

//headings
else if (parent.headings.length) {
console.log(caret.checkIfBorder())
if (caret.checkIfBorder() != 1)
return false
}

// inlines
else if (parent.formula_inline.length) {
if (parent.formula_inline.find('span[data-mathml]').length)
Expand Down Expand Up @@ -232,7 +243,8 @@ rashEditor.

/** endnotes */
else if (parent.endnote.length) {
rashEditor.insertEndnote($(node).parents('section[role="doc-endnote"]').last())
rashEditor.insertParagraph(parent.paragraph[0]);
//rashEditor.insertEndnote($(node).parents('section[role="doc-endnote"]').last())
return false
}

Expand Down Expand Up @@ -298,6 +310,7 @@ rashEditor.
if (parent.placeholderAffiliation.length) {

parent.placeholderAffiliation.removeClass('placeholder')
parent.placeholderAffiliation.text('')
}
}
})
Expand All @@ -309,7 +322,8 @@ rashEditor.
var parent = {
title: $(node).parents('h1.title').last(),
pre: $(node).parents('pre').last(),
blockquote: $(node).parents('blockquote').last()
blockquote: $(node).parents('blockquote').last(),
headings: $(node).parents('h1, h2, h3, h4, h5, h6')
}

if (parent.title.length) {
Expand All @@ -326,6 +340,10 @@ rashEditor.
rashEditor.insertParagraph(parent.blockquote[0])
return false
}

else if (parent.headings.length) {
return false
}
}
})

Expand Down
Loading

0 comments on commit 30521b0

Please sign in to comment.