Dynamic ckeditor toolbar [closed] - dynamic

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to set ckeditor tool bar based on the user type and some condition.
Partialy I done as below:
switch(UserMode)
{
case "1":
config.toolbar_MyTool = [
['Find', 'SelectAll'], ['Anchor'], ['Maximize']
];
break;
case "2":
config.toolbar_MyTool = [
['Find'], ['Anchor'], ['Maximize']
];
break;
}
Code goes long based on the usermode
so I want to create a array and just I want to assign the toolbar
like as below:
config.toolbar_MyTool = myToolArray;
Also I want to check own post or other person post. If it is own post I want to add some tools additionally.

You would start by defining your different toolbars in the config.js
config.toolbar_MyToolUserMode1 = [
['Find', 'SelectAll'], ['Anchor'], ['Maximize']
];
config.toolbar_MyToolUserMode2 = [
['Find'], ['Anchor'], ['Maximize']
];
Those toolbar-definitions can then be used later in your page, but be aware that as soon as you create an instance of CKEditor, the toolbar layout CAN NOT be changed:
CKEDITOR.config.toolbar = "MyToolUserMode1";
var instance = CKEDITOR.appendTo(parentElement);
Solution 1:
You would have to create a new instance to change the toolbar dynamically:
switch(UserMode)
{
case "1":
if (instance) instance.destroy();
CKEDITOR.config.toolbar = "MyToolUserMode1";
instance = CKEDITOR.appendTo(parentElement);
break;
case "2":
if (instance) instance.destroy();
CKEDITOR.config.toolbar = "MyToolUserMode2";
instance = CKEDITOR.appendTo(parentElement);
break;
}
Solution 2:
However, if you are happy with showing the full toolbar also in usermode 2 and greying the SelectAll-Button, then the following could be your solution:
CKEDITOR.config.toolbar = "MyToolUserMode1";
var instance = CKEDITOR.appendTo(parentElement);
switch(UserMode)
{
case "1":
instance.getCommand('selectAll').enable();
break;
case "2":
instance.getCommand('selectAll').disable();
break;
}
[EDIT feb 15]
Solution 3:
According to your comment -> how to dynamically construct with array.push
No configuration needed in config.js
// your code
var myToolbarSection1 = new Array();
myToolbarSection1.push('Bold');
myToolbarSection1.push('Italic');
// attaching this section to toolbar
var myToolbar = new Array();
myToolbar.push(myToolbarSection1);
// setting the toolbar
CKEDITOR.config.toolbar_Dynamic = myToolbar;
CKEDITOR.config.toolbar = 'Dynamic';
var instance = CKEDITOR.appendTo('myDIVID');

Related

How to exclude certain images from autosave in Gatan Digital Micrograph (GMS) in DM-script

