Laravel file manager standalone iframe to input - laravel

I don't know how can't I find any examples on this, like no one used it before..
I want to open file manager in iframe and on images click to insert image url to input. Their example opens new window...
I am using laravel file manager standalone button to change avatar image but by their docs I can do it like this:
<div class="input-group">
<span class="input-group-btn">
<a id="lfm" data-input="thumbnail" data-preview="holder" class="btn btn-primary">
<i class="fa fa-picture-o"></i> Choose
</a>
</span>
<input id="thumbnail" class="form-control" type="text" name="filepath">
</div>
<img id="holder" style="margin-top:15px;max-height:100px;">
And calling $('#lfm').filemanager('image');
Which works but it opens new window because this is .filemanager()
(function( $ ){
$.fn.filemanager = function(type, options) {
type = type || 'file';
this.on('click', function(e) {
var route_prefix = (options && options.prefix) ? options.prefix : '/laravel-filemanager';
localStorage.setItem('target_input', $(this).data('input'));
localStorage.setItem('target_preview', $(this).data('preview'));
window.open(route_prefix + '?type=' + type, 'FileManager', 'width=900,height=600');
window.SetUrl = function (url, file_path) {
//set the value of the desired input to image url
var target_input = $('#' + localStorage.getItem('target_input'));
target_input.val(file_path).trigger('change');
//set or change the preview image src
var target_preview = $('#' + localStorage.getItem('target_preview'));
target_preview.attr('src', url).trigger('change');
};
return false;
});
}
})(jQuery);
Now changing:
window.open(route_prefix + '?type=' + type, 'FileManager', 'width=900,height=600');
To:
$('iframe').attr('src', route_prefix + '?type=' + type);
Will append filemanager to iframe as I want but when I click on image inside iframe it opens image in new tab as it is setting new url but skipping the script?
I think that I could get image url if it was opening in iframe but it is not...
Do you maybe know how to do this?
Thanks

I found out answer for my needs, not finished one tho but it works as needed:
Open up script.js from vendor/..../js folder and change useFIle function if/else statement where it looks up are you using any editor (cke,mce,etc..) and if not it just opens image in new window.
I remove that option and added this:
// parent.document.getElementById(field_name).value = url;
var target_input = parent.document.getElementById(localStorage.getItem('target_input'));
target_input.value = url;
//set or change the preview image src
var target_preview = parent.document.getElementById(localStorage.getItem('target_preview'));
target_preview.src = url;
From my question you can see jquery-plugin for opening laravel-filemanager into iframe and adding elements to localstorage.
I used that elements from localstorage in iframe to append url in input and display image in holder.
Now I will change this a little bit, since I wan't to leave this script as it is for full manager page on that url. I will just add another field as uri to be able to say this url is opened by iframe and use someOtherFUnction instead of useFile function by default.

Related

Google script automatically close UI after clicking link button

I have a script that opens a UI which is used to open another spreadsheet
When I click to open the link I would like the UI to close automatically if possible.
function ServiceSetServiceSheets(){
var html = "<a href='https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxxx'; target='_blank'>Open The Service Sheet</a>";
var anchor = HtmlService.createHtmlOutput(html).setSandboxMode(HtmlService.SandboxMode.IFRAME).setHeight(60).setWidth(150);
SpreadsheetApp.getUi().showModalDialog(anchor,"Click the link to")
}
Can anyone help please?
In your situation, how about using google.script.host.close() as follows? Please modify your script as follows.
From:
var html = "<a href='https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxxx'; target='_blank'>サービス シートを開く";
To:
var html = "<a href='https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxxx'; target='_blank' onclick='google.script.host.close()'>サービス シートを開く";
By this modification, when you click the link, the dialog is closed by google.script.host.close().
Example:
Execute launchClickAndClose();
function launchClickAndClose() {
let html = '<!DOCTYPE html><html><head><base target="_top"></head><body>';
html += '<input type="button" value="Doit" onClick="doSomething();" />';
html += '<script>function doSomething(){google.script.run.withSuccessHandler(() => {google.script.host.close()}).doitontheserver();}</script>'
html += '</body></html>';
SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html), "Close Automatically")
}
function doitontheserver() {
const ss = SpreadsheetApp.getActive();
ss.toast("Doing it");
return;
}

Entering Page Breaks in CKEditor

I have an ASP.NET MVC 4 application that uses the CKEditor control (4.4.5) to capture HTML which is then rendered to a Word (docx) document.
When I use the CKEditor "Page break" button, it produces
<div style="page-break-after: always"><span style="display: none;"> </span></div>
which is retained in the editor's HTML, however it is not rendered in Word.
What does work in Word is:
<br> <br style="page-break-after: always;" />
But I am finding that my CKEditor setup strips this out each time you save data in the CKEditor box.
Can I change CKEditor to put in the code that Word recognizes with the page break button, or should I be considering another option to resolve this?
I've created this tiny plugin for version 4.x:
CKEDITOR.plugins.add('wordpagebreak', {
icons : 'wordpagebreak',
init : function(editor) {
var pluginName = 'wordpagebreak';
editor.addCommand(pluginName, {
exec : function(editor) {
var html = '<br class="wordpagebreak" clear="all" ' +
'style="mso-special-character: line-break; ' +
'page-break-before: always">';
var element = CKEDITOR.dom.element.createFromHtml(html);
editor.insertElement(element);
}
});
editor.ui.addButton(pluginName, {
label : 'Word Page Break',
icon : 'wordpagebreak',
command : pluginName,
toolbar : 'insert'
});
}
});

