How to use the function search and replace in codemirror editor? - codemirror

I am using codemirror and I need to use the function search and replace ... I read this here this function
I want to find word and replace it by another word ... I write this code but did not work :
<script src="plugin/codemirror/addon/search/search.js"></script>
<script src="plugin/codemirror/addon/search/searchcursor.js"></script>
here use the function :
var cor= editor.getSearchCursor("one", null, null);
cor.replace("one","anything");
so what wrong ? How I can call the function correct ?

Related

Pass arguments to JavaScript function from Sightly

I can call JavaScript functions from Sightly with no parameters, e.g.
<div
data-sly-use.ResourceUtils="/libs/wcm/foundation/components/utils/ResourceUtils.js"
data-example="${ResourceUtils.aFunction}" />
But I would like to call a function called 'getResource' that accepts 1 argument.
How can I address this function from Sightly, passing in this argument?
basically, you can access arguments by using "this.", for example:
Your html would look something like this:
<div data-sly-use.ResourceUtils="${'/libs/wcm/foundation/components/utils/ResourceUtils.js' # arg='argument'}" data-example="${ResourceUtils.aFunction}" />
And the JS would be:
use( function () {
var argument = this.arg;

Ext.define() order

I'm using Extjs5 and Sencha Cmd, and I'm working on a l10n engine (over gettext) to implement localization.
Suppose I want to offer a translation function to every class of my project, named _().
In every controller, view, model and any class, I'd like to be able to write something like that:
Ext.define('FooClass', {
someStrings: [
_('One string to translate'),
_('A second string to translate'),
_('Yet another string to translate')
]
});
First problem: _() must exist before all the Ext.define() of my project are executed. How to achieve that?
Second problem: _() is looking in "catalogs" that are some JavaScript files generated from .po files (gettext). So, those catalogs must have been loaded, before all the Ext.define() of my app are executed.
_() is a synchronous function, it musts immediately return the translated string.
Edit concerning the edited question
You have at least two ways to load External libraries:
Ext.Loader.loadScript
loadScript( options )
Loads the specified script URL and calls the supplied callbacks. If
this method is called before Ext.isReady, the script's load will delay
the transition to ready. This can be used to load arbitrary scripts
that may contain further Ext.require calls.
Parameters
options : Object/String/String[] //The options object or simply the URL(s) to load.
// options params:
url : String //The URL from which to load the script.
onLoad : Function (optional) //The callback to call on successful load.
onError : Function (optional) //The callback to call on failure to load.
scope : Object (optional) //The scope (this) for the supplied callbacks.
If you still run into problems you can force the loader to do a sync loading:
syncLoadScripts: function(options) {
var Loader = Ext.Loader,
syncwas = Loader.syncModeEnabled;
Loader.syncModeEnabled = true;
Loader.loadScripts(options);
Loader.syncModeEnabled = syncwas;
}
Place this in a file right after the ExtJS library and before the generated app.js.
Old Answer
You need to require a class when it is needed, that should solve your problems. If you don't require sencha command/the ExtJS class system cannot know that you need a specific class.
Ext.define('Class1', {
requires: ['Class2'],
items: [
{
xtype: 'combo',
fieldLabel: Class2.method('This is a field label')
}
]
});
For further reading take a look at:
requires
requires : String[]
List of classes that have to be loaded before instantiating this
class. For example:
Ext.define('Mother', {
requires: ['Child'],
giveBirth: function() {
// we can be sure that child class is available.
return new Child();
}
});
uses
uses : String[]
List of optional classes to load together with this class. These
aren't neccessarily loaded before this class is created, but are
guaranteed to be available before Ext.onReady listeners are invoked.
For example:
Ext.define('Mother', {
uses: ['Child'],
giveBirth: function() {
// This code might, or might not work:
// return new Child();
// Instead use Ext.create() to load the class at the spot if not loaded already:
return Ext.create('Child');
}
});
Define the translate function outside the scope of the ExtJs project and include it before the Ext application is included in the index.html.
The scripts are loaded in the right order and the _() function is ready to use in your whole project.
i18n.js
function _() {
// do the translation
}
index.html
<html>
<head>
<script src="i18n.js"></script>
<script id="microloader" type="text/javascript" src="bootstrap.js"></script>
</head>
<body>
</body>
</html>

Adding async keyword to script tag using HtmlTextWriter

We are dynamically adding script tags to a page using HtmlTextWriter, which works great. We have a few that need to have async keyword added and I'm not sure how to do it.
I want the tag to look like this.
<script id="my_script" async type="text/javascript" src="myscript.js"></script>
My method that builds the tags look like this.
internal static void RenderJavaScriptInclude(HtmlTextWriter writer, string filePath, string Id)
{
writer.AddAttribute(HtmlTextWriterAttribute.Id, Id);
writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript");
writer.AddAttribute(HtmlTextWriterAttribute.Src, filePath);
writer.RenderBeginTag(HtmlTextWriterTag.Script);
writer.RenderEndTag();
}
How can I modify to add "async"?
Much thanks as always,
Rhonda
According to the source code of the RenderBeginTag method, any attribute with value equals to null (but not String.Empty) will be rendered without quoted value. So, just call writer.AddAttribute("async", null); before calling of RenderBeginTag.

Bind with coffeescript

How can I call native bind method of function-object with coffeescript ? This is the example of what I am trying to achieve:
window.addEventListener("load",function(e){
this._filter(true);
}.bind(this);
)
Just add some parentheses around the function so that you can .bind the right thing:
window.addEventListener('load', ((e) ->
this._filter(true)
).bind(this))
That will use the native bind method instead of the usual var _this = this trickery that CoffeeScript's => uses.

Function argument with jQuery selector

Folks, this works correctly for me to hide any element where the class name starts with "o"
function hider() {$("*[class^=o]").hide();}
Now I'd like to be able to pass that "o" string in as the function's argument, and I have trouble with the syntax. Any help is appreciated.
It seems that something like this will work:
function hider(startsWith) {
$("*[class^="+startsWith+"]").hide();
}
try it in this fiddle:
http://jsfiddle.net/JECUL/
function hider(className) {$("*[class^="+className+"]").hide();}
Call like so
hider("o");