I am trying to mimic the autosave function in GMS v3 so that I can use in version 1 and 2. I would like to first acknowledge that the main bulk of the script originates from Dr Bernhard Schaffer's "How to script... Digital Micrograph Scripting Handbook". I have modified it a bit, so that any new image recorded by the camera can be autosave into the file. However, I met some problems because if I decide to click on live-view image and move the image around, or using live-fft, the live view image or the FFT image will be saved as well. One of the ideas I have is to use the taggroup information such as the "Acquisition:Parameters:Parameter Set Name" because for live view or live-FFT, this would be either in search or focus mode. Another idea is to use the document ID e.g iDocID = idoc.ImageDocumentGETID() to locate the ID of the live image. However, i am clueless then how to use this information to exclude them from autosaving. Can anyone point to me how i can proceed with this script?
Below is the script
Class PeriodicAutoSave : Object
{
Number output
PeriodicAutoSave(Object self) Result("\n Object ID"+self.ScriptObjectGetID()+" created.")
~PeriodicAutoSave(Object self) Result("\n Object ID"+self.ScriptObjectGetID()+" destroyed")
Void Init2(Object self, Number op)
output=op
Void AutoSave_SaveAll(Object self)
{
String path, name, targettype, targettype1, area, mag, mode, search, result1
ImageDocument idoc
Number nr_idoc, count, index_i, index, iDocID, iDocID_search
path = "c:\\path\\"
name = "test"
targettype=="Gatan Format (*.dm4)"
targettype1 = "dm4"
If (output) Result("\n AutoSave...")
nr_idoc = CountImageDocuments()
For (count = 1; count<nr_idoc; count++)
{
idoc = GetImageDocument(count) //imagedocument
index = 1 // user decide the index to start with
index_i= nr_idoc - index
If (idoc.ImageDocumentIsDirty())
{
idoc = getfrontimagedocument()
iDocID = idoc.ImageDocumentGetID()
TagGroup tg = ImageGetTagGroup(idoc.ImageDocumentGetImage(0)) // cannot declare an 'img' for this line as it will prompt an error?
tg.TagGroupGetTagAsString("Microscope Info:Formatted Indicated Mag", mag)
Try{
{
idoc.ImageDocumentSavetoFile( "Gatan Format", path+index_i+"-"+name+"-"+mag+".dm4")
idoc.ImageDocumentSetName(index_i + "-"+name+"-"+mag+".dm4")
idoc.ImageDocumentClean()
}
If (Output) Result("\n\t saving: "+idoc.ImageDocumentGetCurrentFile())
}
Catch{
Result("\n image cannot be saved at the moment:" + GetExceptionString())
Break
}
Result("\ Continue autosave...")
}
}
}
}
Void LaunchAutoSave()
{
Object obj = Alloc(PeriodicAutoSave)
obj.Init2(2)
Number task_id = obj.AddMainThreadPeriodicTask("AutoSave_SaveALL",6)
//Sleep(10)
while(!shiftdown()) 1==2
RemoveMainThreadTask(task_id)
}
LaunchAutoSave()
thank you very much for your pointers! I have tried and it works very well with my script. as the 'TagGroupDoesTagExist' only refers to the taggroup, I modified further to include the tags I want to filter e.g "Search" or "Focus" and it seems to work well. The script that I modified to your existing ones is as below :
If (idoc.ImageDocumentIsDirty())
{
//now find out what is a filter condition and skip if it is true
skip = 0
TagGroup tg = idoc.ImageDocumentGetImage(0).ImageGetTagGroup()
tg.TagGroupGetTagAsString("Microscope Info:Formatted Indicated Mag", mag)
tg.TagGroupGetTagAsString("Acquisition:Parameters:Parameter Set Name", mode)
skip = tg.TagGroupDoesTagExist("Acquisition:Parameters:Parameter Set Name")
if(skip && (mode == "Search" || mode== "Focus")) continue
Your idea of filtering is a good one, but there is something strange with your for loop.
in
nr_idoc = CountImageDocuments()
For (count = 1; count<nr_idoc; count++)
{
idoc = GetImageDocument(count) //imagedocument
you iterate over all currently open imageDocuments (except the first one!?) and get them one by one, but then in
If (idoc.ImageDocumentIsDirty())
{
idoc = getfrontimagedocument()
you actually get the front-most (selected) document instead each time. Why are you doing this?
Why not go with:
number nr_idoc = CountImageDocuments()
for (number count = 0; count<nr_idoc; count++)
{
imagedocument idoc = GetImageDocument(count)
If (idoc.ImageDocumentIsDirty())
{
// now find out what is a filter condition and skip if it is true
number skip = 0
TagGroup tg = idoc.ImageDocumentGetImage(0).ImageGetTagGroup()
skip = tg.TagGroupDoesTagExist("Microscope Info:Formatted Indicated Mag")
if (skip) continue
// do saving
}
}

Google App Script Email as PDF from Spreadsheet [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
My code below for generate PDF attachment is working fine but they send all data in the spreadsheet.
Anyone can help to send only the specify spreadsheet like my code only sheet"Email" in stead of All sheets ?
Thank you
function SendEmail() {
try {
var ss = SpreadsheetApp.getActive();
var url = "https://docs.google.com/feeds/download/spreadsheets/Export?key=" + ss.getId() + "&exportFormat=pdf";
var params = {
method : "get",
headers : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
muteHttpExceptions: true
};
var blob = UrlFetchApp.fetch(url, params).getBlob();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Email')
var subjectrange = sheet.getRange("A20");
var subjectdata = subjectrange.getValues();
var emailranges=sheet.getRange('E14');
var emaildata=emailranges.getValue();
var username=ss.getSheetId();
blob.setName(ss.getName()+ ".pdf");
var confirm = Browser.msgBox('Send Email Confirmation','Are you sure you want to send this mail for booking request ?', Browser.Buttons.OK_CANCEL);
if(confirm=='ok') {
MailApp.sendEmail(emaildata, subjectdata, " Attachment file is: \n" +subjectdata+ "- \n Kindly reply your booking to this email . \n Thank you - ADS Co., Ltd", {attachments: [blob]}) };} catch (f) {Logger.log(f.toString());
}
}
Answer
If you don't want to export some sheets you can hide them. Furthermore, you can export a Spreadsheet with the method getBlob. Once you have made the export, you can undo the hide.
Small code assuming two sheets
var sheet = ss.getSheetByName('Unwanted Sheet')
sheet.hideSheet()
var blob = ss.getBlob()
blob.setName(ss.getName())
sheet.showSheet()
Full code working with many sheets
function exportSheet(sheetName) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
for (var i = 0; i < sheets.length; i++) {
if (sheets[i].getSheetName() !== sheetName) {
sheets[i].hideSheet()
}
}
var blob = ss.getBlob()
blob.setName(ss.getName())
for (var i = 0; i < sheets.length; i++) {
sheets[i].showSheet()
}
}
Some tips
You don't have to add .pdf to the blob name, it already understand that it is a pdf file and the extension will appear automatically
You can use GmailApp service instead of MailApp since it is more versatile and has more functionalities. The main reason to use MailApp is using that it doesn’t require the developer to be a Gmail user.
Reference
hideSheet
showSheet
getBlob
GmailApp
MailApp

Elm : Pass value to outgoing port from the update function

I have an update function that adds an Answer to a Question
Once the question has been updated with an answer, I'd like to send it to an outgoing port, while also updating my model.
port emitQuestion : Question -> Cmd msg
update msg model =
AnswerQuestion answer ->
case model.question of
Nothing ->
( model, Cmd.none)
Just question ->
let
updatedQuestion =
{ question | answer = Just answer }
in
( { model | question = updatedQuestion } , Cmd.none)
How could I pass updatedQuestion to emitQuestion in this scenario ?
You define the outgoing port signature, but without a body, like this:
port questionUpdated : Question -> Cmd msg
(assuming that you have an Question type or alias; your question didn't specify)
Then, in the calling javascript, you define your port handler after calling Elm init:
var app = Elm.Main.init({ node: document.querySelector('main') })
app.ports.questionUpdated.subscribe(function(data) {
// your javascript for handling updated question
});
To pass that new question value to the port on update, just pass it in the second value of the return type from update:
( { model | question = updatedQuestion } , questionUpdated updatedQuestion )

Programmatically set focus on a style-element in Elm [duplicate]

This question already has answers here:
How to set focus on an element in Elm?
(6 answers)
Closed 4 years ago.
Anyone know if there's a way to programmatically set focus on an Element.Input.text element using stylish-elephants (or style-element v5)?
It requires "elm-lang/dom": "1.1.1 <= v < 2.0.0" in elm-package.json
import Dom exposing (focus)
update msg model =
case msg of
FocusOn id ->
{ model | current_focus_id = id } ! [ Task.attempt FocusResult (focus (id)) ]
FocusResult result ->
case result of
Err (Dom.NotFound id) ->
model ! [ YourMsg]
Ok () ->
model ! []
view model = Element.layout [] <| el [onClick <| (FocusOn "id01")] (text "click here")

Exporting multiple sized images in Illustrator [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I want to export my iOS App Icon in different sizes but without having to do it for each size! Is there a way with Adobe Illustrator where you can export various PNG's with different sizes all in one go?
I found an answer myself!
http://www.adobe.com/devnet/illustrator/scripting.html
As detailed in the link above; A script is a series of commands that tells Illustrator to perform one or more tasks.
So by using the following script I was able to export multiple images in different sizes as I wanted.
#target Illustrator
/**
* export multiple PNG's in different sizes
* #author Alexandros Harvey
*/
// Adapted to export an Illustrator file in various sizes by Alexandros Harvey
// based on how to export images as CSS Layers by CarlosCanto
if (app.documents.length > 0) {
main();
}
else alert('Cancelled by user');
function main() {
var document = app.activeDocument;
var afile = document.fullName;
var filename = afile.name.split('.')[0];
var folder = afile.parent.selectDlg("Export as CSS Layers (images only)...");
if(folder != null)
{
var activeABidx = document.artboards.getActiveArtboardIndex();
var activeAB = document.artboards[activeABidx]; // get active AB
var abBounds = activeAB.artboardRect;// left, top, right, bottom
var docBounds = document.visibleBounds;
activeAB.artboardRect = docBounds;
var options = new ExportOptionsPNG24();
options.antiAliasing = true;
options.transparency = true;
options.artBoardClipping = true;
var icons = [
{"name": "Icon-512#2x", "size":1024},
{"name": "Icon-512", "size":512},
{"name": "Icon-60#3x", "size":180},
{"name": "Icon-76#2x", "size":152},
{"name": "Icon-72#2x", "size":144},
{"name": "Icon-60#2x", "size":120},
{"name": "Icon-57#2x", "size":114},
{"name": "Icon-50#2x", "size":100},
{"name": "Icon-40#2x", "size":80},
{"name": "Icon-76", "size":76},
{"name": "Icon-72", "size":72},
{"name": "Icon-60", "size":60},
{"name": "Icon-29#2x", "size":58},
{"name": "Icon-57", "size":57},
{"name": "Icon-50", "size":50},
{"name": "Icon-40", "size":40},
{"name": "Icon-29", "size":29}
];
var icon, file;
for(var i = 0; i < icons.length; i++)
{
icon = icons[i];
file = new File(folder.fsName + '/' + icon.name + ".png");
// My App Icon is originally 1024x1024 so that's why I divide height and width by 1024
options.horizontalScale = 100 * (icon.size / document.width);
options.verticalScale = 100 * (icon.size / document.height);
document.exportFile(file,ExportType.PNG24,options);
}
activeAB.artboardRect = abBounds;
}
}
I hope this helps anyone else who needs something similar.
UPDATE:
With regards to different sizes; Change the icons array to use height and width instead of size e.g.
var icons = [{"name": "Icon-512#2x", "height":250, "width":125}, ...]
Then change horizontalScale to use the width and verticalScale to use height. I have also changed it so it uses the document height and width rather than a hard coded number.
options.horizontalScale = 100 * (icon.width / document.width);
options.verticalScale = 100 * (icon.height / document.height);
RUNNING THE SCRIPT:
By volleybologist
Copy the code above into an editor (like Notepad++)
Save as a javascript file (.js)
Open Illustrator (checked with Illustator CC 19.1.0 and it works)
In Illustrator, go to File > Scripts > Other Script and open the .js file you just saved
A dialog will pop up, find and select the .js file
Another dialog will pop up which asks you to choose a location for the pngs to be exported
Script will run and images should be in the chosen folder