diff --git a/dataviva/static/css/modules/blog.css b/dataviva/static/css/modules/blog.css index 465eb5bf1..b605944ad 100644 --- a/dataviva/static/css/modules/blog.css +++ b/dataviva/static/css/modules/blog.css @@ -230,7 +230,7 @@ font-size: 12px; } .blog .note-editor img, .blog figure { - margin: 20px 20px 10px 20px; + margin: 20px; text-align: center; } .blog .dual-lang-field { diff --git a/dataviva/static/css/modules/news.css b/dataviva/static/css/modules/news.css index 0f22d3845..4f3f6d1ac 100644 --- a/dataviva/static/css/modules/news.css +++ b/dataviva/static/css/modules/news.css @@ -194,7 +194,7 @@ } .news .note-editor img, .news figure { - margin: 20px 20px 10px 20px; + margin: 20px; text-align: center; } diff --git a/dataviva/static/js/base.js b/dataviva/static/js/base.js index 3857c7e70..abf2a0199 100755 --- a/dataviva/static/js/base.js +++ b/dataviva/static/js/base.js @@ -121,7 +121,7 @@ var summernoteConfig = { ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['table', ['table']], - ['insert', ['link', 'picture', 'video']], + ['insert', ['link', 'picture', 'chart', 'video']], ['view', ['fullscreen', 'codeview', 'help']] ], popover: { diff --git a/dataviva/static/js/modules/blog/form.js b/dataviva/static/js/modules/blog/form.js index fda28785e..93b85cfcf 100644 --- a/dataviva/static/js/modules/blog/form.js +++ b/dataviva/static/js/modules/blog/form.js @@ -14,25 +14,29 @@ var inputThumbCallback = function() { } var add_caption = function(image) { + if (image.attr('src').trim() == "http://placehold.it/1600x900/FFFFFF?text=") + return; image.wrap('
'); figcaption = $('
'); if (image.attr('data-original-title')) figcaption.html(image.attr('data-original-title')); figcaption.appendTo(image.parent()); - var image_float = image.css('float'); - var image_width = image.css('width'); + var image_float = image.css('float'), + image_width = image.css('width'); if (image_float == 'left' || image_float == 'right') { image .css('float', 'none') .parent().css('float', image_float); } - image.parent().css('width', image_width); + image.parent().css('max-width', image_width); image.css('width', '100%'); } var remove_caption = function(image) { + if (image.attr('src').trim() == "http://placehold.it/1600x900/FFFFFF?text=") + return; image.siblings('figcaption').remove(); - var figure_width = image.parent().css('width'); + var figure_width = image.parent().css('max-width'); image.css('width', figure_width); var figure_float = image.parent().css('float'); if (figure_float == 'left' || figure_float == 'right') diff --git a/dataviva/static/js/modules/news/form.js b/dataviva/static/js/modules/news/form.js index eb4fb831e..256db464e 100644 --- a/dataviva/static/js/modules/news/form.js +++ b/dataviva/static/js/modules/news/form.js @@ -14,25 +14,29 @@ var inputThumbCallback = function() { } var add_caption = function(image) { + if (image.attr('src').trim() == "http://placehold.it/1600x900/FFFFFF?text=") + return; image.wrap('
'); figcaption = $('
'); if (image.attr('data-original-title')) figcaption.html(image.attr('data-original-title')); figcaption.appendTo(image.parent()); - var image_float = image.css('float'); - var image_width = image.css('width'); + var image_float = image.css('float'), + image_width = image.css('width'); if (image_float == 'left' || image_float == 'right') { image .css('float', 'none') .parent().css('float', image_float); } - image.parent().css('width', image_width); + image.parent().css('max-width', image_width); image.css('width', '100%'); } var remove_caption = function(image) { + if (image.attr('src').trim() == "http://placehold.it/1600x900/FFFFFF?text=") + return; image.siblings('figcaption').remove(); - var figure_width = image.parent().css('width'); + var figure_width = image.parent().css('max-width'); image.css('width', figure_width); var figure_float = image.parent().css('float'); if (figure_float == 'left' || figure_float == 'right') diff --git a/dataviva/static/js/plugins/summernote/summernote-insert-embedded-chart.js b/dataviva/static/js/plugins/summernote/summernote-insert-embedded-chart.js new file mode 100644 index 000000000..be684d1c8 --- /dev/null +++ b/dataviva/static/js/plugins/summernote/summernote-insert-embedded-chart.js @@ -0,0 +1,178 @@ +function doGetCaretPosition (ctrl) { + var CaretPos = 0; // IE Support + if (document.selection) { + ctrl.focus (); + var Sel = document.selection.createRange (); + Sel.moveStart ('character', -ctrl.value.length); + CaretPos = Sel.text.length; + } + + // Firefox support + else if (ctrl.selectionStart || ctrl.selectionStart == '0') + CaretPos = ctrl.selectionStart; + return (CaretPos); + } + +(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($){ + var text = { + 'pt': { + edit: 'Inserir visualização', + titleLabel: 'Visualização com iframe', + tooltip: 'Visualização' + }, + 'en': { + edit: 'Insert visualization', + titleLabel: 'Visualization with iframe', + tooltip: 'Visualization' + } + }; + + $.extend($.summernote.plugins,{ + 'chart':function(context){ + var self=this; + var ui=$.summernote.ui; + var $note=context.layoutInfo.note; + var $editor=context.layoutInfo.editor; + + if (typeof context.options.imageTitle === 'undefined') { + context.options.imageTitle = {}; + } + + if (typeof context.options.imageTitle.specificAltField === 'undefined') { + context.options.imageTitle.specificAltField = false; + } + + var options = context.options; + + context.memo('button.chart', function () { + var button = ui.button({ + contents: '', + tooltip: text[dataviva.language].tooltip, + click: function (e) { + context.invoke('chart.show'); + } + }); + + return button.render(); + }); + + this.initialize = function () { + var $container = options.dialogsInBody ? $(document.body) : $editor; + + var body = '
' + + '' + + '' + + '
'; + + var footer = ''; + + this.$dialog = ui.dialog({ + title: text[dataviva.language].edit, + body: body, + footer: footer + }).render().appendTo($container); + }; + + this.destroy = function () { + ui.hideDialog(this.$dialog); + + this.$dialog.remove(); + }; + + this.show = function () { + + var urlInfo; + + this.showLinkDialog(urlInfo).then(function (urlInfo) { + ui.hideDialog(self.$dialog); + + context.invoke('focus'); + + // Creating a wrapper to embed the chart + var chart = document.createElement('div'), + wrapper = document.createElement('div'), + img = document.createElement('img'), + iframe = document.createElement('iframe'); + + img.src = "http://placehold.it/1600x900/FFFFFF?text= "; + + resquest_iframe = urlInfo.url; + + if (resquest_iframe.lenght != 0){ + iframe = $.parseHTML(resquest_iframe)[0]; + + // If iframe wasn't embedded + if (iframe.nodeName != "IFRAME") { + var url = iframe; + iframe = document.createElement('iframe'); + iframe.src = url.wholeText; + } + + // remove width/height if the iframe already have + $(iframe).removeAttr('width', 'height'); + + chart.style = "width:auto; height:auto; margin:0 auto;"; + img.style = "display:block; width:100%; height:auto;"; + wrapper.style.position = "relative"; + iframe.style = "position:absolute; top:0; left:0; width:100%; height:100%;"; + + wrapper.appendChild(img); + wrapper.appendChild(iframe); + chart.appendChild(wrapper); + + context.invoke('editor.restoreRange'); + context.invoke('editor.focus'); + + // Inserting in summernote html + context.invoke('editor.insertNode', chart); + + $note.val(context.invoke('code')); + $note.change(); + } + }); + }; + + this.showLinkDialog = function (urlInfo) { + return $.Deferred(function (deferred) { + var $url = self.$dialog.find('.note-image-title-text'), + $editBtn = self.$dialog.find('.note-image-title-btn'); + + ui.onDialogShown(self.$dialog, function () { + context.triggerEvent('dialog.shown'); + + context.invoke('editor.saveRange'); + + $url.val('').trigger('focus'); + + $editBtn.click(function (event) { + event.preventDefault(); + deferred.resolve({ + url: $url.val(), + }); + }) + }); + + + ui.onDialogHidden(self.$dialog, function () { + $editBtn.off('click'); + + if (deferred.state() === 'pending') { + deferred.reject(); + } + }); + + ui.showDialog(self.$dialog); + }); + }; + } + }); +})); \ No newline at end of file diff --git a/dataviva/templates/base.html b/dataviva/templates/base.html index 0e0d8326e..9ed360163 100644 --- a/dataviva/templates/base.html +++ b/dataviva/templates/base.html @@ -105,6 +105,7 @@ + {% if g.locale == 'pt' %} {% endif %}