What execCommand commands are available in CKEditor? - javascript

Can anyone tell me what execCommand commands are available in CKEditor?
Like editor.execCommand('bold')

The commands that are available to you depend on the installed plugins.
This list of available CKEditor commands can be found using CKEDITOR.instances.editor1.commands

Unfortunately commands are not specified in JSDocs.
However, every command is added to editor by editor#addCommand method, so you can grep the code for them:
> grep -R addCommand *
Regarding Daevo's response - toolbar config consists of buttons names - not command names. Usually each button has corresponding command, but it doesn't have to be a rule.
Tnnks for ur rply..Is there any command to select particular text..?
There are three commands related to selection - "selectAll", "selectNextCell", "selectPreviousCell". But if you want to do custom selection take a look on Range and Selection APIs. In short - you have to create range and call range#select method.

They can be any command. This would include all the built-in command like listed here http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Toolbar
Addionally and commands you or a plug-in create.
I guess the main point is to allow you to call afterCommandExec and beforeCommandExec so you can perform your own code when a button is clicked.

Related

Auto-import Javascript module in Vscode using Shortcut (Ctrl + .)

If my JS code uses a module/varaible that is not yet imported, VSCode will underline it in red
Image showing underline in VSCode
How can VSCode be configured such that we can select the unimported variable, either press a shortcut or select something from the right-click menu, and select the appropriate module to be imported.
Similar to the Ctrl + . auto-import shortcut when dealing with Rust files
Create a clone of the Rust shortcut
Since there is already a shortcut that does what you want (albeit in a different language), you may be able to create a new shortcut based on the existing one.
First: open your keyboard shortcuts, and do a "reverse-shortcut" search for Ctrl + .. There's an icon near the right side of the search input that switches the search behavior to this:
You may find multiple matches; study them to identify the Rust import command that you like. In particular, take note of the "Source" column: if Source is "Extension," that means you're getting the Rust behavior from an extension, and you may need to find (or create) a similar extension that targets JS/TS. (I suspect you will, because I don't have any commands related to imports in my VSCode.) The next step requires that you copy the value of the Where column, so do that now.
Second: look at the "Command" column for the name given to this behavior. If the name is specific to Rust, do a new search for a similar command that doesn't target Rust. If there is such a command, you just need to configure it to run when you like: edit that shortcut and paste the "When" value from behavior; this may require a hand-edit if the When from the Rust command mentions anything specific about Rust (e.g. if it includes editorLangId == 'markdown', change that to 'javascript' and add alternative for typescript as well).
If there is no auto-import command that is language agnostic, and none that is specific to JS/TS (again, I don't see one in my VSC), you will have to rely on the Intellisense-based option, or find (or create) an extension that does this. Creating an extension is a whole other topic.
Normally, in Visual Studio Code, if you type in a variable or function that isn't imported, then Visual Studio Code will auto-correct it, if you select it.
For example, if I am typing half the name of a function, it will infer that I want a function, and when I hit Tab/Enter, it will autocomplete it, and import it.
See the GIF below for a visual example.

Is it possible run a plugin as a test?

I'm working with HTMLhint but it just run with the command line is a plugin, I want this action to run like a test. Is it possible do it and how? I was googling but I don't find a way to do that.
Do you mean you'd like it to run every time you push code? Or, would you like it to run locally in your editor every time you save/as you type?
Every time you push code: look into TravisCI or another type of continuous integration. These services can run items on your code, including linters, each time you push new commits.
Every time you save/as you type: this depends on what your editor requires to run the lint. For example, Sublime Text has Sublime Linter which can automatically run any type of linter after installation of the corresponding package.

Add new shortcut to selenium IDE

How can i add new shortcut to Selenium IDE modifying its code?
For example, i want to assign to action run test case shortcut: ctrl + p, just like save action has ctrl + s
I could not find any js file responsible for this.
Since you have asked make changes in the code. I would suggest :
Clone the git repository SeleniumHQ on your local machine.
Search for the file which implements the shortcuts on the IDE.
Make changes and create a Pull Request on the project.
Wait for the admin to review it and merge the same.
Note : This would put the usefulness of the idea and correctness of its implementation under regression which shall never be a cause of
worry if you want to develop on something.
Edit : On digging further I've got to know that selenium IDE uses a third party keyboard shortcuts script to provide us with the shortcuts.
The link to the specific file goes in here : keyboardshortcuthandler.js

Add values to a chosen multiselect

I am wondering whether it's possible to add new values on the fly to a chosen.js multiselect (similar to how tagging works).
I've seen in another SO post a user saying this is possible. He links to an example and a fork on github, but I've had some difficulties implementing those.
The source code is written in CoffeeScript. I've tried compiling it (using an online compiler) to regular JavaScript, copy pasted the code into a blank test project but I got errors. After that, I've loaded The AbstractChosen and SelectParser as well (compiled them to js) and didn't get errors, but the 'add items on the fly' functionality is not there (although i initialized the chosen described in the aforementioned link).
Has anybody worked with this fork? If yes, could you please share your experiences with it?
The problem you have is because you haven't follow the steps in the documentation:
If you download the source, install the correct packages and run the build commands you end with a chosen.jquery.js, chosen.proto.js and chosen.css.
So the following steps should do it for you:
Download: https://github.com/koenpunt/chosen/archive/option_adding.zip
Install packages: npm install && gem install bundler && bundle install
Run build: grunt build (note, for this you'll need the grunt cli)
Edit
Or for your convenience, download a compiled release.
the documentation mentions this option:
Updating Chosen Dynamically
If you need to update the options in your select field and want Chosen
to pick up the changes, you'll need to trigger the "chosen:updated"
event on the field. Chosen will re-build itself based on the updated
content.
with this.
$("#form_field").trigger("chosen:updated");
This can be combined with
// Add field
$("#form_field").append("<option>Utopia</option>");
$("#form_field").trigger("chosen:updated");
Adding this together to an example can be found at the jsfiddle:
http://jsfiddle.net/E5X9x/
The solution is here
$('select').chosen({plugins: ['option-adding']});
or
$(function() {
$(".chzn-select").chosen({
create_option: true,
// persistent_create_option decides if you can add any term, even if part
// of the term is also found, or only unique, not overlapping terms
persistent_create_option: true,
// with the skip_no_results option you can disable the 'No results match..'
// message, which is somewhat redundant when option adding is enabled
skip_no_results: true
});
});

Google Chrome - how can i programmatically enable chrome://flags some of the modules from disable mode to enabled mode?

How can I automate the setting of chrome flags to enable few modules?
I have application designed which requires on open the chrome://flags few modules enabled, otherwise the whole application does not work, for normal user its nightmare to do such small changes.
Is there any javascript or google app engine or other method to use from server side scripting or some plugin where i can say click this and it will automatically enable the modules inside chrome://flags?
Almost every Chrome flag can be set via the command line. Here is a quite exhaustive list of command line parameters, but also keep in mind that there would be even more in newer versions!
EDIT: Here is the Comprehensive, up-to-date list of Chrome command line switches
So basically you would launch chrome with these command line flags already set. That's the best way to go about it.
You cannot manually set this using Javascript or other behavior. The only way you can set this programmatically (other than command line flags) is to use Capybara (a tool that can open and control browsers, generally used for running automated tests), open Chrome and then manually navigate to "chrome://flags" and click the necessary combo boxes.
EDIT: Watir is also as good as Capybara
Watir is another browser automation framework (similar to Capybara) but is much easier to setup and start with. Here are examples on how you would open a web page and select a combo box, and here are instructions on using it with Chrome. You can write a single ruby file which looks like:
require 'watir-webdriver'
browser = Watir::Browser.new :chrome
browser.goto "chrome://flags"
browser.select_list(:id => <combo box id>).select("Enabled")
...
Persisting the Flags when using WebDriver
Chrome has the --user-data-dir switch which is where all the profile settings are saved. The default directories that Chrome uses (on Windows/Mac/Linux) [is documented here. Generally, WebDriver launches with a temporary --user-data-dir, and later deletes the temporary folder after use. So whatever flags you set will be lost when you run Chrome again! So set --user-data-dir to your user's default profile directory, and then whatever flags you set will be persisted.
Edit 2: Added comprehensive list of chrome command line flags
Edit 3: Added instructions for persisting the flags in Webdriver
Rooting about in the chrome://flags screen I found something interesting in an included JS file :
/**
* Invoked when the selection of a multi-value choice is changed to the
* specified index.
* #param {HTMLElement} node The node for the experiment being changed.
* #param {number} index The index of the option that was selected.
*/
function handleSelectChoiceExperiment(node, index) {
// Tell the C++ FlagsDOMHandler to enable the selected choice.
chrome.send('enableFlagsExperiment',
[String(node.internal_name) + '#' + index, 'true']);
requestFlagsExperimentsData();
}
chrome.send is indeed a valid method,
Here is another snippet form the same file (chrome://flags/flags.js)
/**
* Asks the C++ FlagsDOMHandler to restart the browser (restoring tabs).
*/
function restartBrowser() {
chrome.send('restartBrowser');
}
Manually calling chrome.send ('restartBroswer') did indeed restart the browser.
I think this provides all the facilities you need to automate the setting of the flags, you will need to trawl through the chrome://flags source to find the flags you need and then
set up the appropriate chrome.send calls.

Categories