Magento - Updating attribute IF THE OPTION changed

I really need some support regarding magento:
on this page: https://goo.gl/wTeUtG
If the option changed out of the dropdown, like from 150 Gramm to 200 Gramm, the ingredients (on this page as "Zutaten") also should be updated. But only the price is going to change not the text right into tooltip on "Zutaten".
How or where can I do this?
That's what I have tried so far:
I've created a new attribute and put it into the checkbox.phtml. This is the code for it:
<p>
<label>Zutaten:</label>
<a class="tooltips" href="#">
<img src="https://shop.ellyseidl.de/skin/frontend/base/default/pektsekye/optionbundle‌​/info_icon.gif" width="11px" height="11px" />
<span><strong>Zutaten:</strong>
<?php echo Mage::getModel('catalog/product')->load($_selection->getId())->getData('zutaten'‌​); ?>
</span>
</a>
</p>
But it doesn't change the tooltip once a option is selected
I guess you will have to do it manually with jQuery since you are using it on your page, by adding event on change on the select box with the id="attribute154" or the class="super-attribute-select".
You will have to change the text in the tooltip according to the option being selected.
EDIT:
jQuery('#attribute154').on('change', function() {
var selectedVal = jQuery(this).val();
//If you want to change the tooltip according to the selected text this is how you can get it:
var selectedText = jQuery(this).find("option:selected").text();
if (selectedVal != '') {
var ingredientsText = '';
if (selectedText == '150 Gramm') {
ingredientsText = 'Ingredients for 150 Gramm';
} else if (selectedText == '200 Gramm') {
ingredientsText = 'Ingredients for 200 Gramm';
}
//And so on
jQuery('.tooltips').find('span:first').html('Zutaten:'+' Folgen in Kürze: '+ingredientsText);
} else {
jQuery('.tooltips').find('span:first').html('Zutaten:'+' Folgen in Kürze: ');
}
});
Please have in mind that you must change the text the way you need it. I still don't know what you have to add in the tooltip, but I just tested this on your site and it works. According to the text Folgen in Kürze which means coming soon, not sure what is the text you need to update.
EDIT2:
The ingredientsText var will depend on the quantity of Gramm selected, if they are static you can enter them in the code by yourself, if they are dynamic, you will have to add them somewhere in the HTML in a hidden <div> for example and then fetch them with JS from there.

AJAX: if right click to open a new tab, render the whole page

I use AJAX on a link to insert data into a certain <div> in the same page. However, if the user right-clicks and opens in a new tab, the new page will contain only the data, without other page elements. How can I do to render a whole page for a right-click-new-tab?
HTML:
<a class=".updateContent" href="...">The link</a>
...
<div id="content></div>
AJAX:
$(document).ready(function() {
$('.updateContent').click(function() {
var url = $(this).attr('href');
$('#content').load(url);
return false;
});
});
Don't use an href. With an href the user has the option to open in a new tab/window or copy/paste no matter what you do (except maybe disable right click entirely but that's annoying). I suggest something like the following:
<a class="updateContent" data-url="...">the link</a>
Then your jQuery
var url = $(this).data('url');

MVC3 returning image file as byte data when using jQuery Fancybox

I have built and MVC3 application with a controller (Picture) and an action method (GetImage) that returns File contents (in my case a jpeg image)
public FileResult GetImage(int pictureID)
{
return File(Server.MapPath("~/Content/pic" + pictureID + ".jpg"), "image/jpeg");
}
When I access images in my views like
<a id="single_image"><img src="/Picture/1" /></a>
..I get the image displayed properly.
But when I apply jQuery Fancybox plugin to this image and click on the image, it displays the pop-up with byte[] data inside (something you would get when the file mime type is missing).
What am I doing wrong?
PS: Sorry I am unable to post any images but can email it.
Just get your images directly using Html.Content in your View.
Forms
<a id="single_image">
<img src="<%= Html.Content("~/Content/pic" + model.pictureID + ".jpg") %>" />
</a>
Razor
<a id="single_image">
<img src="#Html.Content("~/Content/pic" + model.pictureID + ".jpg")" />
</a>
EDIT
If you're dead set on using a picture controller, then I would recommend having your PictureController have the Index action return an ActionResult
public ActionResult Image(int id)
{
var dir = Server.MapPath("/Pictures");
var path = Path.Combine(dir, id + ".jpg");
return base.File(path, "image/jpeg");
}
This will however slow down your requests over a direct .jpg file access.

Resources