/* https://github.com/DiemenDesign/summernote-image-captionit */
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'],factory)
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('jquery'));
} else {
factory(window.jQuery)
}
}
(function ($) {
$.extend(true,$.summernote.lang, {
'en-US': {
captionIt: {
tooltip: 'Caption It'
}
}
});
$.extend($.summernote.options, {
captionIt: {
icon: '',
figureClass: '',
figcaptionClass: '',
captionText: 'Caption Goes Here.'
}
});
$.extend($.summernote.plugins, {
'captionIt': function(context) {
var ui = $.summernote.ui,
$editable = context.layoutInfo.editable,
options = context.options,
lang = options.langInfo;
context.memo('button.captionIt', function () {
var button=ui.button({
contents: options.captionIt.icon,
container: options.container,
tooltip: lang.captionIt.tooltip,
placement: options.placement,
click: function () {
var img = $($editable.data('target'));
var $parentAnchorLink = img.parent();
if ($parentAnchorLink.parent('figure').length) {
$parentAnchorLink.next('figcaption').remove();
$parentAnchorLink.unwrap('figure');
} else {
var titleText = img.attr('title'),
altText = img.attr('alt'),
classList = img.attr('class'),
inlineStyles = img.attr('style'),
classList = img.attr('class'),
inlineStyles = img.attr('style'),
imgWidth = img.width(),
captionText = '';
if (titleText) {
captionText = titleText;
} else if (altText) {
captionText = altText;
} else {
captionText = options.captionIt.captionText;
}
if ($parentAnchorLink.is('a')) {
$newFigure = $parentAnchorLink.wrap('').parent();
$newFigure.append('').parent();
img.after('' + captionText + '');
$newFigure.width(imgWidth);
}
}
}
});
return button.render();
});
}
});
}));