/home/techb158/immovalet.com/vendor/botble/platform/media/resources/assets/js
Edit: /home/techb158/immovalet.com/vendor/botble/platform/media/resources/assets/js/jquery.addMedia.js (5825B)
/* ========================================================================
* AddMedia.js v1.0
* Requires Botble Media
* ======================================================================== */
+function ($) {
'use strict';
/**
* @param element
* @param options
* @constructor
*/
let AddMedia = function (element, options) {
this.options = options;
$(element).rvMedia({
multiple: true,
onSelectFiles: function (files, $el) {
if (typeof files !== 'undefined') {
switch ($el.data('editor')) {
case 'summernote':
handleInsertImagesForSummerNote($el, files);
break;
case 'wysihtml5':
let editor = $(options.target).data('wysihtml5').editor;
handleInsertImagesForWysihtml5Editor(editor, files);
break;
case 'ckeditor':
handleForCkeditor($el, files);
break;
case 'tinymce':
handleForTinyMce(files);
break;
}
}
}
});
};
AddMedia.VERSION = '1.1.0';
/**
* Insert images to summernote editor
* @param $el
* @param files
*/
function handleInsertImagesForSummerNote($el, files) {
if (files.length === 0) {
return;
}
let instance = $el.data('target');
for (let i = 0; i < files.length; i++) {
if (files[i].type === 'video') {
let link = files[i].full_url;
link = link.replace('watch?v=', 'embed/');
$(instance).summernote('pasteHTML', '
');
} else if (files[i].type === 'image') {
$(instance).summernote('insertImage', files[i].full_url, files[i].basename);
} else {
$(instance).summernote('pasteHTML', '
' + files[i].full_url + '');
}
}
}
/**
* Insert images to Wysihtml5 editor
* @param editor
* @param files
*/
function handleInsertImagesForWysihtml5Editor(editor, files) {
if (files.length === 0) {
return;
}
// insert images for the wysihtml5 editor
let s = '';
for (let i = 0; i < files.length; i++) {
if (files[i].type === 'video') {
let link = files[i].full_url;
link = link.replace('watch?v=', 'embed/');
s += '
';
} else if (files[i].type === 'image') {
s += '
![' + files[i].name + '](' + files[i].full_url + ')
';
} else {
s += '
' + files[i].full_url + '';
}
}
if (editor.getValue().length > 0) {
let length = editor.getValue();
editor.composer.commands.exec('insertHTML', s);
if (editor.getValue() === length) {
editor.setValue(editor.getValue() + s);
}
} else {
editor.setValue(editor.getValue() + s);
}
}
/**
* @param $el
* @param files
*/
function handleForCkeditor($el, files) {
let instance = $el.data('target').replace('#', '');
let content = '';
$.each(files, (index, file) => {
let link = file.full_url;
if (file.type === 'youtube') {
link = link.replace('watch?v=', 'embed/');
content += '
';
} else if (file.type === 'image') {
content += '

';
} else {
content += '
' + file.name + '';
}
});
CKEDITOR.instances[instance].insertHtml(content);
}
/**
* @param files
*/
function handleForTinyMce(files) {
let html = '';
$.each(files, (index, file) => {
let link = file.full_url;
if (file.type === 'youtube') {
link = link.replace('watch?v=', 'embed/');
html += '
';
} else if (file.type === 'image') {
html += '

';
} else {
html += '
' + file.name + '';
}
});
tinymce.activeEditor.execCommand('mceInsertContent', false, html);
}
/**
* @param option
*/
function callAction(option) {
return this.each(function () {
let $this = $(this);
let data = $this.data('bs.media');
let options = $.extend({}, $this.data(), typeof option === 'object' && option);
if (!data) {
$this.data('bs.media', (new AddMedia(this, options)));
}
})
}
$.fn.addMedia = callAction;
$.fn.addMedia.Constructor = AddMedia;
$(window).on('load', function () {
$('[data-type="rv-media"]').each(function () {
let $addMedia = $(this);
callAction.call($addMedia, $addMedia.data());
});
});
}(jQuery);