File html2canvas.js
has 2470 lines of code (exceeds 250 allowed). Consider refactoring. Open
/*
html2canvas 0.4.1 <http://html2canvas.hertzen.com>
Copyright (c) 2013 Niklas von Hertzen
Released under MIT License
- Create a ticketCreate a ticket
Function Parse
has 1039 lines of code (exceeds 25 allowed). Consider refactoring. Open
_html2canvas.Parse = function (images, options, cb) {
window.scroll(0,0);
var element = (( options.elements === undefined ) ? document.body : options.elements[0]), // select body by default
numDraws = 0,
- Create a ticketCreate a ticket
Function Preload
has 265 lines of code (exceeds 25 allowed). Consider refactoring. Open
_html2canvas.Preload = function( options ) {
var images = {
numLoaded: 0, // also failed are counted here
numFailed: 0,
- Create a ticketCreate a ticket
Function parseGradient
has 252 lines of code (exceeds 25 allowed). Consider refactoring. Open
Generate.parseGradient = function(css, bounds) {
var gradient, i, len = reGradients.length, m1, stop, m2, m2Len, step, m3, tl,tr,br,bl;
for(i = 0; i < len; i+=1){
m1 = css.match(reGradients[i]);
- Create a ticketCreate a ticket
Function h2cRenderContext
has 117 lines of code (exceeds 25 allowed). Consider refactoring. Open
function h2cRenderContext(width, height) {
var storage = [];
return {
storage: storage,
width: width,
- Create a ticketCreate a ticket
Function Canvas
has 107 lines of code (exceeds 25 allowed). Consider refactoring. Open
_html2canvas.Renderer.Canvas = function(options) {
options = options || {};
var doc = document,
safeImages = [],
- Create a ticketCreate a ticket
Function Renderer
has 90 lines of code (exceeds 25 allowed). Consider refactoring. Open
_html2canvas.Renderer = function(parseQueue, options){
function sortZindex(a, b) {
if (a === 'children') {
return -1;
} else if (b === 'children') {
- Create a ticketCreate a ticket
Function parseBackgroundImage
has 89 lines of code (exceeds 25 allowed). Consider refactoring. Open
_html2canvas.Util.parseBackgroundImage = function (value) {
var whitespace = ' \r\n\t',
method, definition, prefix, prefix_i, block, results = [],
c, mode = 0, numParen = 0, quote, args;
- Create a ticketCreate a ticket
Function parseBorders
has 73 lines of code (exceeds 25 allowed). Consider refactoring. Open
function parseBorders(element, bounds, borders){
var x = bounds.left,
y = bounds.top,
width = bounds.width,
height = bounds.height,
- Create a ticketCreate a ticket
Function calculateCurvePoints
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
function calculateCurvePoints(bounds, borderRadius, borders) {
var x = bounds.left,
y = bounds.top,
width = bounds.width,
- Create a ticketCreate a ticket
Function createRenderQueue
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
function createRenderQueue(parseQueue) {
var queue = [],
rootContext;
rootContext = (function buildStackingContext(rootNode) {
- Create a ticketCreate a ticket
Function getCurvePoints
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
function getCurvePoints(x, y, r1, r2) {
var kappa = 4 * ((Math.sqrt(2) - 1) / 3);
var ox = (r1) * kappa, // control point offset horizontal
oy = (r2) * kappa, // control point offset vertical
xm = x + r1, // x-middle
- Create a ticketCreate a ticket
Function html2canvas
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
window.html2canvas = function(elements, opts) {
elements = (elements.length) ? elements : [elements];
var queue,
canvas,
options = {
- Create a ticketCreate a ticket
Function renderElement
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
function renderElement(element, parentStack, ignoreBackground) {
var transform = getTransform(element, parentStack),
bounds = getBounds(element, transform),
image,
stack = createStack(element, parentStack, bounds, transform),
- Create a ticketCreate a ticket
Function Support
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
_html2canvas.Util.Support = function (options, doc) {
function supportSVGRendering() {
var img = new Image(),
canvas = doc.createElement("canvas"),
- Create a ticketCreate a ticket
Function addPseudoElements
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
function addPseudoElements(el) {
// These are done in discrete steps to prevent a relayout loop caused by addClass() invalidating
// layouts & getPseudoElement calling getComputedStyle.
var jobs = [], classes = [];
getPseudoElementClasses();
- Create a ticketCreate a ticket
Function Font
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
_html2canvas.Util.Font = (function () {
var fontData = {};
return function(font, fontSize, doc) {
- Create a ticketCreate a ticket
Function Gradient
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
Generate.Gradient = function(src, bounds) {
if(bounds.width === 0 || bounds.height === 0) {
return;
}
- Create a ticketCreate a ticket
Function drawShape
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
drawShape: function() {
var shape = [];
storage.push({
- Create a ticketCreate a ticket
Function cleanupDOM
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
cleanupDOM: function(cause) {
var img, src;
if (!images.cleanupDone) {
if (cause && typeof cause === "string") {
Util.log("html2canvas: Cleanup because: " + cause);
- Create a ticketCreate a ticket
Function proxyGetImage
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
function proxyGetImage(url, img, imageObj){
var callback_name,
scriptUrl = options.proxy,
script;
- Create a ticketCreate a ticket
Function renderText
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
function renderText(el, textNode, stack) {
var ctx = stack.ctx,
color = getCSS(el, "color"),
textDecoration = getCSS(el, "textDecoration"),
textAlign = getCSS(el, "textAlign"),
- Create a ticketCreate a ticket
Function loadImage
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
loadImage: function( src ) {
var img, imageObj;
if ( src && images[src] === undefined ) {
img = new Image();
if ( src.match(/data:image\/.*;base64,/i) ) {
- Create a ticketCreate a ticket
Function renderItem
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
function renderItem(ctx, item) {
switch(item.type){
case "variable":
ctx[item.name] = item['arguments'];
break;
- Create a ticketCreate a ticket
Function renderFormValue
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
function renderFormValue (el, bounds, stack){
var valueWrap = doc.createElement('valuewrap'),
cssPropertyArray = ['lineHeight','textAlign','fontFamily','color','fontSize','paddingLeft','paddingTop','width','height','border','borderLeftWidth','borderTopWidth'],
textValue,
- Create a ticketCreate a ticket
Function renderBackgroundRepeating
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function renderBackgroundRepeating(el, bounds, ctx, image, imageIndex) {
var backgroundSize = Util.BackgroundSize(el, bounds, image, imageIndex),
backgroundPosition = Util.BackgroundPosition(el, bounds, image, imageIndex, backgroundSize),
backgroundRepeat = Util.BackgroundRepeat(el, imageIndex);
- Create a ticketCreate a ticket
Function Children
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
_html2canvas.Util.Children = function( elem ) {
var children;
try {
children = (elem.nodeName && elem.nodeName.toUpperCase() === "IFRAME") ? elem.contentDocument || elem.contentWindow.document : (function(array) {
var ret = [];
- Create a ticketCreate a ticket
Function buildStackingContext
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
rootContext = (function buildStackingContext(rootNode) {
var rootContext = {};
function insert(context, node, specialParent) {
var zi = (node.zIndex.zindex === 'auto') ? 0 : Number(node.zIndex.zindex),
contextForChildren = context, // the stacking context for children
- Create a ticketCreate a ticket
Function sortZ
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function sortZ(context) {
Object.keys(context).sort(sortZindex).forEach(function(zi) {
var nonPositioned = [],
floated = [],
positioned = [],
- Create a ticketCreate a ticket
Function setImageLoadHandlers
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function setImageLoadHandlers(img, imageObj) {
img.onload = function() {
if ( imageObj.timer !== undefined ) {
// CORS succeeded
window.clearTimeout( imageObj.timer );
- Create a ticketCreate a ticket
Function bezierCurve
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function bezierCurve(start, startControl, endControl, end) {
var lerp = function (a, b, t) {
return {
x:a.x + (b.x - a.x) * t,
- Create a ticketCreate a ticket
Function getPseudoElement
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function getPseudoElement(el, which) {
var elStyle = window.getComputedStyle(el, which);
var parentStyle = window.getComputedStyle(el);
// If no content attribute is present, the pseudo element is hidden,
// or the parent has a content property equal to the content on the pseudo element,
- Create a ticketCreate a ticket
Function parseChildren
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function parseChildren(element, stack, cb) {
var children = Util.Children(element);
// After all nodes have processed, finished() will call the cb.
// We add one and kick it off so this will still work when children.length === 0.
// Note that unless async is true, this will happen synchronously, just will callbacks.
- Create a ticketCreate a ticket
Function backgroundRepeatShape
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
function backgroundRepeatShape(ctx, image, backgroundPosition, bounds, left, top, width, height) {
- Create a ticketCreate a ticket
Function parseCorner
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
function parseCorner(borderArgs, radius1, radius2, corner1, corner2, x, y) {
- Create a ticketCreate a ticket
Function drawSide
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
function drawSide(borderData, radius1, radius2, outer1, inner1, outer2, inner2) {
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if(m3[1] === 'to') {
stop = 1.0;
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if(m3[2]){
stop = parseFloat(m3[2]);
if(m3[3] === '%'){
stop /= 100;
} else { // px - stupid opera
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (img.script && img.script.parentNode) {
img.script.setAttribute("src", "about:blank"); // try to cancel running request
img.script.parentNode.removeChild(img.script);
}
- Create a ticketCreate a ticket
Function renderRect
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function renderRect (ctx, x, y, w, h, bgcolor) {
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if(m3[1] === 'from') {
stop = 0.0;
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if(m3[2]){
stop = parseFloat(m3[2]);
if(m3[3] === '%'){
stop /= 100;
} else { // px - stupid opera
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if(m2[0] === 'circle'){
gradient.rx = gradient.ry = Math.min(
gradient.cx,
gradient.cy,
gradient.x1 - gradient.cx,
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if(m3[2]){
stop = parseFloat(m3[2]);
if(m3[3]){ // percentage
stop /= 100;
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if(m2[0] === 'circle'){
gradient.rx = gradient.ry = Math.max(
gradient.cx,
gradient.cy,
gradient.x1 - gradient.cx,
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
switch(m2[i]) {
case 'top':
gradient.y0 = 0;
gradient.y1 = bounds.height;
break;
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if(!elStyle || !elStyle.content || elStyle.content === "none" || elStyle.content === "-moz-alt-content" ||
elStyle.display === "none" || parentStyle.content === elStyle.content) {
return;
}
- Create a ticketCreate a ticket
Function getTextBounds
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function getTextBounds(state, text, textDecoration, isLast, transform) {
- Create a ticketCreate a ticket
Function getBorderClip
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function getBorderClip(element, borderPoints, borders, radius, bounds) {
- Create a ticketCreate a ticket
Function renderBackgroundRepeating
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function renderBackgroundRepeating(el, bounds, ctx, image, imageIndex) {
- Create a ticketCreate a ticket
Function BackgroundPosition
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
_html2canvas.Util.BackgroundPosition = function(element, bounds, image, imageIndex, backgroundSize ) {
- Create a ticketCreate a ticket
Function renderTextDecoration
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function renderTextDecoration(ctx, text_decoration, bounds, metrics, color) {
- Create a ticketCreate a ticket
Function renderImage
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function renderImage(ctx, element, image, bounds, borders) {
- Create a ticketCreate a ticket
Function resizeBounds
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
_html2canvas.Util.resizeBounds = function( current_width, current_height, target_width, target_height, stretch_mode ){
- Create a ticketCreate a ticket
Identical blocks of code found in 3 locations. Consider refactoring. Open
(function(window, document, undefined){
//"use strict";
var _html2canvas = {},
- Read upRead up
- Create a ticketCreate a ticket
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 25895.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76