ckeditor dialog and widget not working properly - ckeditor

In the ckeditor (plugin.js) I have this code below.
CKEDITOR.plugins.add( 'beforeafter', {
requires: 'widget',
icons: 'beforeafter',
init: function( editor ) {
editor.widgets.add( 'beforeafter', {
button: 'beforeafter',
template:
'<div class="ba-slider-element">' +
'<div class="ba-slider">' +
'<div class="resize">' +
'<div class="handle">' +
'</div>',
dialog: 'beforeafterDialog',
upcast: function( element ) {
return element.name == 'div' && element.hasClass( 'ba-slider' );
}
} );
// Define an editor command that opens our dialog window.
editor.addCommand( 'beforeafter', new CKEDITOR.dialogCommand( 'beforeafterDialog' ) );
// Create a toolbar button that executes the above command.
editor.ui.addButton( 'beforeafter', {
// The text part of the button (if available) and the tooltip.
label: 'Insert A Before And After Image',
// The command to execute on click.
command: 'beforeafter',
// The button placement in the toolbar (toolbar group name).
toolbar: 'insert'
});
// Register our dialog file -- this.path is the plugin folder path.
CKEDITOR.dialog.add( 'beforeafterDialog', this.path + 'dialogs/beforeafter.js' );
}
});
In the dialog file (beforeafter.js) I have this code below.
CKEDITOR.dialog.add( 'beforeafterDialog', function( editor ) {
return {
title: 'Before and After Image Tool',
minWidth: 400,
minHeight: 200,
contents: [
{
id: 'tab-basic',
label: 'Basic Settings',
// The tab content.
elements: [
{
type: 'text',
id: 'beforeimage',
label: 'paste your BEFORE image URL below',
validate: CKEDITOR.dialog.validate.notEmpty( "Please add a URL in the Before image field." )
},
{
type: 'text',
id: 'afterimage',
label: 'paste your AFTER image URL below',
validate: CKEDITOR.dialog.validate.notEmpty( "Please add a URL in the After image field." )
}
]
},
],
onOk: function() {
var dialog = this;
var result = editor.document.createElement('div');
result.setHtml("<div class=\"ba-slider-element\">\n" +
"<div class=\"ba-slider\">\n" +
"<img src=\"" + dialog.getValueOf( 'tab-basic', 'beforeimage' ) + "\" alt=\"\">\n" +
"<div overlay-lable=\"Before\" class=\"before-lable-1\">\n" +
"<div overlay-lable=\"Before\" class=\"before-lable-2\">\n" +
"<div class=\"resize\">\n" +
"<img src=\"" + dialog.getValueOf( 'tab-basic', 'afterimage' ) + "\" alt=\"\">\n" +
"<div overlay-lable=\"After\" class=\"after-lable-1\">\n" +
"</div>\n" +
"<div overlay-lable=\"After\" class=\"after-lable-2\"></div></div>\n" +
"<div class=\"handle\">\n" +
"</div>");
editor.insertElement( result );
}
};
});
In the ckeditor posting edit window, when I click the source button to view the source, this is the code that is generated below.
<div>
<div class="ba-slider-element">
<div class="ba-slider">
<img alt="" src="https://pepsized.com/wp-content/uploads/2018/09/beerslider/demo-assets/images/man-hold-beer.jpg">
<div overlay-lable="Before" class="before-lable-1">
<div overlay-lable="Before" class="before-lable-2">
<div class="resize">
<img alt="" src="https://pepsized.com/wp-content/uploads/2018/09/beerslider/demo-assets/images/man-hold-beer-after1logo.jpg">
<div overlay-lable="After" class="after-lable-1">
</div>
<div overlay-lable="After" class="after-lable-2">
</div>
</div>
<div class="handle">
</div>
</div>
</div>
</div>
</div>
The slider works fine but I am not able to edit the URL fields.
When I double click the slider to edit it the dialog window will pop up with an empty URL fields.
ckeditor diolog
What I need help with is.
1. I need the element to highlight in yellow and blue when I hover over the area
2. When I double click to edit, the dialog fields should show the previous inputted URL.
3. How would be able to preview the slider wile in edit mode. the slider use jquery script.
Your help will be truly appreciated.

