Loading and Saving - carstenschaefer/ImagerJs GitHub Wiki
Specifies how and where ImagerJs will store its data. It is only needed when data should be saved locally.
Configuration
contentConfig: {
saveImageData: saveFunction,
loadImageData: loadFunction
}
Standalone Version
var options = {
plugins: ['Rotate', 'Crop', 'Resize', 'Toolbar', 'Save', 'Delete'],
contentConfig: {
saveImageData: function (imageId, imageData) {
try {
localStorage.setItem('image_' + imageId, imageData);
} catch (err) {
console.error(err);
}
}
}
};
Redactor Version
var imagerOptions = {
plugins: ['Rotate', 'Crop', 'Resize', 'Toolbar', 'Save', 'Delete'],
waitingCursor: 'wait'
};
$('.redactor').redactor({
plugins: ['ImagerJs'],
ImagerJs: {
contentConfig: {
saveImageData: function (imageId, imageData) {
try {
localStorage.setItem('image_' + imageId, imageData);
} catch (err) {
console.error(err);
}
},
loadImageData: function (imageId) {
return localStorage.getItem('image_' + imageId);
}
},
hideFileSelection: true,
redactor: imagerOptions,
preview: imagerOptions
}
});
var save = function () {
var content = $('.redactor').redactor('code.get');
localStorage.setItem('content', content);
console.log(content);
};
var load = function () {
// firstly clean all content from redactor
$('.redactor').redactor('code.set', '');
$('.redactor').redactor('code.startSync');
var content = localStorage.getItem('content');
$('.redactor').redactor('code.set', content);
};
saveImageData
:
- Specifies a function that will be called when a ImagerJs element needs to save base64/png image data.
loadImageData
:
- Specifies a function that will be called when a ImagerJs element needs to load base64/png image data.