I created a dialog in ckeditor.
editor.ui.addButton('blublu',
{
label: 'blublu',
command: 'blublu',
icon: this.path + 'icons/blublu.png'
}
);
editor.addCommand('blublu', new CKEDITOR.dialogCommand('blublu'));
CKEDITOR.dialog.add( 'blublu', this.path + 'dialogs/dialog.js' );
If I press the button the dialog shows, everything is fine. Now I try to open this window from another dialog :
( function() {
CKEDITOR.dialog.add( 'templates', function( editor ) {
return {
title: editor.lang.templates.title,
contents: [...],
onHide: function(){
if(condition)
//dostufff;
this.hide();
editor.execCommand('blublu');
}
}
}
});
It works the first time the editor is loaded. But if I open the dialog from the button in the toolbar, and I close it, I can't open the dialog from the 'templates' dialog. I have the dark background as if a dialog where shown, except the dialog, is not there. It is hidden and just shows it is not enough because all buttons handlers on it don't work.
I have no error in console.
Any solution?
I've tested it with existing plugins and it looks like you need to call execCommand asynchronously with setTimeout.
setTimeout( function() {
execCommand( commandName );
} );
If fix doesn't work for every browser, then you will have to add some short delay. I don't see better solution.
Related
im busy with creating a bookmaker extension in safari and running up against the following issue. In my popover i've a iframe which includes a button. When that button (submit button) is clicked the following message must be send:
window.addEventListener('message', function(e){
if(e.data.command == 'closeSymbalooBookmarker'){
window.setTimeout(function(){
window.close();
}, 2000);
}
});
as you can see this close the popover in 2 seconds (the above script is made in chrome extension).
I need to send a message from the inject script to a popover so i can close the popover in the popover window. Or is there some other way to that?
Thank u.
The global page is the best place to receive messages from an injected script.
Do something like this:
global.js
safari.application.addEventListener('message', handleMessage, false);
function handleMessage(msg) {
if (msg.name === 'hidepopover') {
safari.extension.popovers[0].hide()
}
}
injected.js
setTimeout(function() {
safari.self.tab.dispatchMessage('hidepopover');
}, 2000);
I am developing an extension for Firefox that needs to open a standard Javascript popup window that can be a custom size. I have looked all around and I can't seem to figure out how to do it. My code for a contextual menu works good, but it seems like Firefox is blocking the window.open snippet needed to accomplish this.
Is there a way todo it via XUL, or any other SDK modules?
We need a bit more details, here's what I think you're going for.
require("sdk/context-menu").Item({
label: "Open Window",
contentScript: 'self.on("click", function (node, data) {' +
' window.open("http://stackoverflow.com/questions/14572412/how-to-open-a-popup-window-via-firefox-addon-contextual-menu");' +
'});'
});
This code would open up a new window (or tab) when the user clicks on the Open Window item. The window.open function works in this context but I'm not sure what context you're not seeing it work in.
Hope this helps you.
If you want open not a popup window but panel, here's an example:
var self = require("sdk/self");
var panels = require("sdk/panel");
var panel = panels.Panel({
contentURL: self.data.url("panel.html")
// , onHide: handleHide
});
require("sdk/context-menu").Item({
label: "Open Window",
contentScript: 'self.on("click", function (node, data) {' +
' self.postMessage(node.innerHTML);' +
'});',
onMessage: function (data) {
console.log('posted retrieved: '+data);
panel.show();
}
});
And some reference
You can also use:
`<popupset>
<panel id="some">
</panel>
<popupset>`
In the JavaScript write:
document.getElementById('some').openPopup(...)
I'm building a simple dialog plugin to replace the default link tool. The design calls for a particular layout that is difficult to achieve with the CKEdit dialog definition: We want a single field to appear above the tab elements in the dialog (see illustration).
Can anyone suggest a way that this might be implemented? Thanks!
As far as I can tell it is not possible to achieve this using the built-in dialog definition.
I was able to get around this limitation by building my dialog plugin using the iframedialog plugin. This basically pops up a CKEditor dialog window and loads an external URL into it. You can do anything you want in that iframe, and then return the text to CKEditor when the user presses the OK button.
A simple example:
// plugins/iframelink/plugin.js
CKEDITOR.plugins.add('iframelink', {
requires: ['iframedialog'],
init: function(editor){
CKEDITOR.dialog.addIframe('iframelinkDialog',
// title
'Insert a Link',
// src
this.path + 'dialogs/link.html',
// minWidth
500,
// minHeight
250,
// onContentLoad
);
var cmd = editor.addCommand('iframelink', {exec: iframelinkOnclick});
editor.ui.addButton('iframelink', {
label: 'Insert a Link (Special Link Tool)',
command: 'iframelink',
icon: this.path + 'images/world_link.png'
});
}
});
function iframelinkOnclick(editor){
dialog = editor.openDialog('msiteslinkDialog');
};
// plugins/iframelink/dialogs/iframelink.js
$(function() {
if (typeof(window.parent.CKEDITOR) != 'undefined') {
CKEDITOR = window.parent.CKEDITOR;
var dialog = CKEDITOR.dialog.getCurrent();
var editor = dialog.getParentEditor();
// Get value of the selected text:
var selection = editor.getSelection().getSelectedText();
// Do something when the user presses the OK button:
var okListener = function(ev) {
link = yourFunctionToDoSomethingClever();
this._.editor.insertHtml(link);
dialog.removeListener("ok", okListener);
};
// Bind the OK button to your okListener method:
dialog.on("ok", okListener);
};
}
So you can make the dialog look any way you want:
I have a main window (app.js) and two sub-windows (login.js and signUp.js)
Here is my app.js
var login=Titanium.UI.createWindow({
url:'wins/login.js',
title:'Login',
backgroundColor:'#CCC',
navBarHidden:true
});
var signUp=Titanium.UI.createWindow({
url:'wins/signUp.js',
title:'Sign-up',
backgroundColor:'#CCC',
navBarHidden:true
});
login.open({fullscreen:true});
Now I want to open signUp.js from with login.js. Is there any way to do this? I've tried googling and reading over the documentation to no avail.
just typed this up, not perfect, but this is the general idea.
// create buttons on main window
var loginBtn = Titanium.UI.createButton({
title : 'LOGIN'
});
var signUpBtn = Titanium.UI.createButton({
title : 'SIGN UP'
});
// add to window
mainWindow.add(loginBtn);
mainWindow.add(signUpBtn);
// associate click events
loginBtn.addEventListener('click', function() {
Ti.API.log('loginBtn button clicked, show window');
login.open();
});
signUpBtn.addEventListener('click', function() {
Ti.API.log('signUpBtn button clicked, show window');
signUp.open();
});
I'm trying to call close function for CKEditor dialog box from my custom plugin. Just like it happens when you are clicking on smile in "smileys" plugin, but I can't find out how can I do the same in my own plugin.
Thanx for reply!
I've got the solution.
In my plugin I needed to call close function from "CKEDITOR.dialog.add" in "onLoad" section. So, I have to do this:
CKEDITOR.dialog.add( 'plugin_name', function( editor ){
onLoad: function( event ){
[...some code...]
event.sender.hide();
}
}
CKEDITOR.dialog.getCurrent().hide()
I propose you do it the same way it is done by CKEditor Dialog plugin internally. See line 535 in plugin.js
By clicking the button or firing the cancel event you ensure correct handling by the plugin.
Code sample:
// If there's a Cancel button, click it, else just fire the cancel event and hide the dialog.
button = CKEDITOR.dialog.getCurrent().getButton( 'cancel' );
if ( button )
CKEDITOR.tools.setTimeout( button.click, 0, button );
else {
if ( CKEDITOR.dialog.getCurrent().fire( 'cancel', { hide : true } ).hide !== false )
CKEDITOR.dialog.getCurrent().hide();
}