Related

Make 'export to excel' button in DataTable for Laravel

I want to ask if someone know about 'export to excel' button in Laravel. I need to use the button inside the DataTable beside 'export pdf' button. Can someone help me to make the button function properly.
First pic is the controller for 'export' 1
if(!empty($request['export']))
{
return Excel::download(new ExcelExport($start_date, $end_date, $staff_name), 'Laporan Pegawai Tidak Aktif.xls');
}
Sec pic is the blade for DataTable script 2
$(function () {
$('#staffs').DataTable({
dom:
"<'row'<'col-sm-5'l><'col-sm-4 text-center'B><'col-sm-3'f>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
buttons: [{
extend : 'pdfHtml5',
text: '<i class="fa fa-file-pdf-o"></i> Export PDF',
className: 'btn btn-default',
title: "Senarai Pegawai Tidak Aktif",
exportOptions:
{
columns: ':visible:not(.not-exported)'
},
},
{
extend : 'excelHtml5',
text: '<i class="fa fa-file-excel-o"></i> Export Excel',
className: 'btn btn-default',
name:'export',
text: function (dt)
{
return '<i class="fa fa-file-excel-o"></i> ' + ('buttons.excel', 'Export Excel');
},
action: function (e, dt, button, config)
{
var url = dt.ajax.url() || window.location.href;
var params = _buildParams(dt, 'excel');
_downloadFromUrl(url, params);
}
}
],
*help me to check whether the code for export excel is right or not
if you want to see an example of how to add export button in datatable then this link is the right place for you.
Larave Yajra DataTables

Shom image on hover over imageurl inside Kendo UI grid cell

Is it possible to display in some pop up or tooltip image when user make mouse over url that is displayed inside table cell.
I have made it for now like this and this display image inside cell:
{
field: 'image',
title: 'Image',
lockable: false,
template:
'<div class="tooltipcontent">' +
'<img src="' + '#= image #' + '" alt="" />' +
'</div>',
width: '300px'
}
I would do something like this:
<div id="grid"></div>
<script type="text/x-kendo-template" id="template">
<img style="width:100px" src="#=url#">
</script>
</div>
$("#grid").kendoGrid({...});
$("#grid").kendoTooltip({
filter: "td:nth-child(1)", //this filter selects the first column's cells
position: "right",
content: function(e) {
var dataItem = $("#grid").getKendoGrid().dataItem(e.target.closest("tr"));
return kendo.template($("#template").html())(dataItem);
}
}).data("kendoTooltip");
Example: Row template tooltip

jquery addon function not adding element to DOM in nw.js inside w2ui panel

I created this in fiddle to show what I'm trying to do in nw.js. This works just fine. 2 tabs get created dynamically at run-time just fine.
http://jsfiddle.net/fnbqupf4/
I port this over to my nw.js and I get an error when ace.edit() is called saying it can't find the element ID. When I look at the DOM in nw.js I see the tab and the editor is NOT created there. So the issue is the tab and editor div get created in the jsFiddle but not in the nw.js site.
Is there something with not being able to dynamically add elements to the DOM in nw.js?
$.fn.addEditorTab = function(name, tabName, contents) {
console.log("1");
$('ul', this).append('<li title="' + name + '">' + tabName + '<span class="ui-icon ui-icon-close" role="presentation"></li>');
$(this).append("<div id='tab-" + name + "'><div id='editor-" + name + "' class='editor'></div></div>");
$(this).tabs("refresh");
console.log("2");
var editor = ace.edit("editor-" + name);
console.log("3");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/lua");
editor.setOptions({
maxLines: Infinity
});
editor.getSession().setValue(contents);
return editor;
};
[EDIT]
After some more messing around it seems it's only an issue when I have the tabs div inside a panel in w2ui.
$('#layout').w2layout({
name: 'layout',
panels: [
{ type: 'top', size: 50, style: pstyle, content: 'top', resizable: true },
{ type: 'left', size: 300, style: pstyle, content: '<div id="sidebar" style="height: 100%; width: 100%;"></div>', resizable: true }
//{ type: 'main', style: pstyle, content: '<div id="editor"></div>' }
{ type: 'main', style: pstyle, content: '<div id="tabs"><ul></ul></div>' }
]
});

How to put an if condition under columns in kendo grid

Can we add a if Condition inside the column while describing the columns of the grid? Whats wrong in this code
I want to display one button in the grid under a column ,if length of the text exceeds more than 40char.
I am trying to put an if condition if the content/data is less than 40 char then display the content else display a button , On click of button open a pop-up to display the complete content inside that pop-up?
How we can put the command conditionally to display the button?
Here is my code
columns: [{
field: "id",
title: "ID",
width: "100px"
}, // fields in the grid
{
field: "name",
title: "Name",
width: "100px"
}, {
field: "remarks",
title: "Remarks",
width: "160px", // under this column button will be displayed in each
var length = 40;
if (data.remarks.length > length) { //here this condition seems to be wrong, is there any other way to display the button for this condition
command: {
name: "remarks",
text: "Remarks",
click: function (e) {
var tr = $(e.target).closest("tr");
var data = this.dataItem(tr);
var win = $('#remarksWindow');
win.html(data.remarks);
if (!win.data('kendoWindow')) {
win.kendoWindow({
width: '600px',
height: '200px',
title: 'Remarks',
actions: ['Close']
});
}
win.parent().css({
top: e.pageY - 50,
left: e.clientX - 640,
width: '600px',
height: '200px'
});
win.data('kendoWindow').open(); // open the pop-up which contains the data
return false;
}
}
}
}
},
First of all, you have a syntax error in JavaScript. Note that you can't put statements or declarations between the properties of an object:
var obj = {
a: 1,
if (true) {
b: 2;
}
}
Or
var obj = {
a: 1,
var b = 1;
}
The examples above doesn't works. So in your column property you have to use a template property:
{
field: "remarks",
title: "Remarks",
width: "160px",
template: "" // <- here goes your logic
}
So a simple template can be set as a string containing html with JavaScript logic, e.g.:
# if (remarks.length > 40) { # <input type='button' class='btn-remarks' /> # } #
Yes, you will have to set the button html by yourself. There is no way to add a condition to a command button(and that is a shame, actually).
You can check how template works here.
Then your column item should be:
{
field: "remarks",
title: "Remarks",
width: "160px",
template: "# if (remarks.length > 40) { # <input type='button' class='remarks' /> # } #"
}
Then you have to set the event for all your buttons(probably in the dataBound event):
$("#yourGrid").on("click", ".btn-remarks", function()
{
// all your click logic here
});
Give it a try and tell me what happens.
Hopefully this dojo is what you are looking for: http://dojo.telerik.com/ETora
(I have used one of Telerik's grid demos and modified to show you the principles)
The functionality you are looking for can be achieved by two means:
1) Apply a client Template to the column
2) Add a databound event that then hooks up the buttons
columns:[ {
field: "CompanyName",
title: "Company Name",
template: "#= displayTextorButton(data.CompanyName) #"
}]
function displayTextorButton(data){
var retString = '';
console.log(data);
if(data !== null && data !== undefined)
{
if(data.length > 20)
{
retString = ' <button type="button" class="btn btn-xs btn-primary"' +
'data-toggle="popover" data-placement="auto right" data-container="body" ' +
'data-content="' + kendo.htmlEncode(data) + '"' +
'data-title="Running Log Information" data-trigger="click" data-role-me="content-popover" > <span class="glyphicons glyphicons-pencil"></span> View</button>';
}
else
{
retString = '<span>' + data + '</span>';
}
}else
{
retString = '<span> - </span>';
}
return retString;
}
so the first bit I have done is added a template to the Company Name column that checks if the name is more than 20 characters if it is then it will display a button if it isn't then it will display the text as normal.
function(e){
$('button[data-role-me="content-popover"]').popover({ trigger: "focus", html: true });
}
I then hook up a databound event to the grid to then attach the event features to the "pop up" in my sample
Also note I have hooked in the bootstrap features just to make things a little easier for the demo. So this is using their popover feature. You could modify this code to work with your window.
Any issues let me know.
This is the kendo grid code
{ field: "marks", title: "marks",width: "160px",
template: function(dataItem) {
var marks = dataItem.marks;
var retString = '';
if(marks !== null && marks !== undefined)
{
if(marks.length > 40)
{
marks1 = marks.substring(0, 40)+'...';
retString1 ='<span>'+ marks1 +'</span>';
retString = retString1 + ' <button id="marksButton" type="button"' +
'data-toggle="popover" data-placement="auto right" data-container="body" ' +
'data-content="' + kendo.htmlEncode(addlRemarks) + '"' +
'data-title="marks" data-trigger="click" data-role-me="content-popover" > marks</button>';
}
else
{
retString = '<span>' + marks + '</span>';
}
}else
{
retString = '<span> - </span>';
}
return retString;
}
And its being called from a HTMl
<div class="panel-body" ng-show="accOpen[$index]">
<!-- Marks TABLE -->
<div marks-table=""
accordion-flag="accOpen[$index]"
name="name"
id="id"
>
</div>
</div>

Adding a custom button to Dropzone

I have been googling this and trying to find a solution which seems to be pretty much impossible, I have dropzone integrated in to my application with the remove button, I want to add an additional button to each thumb nail is this possible to do? so two buttons per each thumbnail?
I have added custom download button for each file check below code
var myDropzone = new Dropzone("#form", {
maxFilesize: 2, // MB
addRemoveLinks: true,
dictRemoveFileConfirmation : 'Sure Want To Delete',
init: function() {
this.on("success", function(file, responseText) {
var filename = file.name;
$('#form').append("<input type='hidden' data='"+filename+"' name='files[]' value='"+responseText+"'>");
});
this.on("complete",function(file){
var newNode = document.createElement('a');
newNode.className = 'btn btn-primary btn-xs downloadbtn';
newNode.href = "<?= SITE_URL.''.'upload/attachments/' ?>"+file.name;
newNode.target = "_blank";
newNode.innerHTML = '<i class="fa fa-download"></i> Download';
file.previewTemplate.appendChild(newNode);
});
}
});
Are you creating a custom theme for the thumbnail? That is the easiest way to add buttons etc. http://www.dropzonejs.com/#theming
for example:
<div id="preview-template" style="display:none">
<div class="documents_drop_file_thumb">
<div class="documents_drop_file_thumb_remove"><a class="dz-remove" href="javascript:undefined;" data-dz-remove=""><img src="<?php echo DIRECTORY_INDEX . "/"; ?>images/remove_file.png" alt=""></a></div>
<div class="documents_drop_file_thumb_EXTRABUTTON"><a class="dz-extraaction" href="javascript:undefined;"><img src="<?php echo DIRECTORY_INDEX . "/"; ?>images/extrabutton_file.png" alt=""></a></div>
<div class="documents_drop_file_thumb_image"><img data-dz-thumbnail /></div>
<div class="documents_drop_file_thumb_progress_status"><span data-dz-name></span></div>
<div class="documents_drop_file_thumb_progress"><span class="dz-upload" data-dz-uploadprogress></div>
<div class="documents_drop_file_thumb_progress_status"><span data-dz-errormessage></span></div>
</div>
Then all you need is a dropzone parameter when setting up your dz.
//Prepare the drop zone area
var myNewdDropzone = new Dropzone("#idOfForm", {
url: "my-ajax.php",
method: "POST",
addRemoveLinks: false,
clickable: true,
previewTemplate: document.querySelector('#preview-template').innerHTML,
init : function() {
this.on("addedfile", function(file) { new_file_added(file); });
this.on("thumbnail", function(file,fileurl) { new_thumbnail_added(file); });
this.on("removedfile", function(file) { new_file_removed(file); });
this.on("totaluploadprogress", function(progress) { display_progress(progress); });
this.on("queuecomplete", function() { all_files_uploaded(); });
//this.on("processing", function(file) { new_file_processed(file); });
}
});
Pay particular attention to:
EXTRABUTTON - that is your shiny new button area
addRemoveLinks - your template has them, so don't add new ones (with a nice icon, assuming you have a nice icon with that name)
previewTemplate - that sets up your new thumbnail template
this.on("etcetcetc") calls functions driven by events if you need them

Resources