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

accept ele color as underline color #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
103 changes: 54 additions & 49 deletions js/underline.js
Expand Up @@ -15,6 +15,9 @@ var getElementStyles = function(element){
var height = $this.getBoundingClientRect().height;
var parentWidth = $this.parentNode.getBoundingClientRect().width;

var fontColor = window.getComputedStyle($this, null)
.getPropertyValue("color");


var offsetLeft = $this.offsetLeft;
var parentOffsetLeft = $this.parentNode.offsetLeft;
Expand All @@ -32,73 +35,75 @@ var getElementStyles = function(element){
fontStyle: fontStyle,
baselinePositionRatio: baselinePositionRatio,
canvasLeft: canvasLeft,
textIndent: textIndent
textIndent: textIndent,
fontColor: fontColor
}
};

window.requestAnimFrame = (function(callback) {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
})();

var myUnderlines = [];
var myMultipleUnderlines = [];
window.onload = function() {
var underlineElements = document.querySelectorAll(".underline");
var underlineElements = document.querySelectorAll(".underline");
for(var n = 0; n < underlineElements.length; n++) {

var element = underlineElements[n];

var underlineStyles = {
'text-underline-color': '#000',
'text-underline-position': 'auto', // could be ratio or todo: px
'text-underline-skip': true,
'text-underline-width': 'auto' // could be auto or px or ratio
}


var elementStyles = getElementStyles(element);
// single line or multiple line?
if (elementStyles.height > elementStyles.lineHeight) {
// multiple lines
// console.log('multiple lines');
var myUnderline = new MultipleUnderline(element, underlineStyles, elementStyles);
// myUnderline.update();
// myUnderline.draw();
myUnderlines.push(myUnderline);
} else {
// single line
var myUnderline = new SingleUnderline(element, underlineStyles, elementStyles);
myUnderlines.push(myUnderline);
}

// if(window.device)
var element = underlineElements[n];

var elementStyles = getElementStyles(element);

var underlineStyles = {
'text-underline-color': elementStyles.fontColor,
'text-underline-position': 'auto', // could be ratio or todo: px
'text-underline-skip': true,
'text-underline-width': 'auto' // could be auto or px or ratio
}


// single line or multiple line?
if (elementStyles.height > elementStyles.lineHeight) {
// multiple lines
// console.log('multiple lines');
var myUnderline = new MultipleUnderline(element, underlineStyles, elementStyles);
// myUnderline.update();
// myUnderline.draw();
myUnderlines.push(myUnderline);
} else {
// single line
var myUnderline = new SingleUnderline(element, underlineStyles, elementStyles);
myUnderlines.push(myUnderline);
}

// if(window.device)
}
}


function animate() {
function animate() {

for(var i = 0; i < myUnderlines.length; i++) {
var myUnderline = myUnderlines[i];
for(var i = 0; i < myUnderlines.length; i++) {
var myUnderline = myUnderlines[i];

// clear
myUnderline.clear();
// update
myUnderline.update();
// draw stuff
myUnderline.draw();
}
// clear
myUnderline.clear();
// update
myUnderline.update();
// draw stuff
myUnderline.draw();
}

// request new frame
requestAnimFrame(function() {
animate();
});
// request new frame
requestAnimFrame(function() {
animate();
});
}
animate();

Expand Down