Now that webkitGetAsEntry() has been activated on Chrome 21 to allow folder drag&drop, is there an equivalent in mozilla - mozGetAsEntry(), getAsEntry(), or something else? I've only been able to find very minimal info on webkit's method and the whatwg proposal; I can find nothing for Firefox (or any other browsers).
References:
http://wiki.whatwg.org/wiki/DragAndDropEntries#DataTransferItem.getAsEntry.28.29
http://updates.html5rocks.com/2012/07/Drag-and-drop-a-folder-onto-Chrome-now-available
http://blog.protonet.info/post/26894439416/html5-drag-drop-files-and-folders
What you're looking for is the mozGetDataAt() method, which returns an nsIFile object:
https://developer.mozilla.org/En/DragDrop/Recommended_Drag_Types#file
So to answer your question, the equivalent would be:
mozEntry = event.dataTransfer.mozGetDataAt(0);
or..
event.dataTransfer.mozGetDataAt(0).isFile() etc.
Documentation for nsIFile(contains the fields that are in the webkit entries):
https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIFile
Related
I am migrating from Firefox to Chrome and I haven't been able to copy or emulate my multiple criteria queries. In Firefox it works as a breeze using a javascript script that I have found here but after a lot of testing I think is not possible to implement in Chrome. Take a look at my modified version for converting currency:
javascript:var s='%s'; url='http://www.google.com/finance/converter?a=%s&from=%s&to=%s'; t=''; qc=0; chunks=url.split('%s'); for(i=0; i<s.length; i++){if(s.charAt(i)=='"')qc=qc^1; t+=((s.charAt(i)==' '&&qc)?'^':s.charAt(i)); }args=t.split(/\s/); nurl=''; for(i=0; i<chunks.length; i++){nurl+=chunks[i]; if(args[i]!=undefined) {args[i]=args[i].replace(/\^/g,' '); nurl+=args[i]; }}location.replace(nurl,'< BR>');
. . Sadly this functionality was intentionally disabled, as per this bug report on Chromium (see comment #3).
. . If you want to replicate that functionality, you need to use the Omnibox API. Check http://developer.chrome.com/extensions/samples.html#be68e4d262d74d2457999fc402f5bf5e for an example. It is very easy to adapt the sample code for your needs.
Chrome has supported this since at least the date of your question. Here is how I do it:
javascript: (function(){
var s='%s';
url='https://www.google.com/search?hl=en&q=%s&tbo=1&tbs=qdr:%s';
query='';
urlchunks=url.split('%s');
schunks=s.split(';');
for(i=0; i<schunks.length; i++)query+=urlchunks[i]+schunks[i];
location.replace(query);
})();
You can use any URL that has more than one paramenter, which takes more than one argument.
To use from omnibox: search word(s);search word(s)
Asking about Object.defineProperty as demonstrated below:
function testComponent(){
var testProperty;
Object.defineProperty(this, "testProperty",
{
get : function()
{
return testProperty;
},
set : function(val)
{
testProperty = val;
}
});
}
Where it would be used like so:
testObject = new testComponent();
testObject.testProperty = "testValue";
Based on what I've seen so far, it looks like there is no cross browser solution, as I've tried using es5-shim with no luck, but I would like to confirm. I also found a reference to this post and my tests still fail in IE 7 & 8, can anyone shed any light on this?
I remember looking through a related question a few months ago somewhere on S/O and I think I saw someone had written a solution for this in an answer. Any general workarounds for getter / setters would also be appreciated. The idea is that I need some equivalent of a getter setter on an object without passing the parameter change through a method. I don't need IE6, but I would like to support browsers in the range of IE7+ ff 3.6+ , etc
QUnit tests below: (jsFiddles)
(these pass in all browsers on my machine except IE 7 & 8
direct use of defineProperty, no shims: http://jsfiddle.net/uSYFE/
fiddle using the ES5 shim, I'm assuming all I need to do is include it? : http://jsfiddle.net/hyperthalamus/ntwDy/
fiddle using the IE recommended solution : http://jsfiddle.net/hyperthalamus/xfvz3/
According to ES5-shim:
/!\ Object.defineProperty
This method will silently fail to set "writable", "enumerable", and "configurable" properties.
Providing a getter or setter with "get" or "set" on a descriptor will silently fail on engines that lack "defineGetter" and "defineSetter", which include all versions of IE up to version 8 so far.
IE 8 provides a version of this method but it only works on DOM objects. Thus, the shim will not get installed and attempts to set "value" properties will fail silently on non-DOM objects.
https://github.com/kriskowal/es5-shim/issues#issue/5
So you know your answer. It can be done on DOM elements, that's it (and on IE8 only).
I'd suggest you just use get/set methods if you want IE7 to work.
For older IEs you'd have to make sure your property is a dom object (even a fake tag) and use onPropertyChange to get notified. See this post by John Dyer for more details.
I've had this same question myself. (See here.) It doesn't look like it's fully possible in IE8 or lower. Otherwise the ES5 Shim is your best bet.
In IE, I can go like:
var x = document.getElementById("header");
alert(x.all[0].tagName);
If I try that in Firefox, I get the error "all is undefined".
What is the Firefox equivalent of IE's .all property?
.all is a Microsoft-specific extension to the DOM, and is not supported by any other browsers (except Opera, I believe, who simulate it in order to improve compatibility with sites written for IE).
You can use things like x.children and x.childNodes, or x.getElementById() and x.getElementsByTagName() to reference elements below the current one in the tree, depending on your usage. I suspect in this case x.children is what you're after.
all would be the name of an array. It is not a native javascript keyword.
You may want to look at childNodes instead.
I have a Javascript function that calculates a value and re-inserts the value into a <td> while also injecting the value into a hidden <input>.
This is my function:
$("input[name^='policies']:checkbox").change(function() {
var el = $(this);
if (el.is(":checked")) {
no_policies++;
}
if (el.is(":not(:checked)")) {
no_policies--;
}
subscription = no_policies*policy_cost;
first_payment = Math.ceil(subscription+no_policies*(policy_cost/days_month)*days_left).toFixed(2);
alert(first_payment);
$("td#first_payment").text("R "+first_payment);
$("input#first_payment_txt").val(first_payment);
$("td#subscription").text("R "+subscription.toFixed(2));
});
Everything works on IE8 up until this statement:
first_payment = Math.ceil(subscription+no_policies*(policy_cost/days_month)*days_left).toFixed(2);
I suspect IE8 is having trouble with Math.ceil, is that true? Also, is there any other function/method I can use to circumvent this?
Thanks in advance.
Answer is yes to both your questions:
Math.ceil()
Math.round()
Supported in the following document
modes: Quirks, Internet Explorer 6
standards, Internet Explorer 7
standards, Internet Explorer 8
standards, Internet Explorer 9
standards.
See also general table of Javascript compatibility for different IE versions:
Seems like microsoft supports Math.ceil on all versions beginning from ie6 (msdn), maybe one of the variables use is undefined or you devide by 0 or one of the variables is not a number so the result cannot be ceiled/rounded.
IE8 actually has a fairly good debugger. I recommend hitting F12 to open it, then going to the Script tab and selecting the Start Debugging button. This will let you set breakpoints along the script, letting it stop and wait for you to analyze variables as it executes at your own pace. As Adriano mentions in his comment, it's most likely an issue with one of your variables.
Dan Webb's Low Pro UJS extension to Prototype offers the following elegant DOM Builder:
var listItem = $li({ id : 'item-1' },
$strong("Some text")
);
// returns a node equivalent to: <li id="item-1"><strong>Some text</strong></li>
$('a_list').appendChild(listItem);
While this works like a dream for us in Firefox and Safari, it explodes with delight in IE 6 and IE7 with the error "Object doesn't support this property or method"
Any insight into what Dan Webb's DOM Builder might be doing to wrap Element.new that isn't compatible with IE?
I would imagine the "Object doesn't support this property or method" error is coming from a call to one of Prototype's extended element methods (which are not applied automatically in IE). However, all the elements you're dealing with are coming from LowPro or the $() function, which should extend the elements for you.
You could try this and see if it resolves the problem:
var listItem = Element.extend($li({id: 'item-1'},
Element.extend($strong("Some text"))
));
$('a_list').appendChild(listItem);
If that fixes it then LowPro isn't extending the elements, which is very odd. If it doesn't then there must be something else wrong, can you post a demo page somewhere?
Since v1.6, Prototype has a had a built-in element constructor. The syntax is just a little different than Low Pro.
$('a_list').insert(new Element("li", {id: 'item-1'})).update('some text').wrap('strong')