Skip to content

Commit

Permalink
feat: Update "printScreen" to html2canvas 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mickjol committed Jan 22, 2018
1 parent ef0811a commit fa3b5a4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 54 deletions.
46 changes: 19 additions & 27 deletions js/cause.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var cause = {
googleMaps: '3', // Maps
jPlayer: '2.9.2', // Video player
jsZip: '3.1.2', // Zip generator
html2canvas: '0.5.0', // Image generator
html2canvas: '1.0.0', // Image generator
pdfjs: '1.6.210', // PDF viewer
psdjs: '3.1.0', // PSD viewer
recordRTC: '5.4.0', // Audio recording
Expand Down Expand Up @@ -7484,58 +7484,50 @@ cause.objects.printScreen = function (element, params) {
element = document.body;
}

this.name = 'print_screen';
this.name = 'printScreen';
this.element = element;
this.options = cause.extend({}, params);

/* Initialize the addons "html2canvas" */
this.options.onrendered = this.onRendered.bind(this, (params || {}));

if (!cause.helpIsOn) {
if (typeof(html2canvas) == 'object') {
html2canvas(this.element, this.options);
html2canvas(this.element, this.options).then(this.onRendered.bind(this));
} else {
cause.include.js(cause.baseUrlPlugins + 'html2canvas/' + cause.version.html2canvas + '/html2canvas.min.js', (function () {
html2canvas(this.element, this.options);
html2canvas(this.element, this.options).then(this.onRendered.bind(this));
}).bind(this), function () {
cause.alert(cause.localize('missingPlugins'), 'html2canvas ' + cause.version.html2canvas);
});
}
}
};

/** Show help when is cause.help('print_screen') is call.
/** Show help when is cause.help('printScreen') is call.
*
* @memberOf cause.objects.printScreen
*/
cause.objects.printScreen.prototype.help = function () {
cause.log('Aide pour "cause.print_screen":', 'help_title');
cause.log("\t" +
'new cause.print_screen();', 'help');
cause.log('Aide pour "cause.objects.printScreen":', 'help_title');
cause.log("\t" + 'new cause.objects.printScreen();', 'help');
};

/** Executed when the rendering of print screen is finish.
*
* @memberOf cause.objects.printScreen
* @param {object} params: Object with all options pass to addons
* @param {HTMLElement} canvas: The canvas with the image of screen
*/
cause.objects.printScreen.prototype.onRendered = function (params, canvas) {
if (params.width) {
canvas.style.width = params.width + 'px';
}
if (params.height) {
canvas.style.height = params.height + 'px';
}

if (typeof(params.onrendered) == 'function') {
params.onrendered(canvas);
} else if (typeof(params.success) == 'function') {
params.success(canvas);
} else if (params.download) {
cause.$('<a>').attr('href', canvas.toDataURL()).attr('download', 'cause_print_screen.png').get(0).click();
} else if (params.insert) {
cause.$(canvas).appendTo(params.insert);
cause.objects.printScreen.prototype.onRendered = function (canvas) {
if (typeof(this.options.onrendered) == 'function') {
this.options.onrendered(canvas);
} else if (typeof(this.options.success) == 'function') {
this.options.success(canvas);
} else if (this.options.download) {
var name = (typeof(this.options.download) == 'string' ? this.options.download : 'cause_print_screen.png');

name += (name.includes('.png') ? '' : '.png');
cause.$('<a>').attr('href', canvas.toDataURL()).attr('download', name).get(0).click();
} else if (this.options.insert) {
cause.$(canvas).appendTo(this.options.insert);
}
};/** Class for helping with media recording.
*
Expand Down
2 changes: 1 addition & 1 deletion js/cause.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/uncompressed/1-cause.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var cause = {
googleMaps: '3', // Maps
jPlayer: '2.9.2', // Video player
jsZip: '3.1.2', // Zip generator
html2canvas: '0.5.0', // Image generator
html2canvas: '1.0.0', // Image generator
pdfjs: '1.6.210', // PDF viewer
psdjs: '3.1.0', // PSD viewer
recordRTC: '5.4.0', // Audio recording
Expand Down
42 changes: 17 additions & 25 deletions js/uncompressed/externalPlugins/print-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,49 @@ cause.objects.printScreen = function (element, params) {
element = document.body;
}

this.name = 'print_screen';
this.name = 'printScreen';
this.element = element;
this.options = cause.extend({}, params);

/* Initialize the addons "html2canvas" */
this.options.onrendered = this.onRendered.bind(this, (params || {}));

if (!cause.helpIsOn) {
if (typeof(html2canvas) == 'object') {
html2canvas(this.element, this.options);
html2canvas(this.element, this.options).then(this.onRendered.bind(this));
} else {
cause.include.js(cause.baseUrlPlugins + 'html2canvas/' + cause.version.html2canvas + '/html2canvas.min.js', (function () {
html2canvas(this.element, this.options);
html2canvas(this.element, this.options).then(this.onRendered.bind(this));
}).bind(this), function () {
cause.alert(cause.localize('missingPlugins'), 'html2canvas ' + cause.version.html2canvas);
});
}
}
};

/** Show help when is cause.help('print_screen') is call.
/** Show help when is cause.help('printScreen') is call.
*
* @memberOf cause.objects.printScreen
*/
cause.objects.printScreen.prototype.help = function () {
cause.log('Aide pour "cause.print_screen":', 'help_title');
cause.log("\t" +
'new cause.print_screen();', 'help');
cause.log('Aide pour "cause.objects.printScreen":', 'help_title');
cause.log("\t" + 'new cause.objects.printScreen();', 'help');
};

/** Executed when the rendering of print screen is finish.
*
* @memberOf cause.objects.printScreen
* @param {object} params: Object with all options pass to addons
* @param {HTMLElement} canvas: The canvas with the image of screen
*/
cause.objects.printScreen.prototype.onRendered = function (params, canvas) {
if (params.width) {
canvas.style.width = params.width + 'px';
}
if (params.height) {
canvas.style.height = params.height + 'px';
}
cause.objects.printScreen.prototype.onRendered = function (canvas) {
if (typeof(this.options.onrendered) == 'function') {
this.options.onrendered(canvas);
} else if (typeof(this.options.success) == 'function') {
this.options.success(canvas);
} else if (this.options.download) {
var name = (typeof(this.options.download) == 'string' ? this.options.download : 'cause_print_screen.png');

if (typeof(params.onrendered) == 'function') {
params.onrendered(canvas);
} else if (typeof(params.success) == 'function') {
params.success(canvas);
} else if (params.download) {
cause.$('<a>').attr('href', canvas.toDataURL()).attr('download', 'cause_print_screen.png').get(0).click();
} else if (params.insert) {
cause.$(canvas).appendTo(params.insert);
name += (name.includes('.png') ? '' : '.png');
cause.$('<a>').attr('href', canvas.toDataURL()).attr('download', name).get(0).click();
} else if (this.options.insert) {
cause.$(canvas).appendTo(this.options.insert);
}
};

0 comments on commit fa3b5a4

Please sign in to comment.