Skip to content

Commit

Permalink
Merge pull request #1290 from DataViva/fix/#1283
Browse files Browse the repository at this point in the history
Fix/#1283
  • Loading branch information
litodaldegan authored Oct 5, 2016
2 parents f60e89e + beb0422 commit 36accab
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dataviva/static/css/modules/blog.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion dataviva/static/css/modules/news.css
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
}

.news .note-editor img, .news figure {
margin: 20px 20px 10px 20px;
margin: 20px;
text-align: center;
}

Expand Down
2 changes: 1 addition & 1 deletion dataviva/static/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
12 changes: 8 additions & 4 deletions dataviva/static/js/modules/blog/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<figure> </figure>');
figcaption = $('<figcaption> </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')
Expand Down
12 changes: 8 additions & 4 deletions dataviva/static/js/modules/news/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<figure> </figure>');
figcaption = $('<figcaption> </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')
Expand Down
Original file line number Diff line number Diff line change
@@ -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: '<i class="fa fa-area-chart" aria-hidden="true"></i>',
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 = '<div class="form-group">' +
'<label>' + text[dataviva.language].titleLabel + '</label>' +
'<input class="note-image-title-text form-control" type="text" />' +
'</div>';

var footer = '<button href="#" class="btn btn-primary note-image-title-btn">' + text[dataviva.language].edit + '</button>';

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);
});
};
}
});
}));
1 change: 1 addition & 0 deletions dataviva/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<script type="text/javascript" src="/static/js/plugins/jquery.jcarousel.js"></script>
<script type="text/javascript" src="/static/js/plugins/summernote/summernote.js"></script>
<script type="text/javascript" src="/static/js/plugins/summernote/summernote-image-title.js"></script>
<script type="text/javascript" src="/static/js/plugins/summernote/summernote-insert-embedded-chart.js"></script>
{% if g.locale == 'pt' %}
<script type="text/javascript" src="/static/js/plugins/summernote/summernote-pt-BR.js"></script>
{% endif %}
Expand Down

0 comments on commit 36accab

Please sign in to comment.