Skip to content

Commit

Permalink
started work on adding highlight ability #3
Browse files Browse the repository at this point in the history
  • Loading branch information
caseymm committed Aug 9, 2017
1 parent 2149df8 commit 0149636
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions less/quotable.less
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,11 @@ canvas {
font-weight: inherit;
margin: 0;
line-height: 110%;
// background-color: #fff;

span {
line-height: inherit !important;
background-color: #fff200;
}
}

Expand Down Expand Up @@ -334,6 +336,10 @@ canvas {
line-height: 1.3;
display: block;
margin-top: 0;

span{
background-color: #fff200;
}
}

.show-credit {
Expand Down
31 changes: 31 additions & 0 deletions www/js/quotable.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ function adjustFontSize(size) {
};
}

function getSelectionText() {
var text = "";
if (window.getSelection) {
console.log();
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}

$(function() {
$text = $('.poster blockquote p, .source');
$save = $('#save');
Expand Down Expand Up @@ -183,6 +194,26 @@ $(function() {
// console.log($(this)[0].selectionStart);
// process_text();
// });
var selectedDiv;
$('.poster blockquote p').on('mousedown', function(){
selectedDiv = this;
});

$('.poster .source').on('mousedown', function(){
selectedDiv = this;
});

$(window).on('mouseup', function(){
if(getSelectionText().length > 0){
var selectedText = getSelectionText(),
text = $(selectedDiv).text(),
textArray = text.split(selectedText);

textArray.splice(1, 0, '<span>'+selectedText.split(' ').join('</span><span> </span><span>')+'</span>');
$(selectedDiv).html(textArray.join(''));
$(selectedDiv).blur();
}
});


var quoteEl = document.querySelectorAll('.poster blockquote');
Expand Down

0 comments on commit 0149636

Please sign in to comment.