Is it possible to change the FineUploader options after it has been constructed? I would like to construct the instance once, but then change the itemLimit based on the circumstances. So I would construct the instance like this:
App.fineUploader = new qq.FineUploaderBasic({ itemLimit: 25 });
And then change the itemLimit at some point:
App.fineUploader.setOption('itemLimit', 10);
I can't seem to find a function like that in the docs. Am I missing something?
I think thats not possible on the current version, however you can try overriding the limit as a workaround, here is an example (JS):
$("#uploader").fineUploader()
.on("validate", function() {
if (itemLimitOverride > 0) {
return itemLimitOverride > $(this).fineUploader("getNetUploads");
}
});
An you set itemLimitOverride to an non 0 value in-scope.
Check this thread: https://github.com/Widen/fine-uploader/issues/999
Related
I've been able to add a list of suggestions to autocomplete but there is a large list of other suggestions as well.
Is there a way to get rid of the default autocomplete suggestions?
I'm looking at the source here and here and it doesn't describe anything about it. Here is what I have so far:
public function codeCompleter(editor, session, position, prefix, callback):void {
var row:int = position.row;
var column:int = position.column;
if (prefix.length === 0) {
callback(null, []);
}
var testing:Boolean = false;
if (testing) {
callback(null, attributes);
}
else {
callback(null, [{value:"addedToStage"},{value:"test"},{value:"test1"},{value:"adding"},{value:"added"}]);
}
}
I tried setting the completers to an empty array but no effect:
editor.setCompleters([]);
The problem was on my end. The version I was using must have been outdated. I updated to a newer version and the following code clears the auto complete list:
// either line does it
languageTools.setCompleters(null);
languageTools.setCompleters([]);
FYI:
Using version 1.2.6+, 12.03.2016
PS Sorry to anyone looking into this. I will post version numbers in future questions.
Quoted from Marionette.Behavior documentation
Finally, the user must define a location for where their behaviors are stored.
A simple example of this would look like this:
Marionette.Behaviors.behaviorsLookup = function() {
return window.Behaviors;
}
But window.Behaviors is undefined. When I use window everything is good. Do I miss something?
It's undefined because you probably haven't defined it yet. You would create an object window.Behaviors = {} that would be attached to the window when the app starts. From there you could register behaviors off of that and reference window.Behaviors like so,
window.Behaviors.ExampleBehavior = Marionette.Behavior.extend({
defaults: {},
events: {},
//etc..
});
Then inside of your behaviorsLookup, returning window.Behaviors won't be undefined. Here's the documentation explaining it further
Is it possible to use nsISelectionController to watch when a a highlight/selection is made?
I know that there are different selection scopes. I want to watch when a user makes a selection in the default scope seen at MXR - nsISelectionController Constants.
Kind of like an addEventListener on select change but on the text nodes of the document.
Thanks
I found a solution but it doesn't use nsIController as #Neil had recommended in a SO topic HERE to look at viewSource.js.
Im still interested in a nsIController solution if possible, im trying to understand that sucker it confuses me.
So this is how you observer for a selection:
var mylis = {
timeout: 0,
notifySelectionChanged: function(doc, sel, reason)
{
if (!this.timeout) {
this.timeout = setTimeout(function() {
console.log('notifySelectionChanged','doc=',doc,'sel=',sel,'reason=',reason);
mylis.timeout = 0;
}, 1000);
}
}
}
gBrowser.contentWindow.getSelection().QueryInterface(Ci.nsISelectionPrivate).addSelectionListener(mylis);
//gBrowser.contentWindow.getSelection().QueryInterface(Ci.nsISelectionPrivate).removeSelectionListener(mylis);
the timeout is important because otherwise it will slow down the browser thread. you can see as you highlight its all gimicky. viewSource.js used 100ms so I would reocmmend that.
MXR - viewSource.js
Is it possible to know if Backbone.Model.set() has changed/not-changed anything without events if possible? Reason being: if I use events it will look like:
listen to change:something
do something if value has changed
model.set("something", "value")
But what if change does not happen? How do I know that? Also with event handlers, I need to remove them approperately. For example, if I do it this way, I need to remove the handler if a change does not happen
Here is a simple solution that hides Events, into a simple synchronous function that returns if set has an effect.
I choose to implement this in a different function name, but you can also override the default set behavior.
var M = Backbone.Model.extend({
setThatLetsYouKnow: function(key, value){
var thisSetHasEffect = { flag: false};
this.listenToOnce(this, "change", function(){
thisSetHasEffect.flag = true;
});
this.set(key, value);
return thisSetHasEffect.flag;
}
});
And the result is:
var m = new M();
m.setThatLetsYouKnow("key",2)// return true
m.setThatLetsYouKnow("key",2)// reutrn fasle
Of Course, you need to add support to all different kind of set argument, this is just the Idea.
I've build a livesearch with the jQuery.ajax() method. On every keyup events it receives new result data from the server.
The problem is, when I'm typing very fast, e.g. "foobar" and the GET request of "fooba" requires more time than the "foobar" request, the results of "fooba" are shown.
To handle this with the timeout parameter is impossible, I think.
Has anyone an idea how to solve this?
You can store and .abort() the last request when starting a new one, like this:
var curSearch;
$("#myInput").keyup(function() {
if(curSearch) curSearch.abort(); //cancel previous search
curSearch = $.ajax({ ...ajax options... }); //start a new one, save a reference
});
The $.ajax() method returns the XmlHttpRequest object, so just hang onto it, and when you start the next search, abort the previous one.
Assign a unique, incrementing ID to each request, and only show them in incrementing order. Something like this:
var counter = 0, lastCounter = 0;
function doAjax() {
++counter;
jQuery.ajax(url, function (result) {
if (counter < lastCounter)
return;
lastCounter = counter;
processResult(result);
});
}
You should only start the search when the user hasn't typed anything for a while (500ms or so). This would prevent the problem you're having.
An excellent jQuery plugin which does just that is delayedObserver:
http://code.google.com/p/jquery-utils/wiki/DelayedObserver
Make it so each cancels the last. That might be too much cancellation, but when typing slows, it will trigger.
That seems like an intense amount of traffic to send an ajax request for every KeyUp event. You should wait for the user to stop typing - presumably that they are done, for at least a few 100 milliseconds.
What I would do is this:
var ajaxTimeout;
function doAjax() {
//Your actual ajax request code
}
function keyUpHandler() {
if (ajaxTimeout !== undefined)
clearTimeout(ajaxTimeout);
ajaxTimeout = setTimeout(doAjax, 200);
}
You may have to play with the actual timeout time, but this way works very well and does not require any other plugins.
Edit:
If you need to pass in parameters, create an inline function (closure).
...
var fun = function() { doAjax(params...) };
ajaxTimeout = setTimeout(fun, 200);
You will want some kind of an ajax queue such as:
http://plugins.jquery.com/project/ajaxqueue
or http://www.protofunc.com/scripts/jquery/ajaxManager/
EDIT:Another option, study the Autocomplete plug-in code and emulate that.(there are several Autocomplete as well as the one in jquery UI
OR just implement the Autocomplete if that serves your needs