I'm writing a Firefox add-on and for the <scale> XUL element, onsyncfrompreference doesn't seem to be called (Firefox 14). Here's my preference:
<preferences>
<preference id="pref-sensitivity" name="bbaddon.sensitivity" type="string"/>
...
</preferences>
and here is the scale:
<scale min="1" max="100" increment="1" preference="pref-sensitivity"
id="bb-sensitivity"
onsynctopreference="Application.console.log('onsynctopreference called')"
onsyncfrompreference="Application.console.log('onsyncfrompreference called')" />
The logs are just for debugging at the moment, onsynctopreference is called no problem as it shows up on the console, but there's no entry from onsyncfrompreference. I have a default value defined in defaults.js.
If you look at the implementation of this feature in preferences.xml, onsyncfrompreference will only be called for "editable" elements. As to what is considered "editable", you can see that below. Some elements are always considered editable, others have to specify preference-editable="true" attribute explicitly. In your case it's the latter meaning that your fix would look like this:
<scale min="1" max="100" increment="1" preference="pref-sensitivity"
preference-editable="true" id="bb-sensitivity"
onsynctopreference="Application.console.log('onsynctopreference called')"
onsyncfrompreference="Application.console.log('onsyncfrompreference called')" />
I've worked around this using Javascript:
<script type="text/javascript">
var loaded = false;
//load preferences
var prefs = Components.classes["#mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("extensions.bb");
prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
function loadpref() //call this in the prefwindow onload
{
document.getElementById('bb-sensitivity').value = prefs.getCharPref('sensitivity');
loaded = true;
}
function setpref(sensitivity)
{
if(loaded) //onchange for scale fires before onload for the window
{
prefs.setCharPref('sensitivity',sensitivity);
}
}
</script>
and the scale element:
<scale min="1" max="100" increment="1"
preference="pref-sensitivity"
id="bb-sensitivity"
onchange="setpref(this.value);"
/>
I'll leave this question open for now to see if anyone else can help. I'd still like to do this the 'correct' way.
Related
I have the following markup:
<paper-input id="alias-input" floatingLabel label="Person Alias (eg: King, Eldest Son, Mooch, etc.)"></paper-input>
<paper-input id="birth-year-input" floatingLabel label="Birth Year (eg: 1969)" validate="^[12][0-9][0-9][0-9]$"></paper-input>
<div center horizontal layout>
<paper-button id="add-button" on-click="{{addPerson}}" class="add" label="Add Person"></paper-button>
</div>
To go along with this markup I have an addButton method which does:
addPerson(_) {
// Add the person
// ...
// Clear the inputs
($['alias-input'] as PaperInput)..inputValue = ''..commit()..blur();
($['birth-year-input'] as PaperInput)..inputValue = ''..commit()..blur();
}
This correctly clears the contents of the inputs, which I want. But I also want the PaperInput help label to drop down onto the line as it is when the control is first loaded. My hope was that the call to blur() would do that. Is there some other call to achieve this?
It seems you need to call blur on the actual <input id='input'> element inside <paper-input> not the <paper-input> itself.
I got it working with
import 'dart:js' as js;
var inp = $['alias-input'] as PaperInput;
inp.inputValue = '';
new js.JsObject.fromBrowserObject(inp).callMethod('inputBlurAction', []);
alternatively you can do it like
var inp = $['alias-input'] as PaperInput;
inp.inputValue = '';
inp.querySelector('* /deep/ #input') // not yet supported with polyfills
..focus() // blur doesn't work when the field doesn't have the focus
..blur();
I'm using a slider to change the min/max for chart I'm displaying with flot.
This is my slider HTML:
<div id=timerangeslider>
<form>
<div class="ui-grid-a" id="slider3">
<label for="slider-2">Anzeige-Zeitraum (in Stunden):</label>
<input type="range" name="slider-2" id="slider-2" data-highlight="true" min="1" max="48" value="24">
</div><!-- /ui-grid -->
</form></div>
And this is my jQuery:
function timerangeslider() {
$(document).ready(function(){
$("#slider-2").change("click",function() {
timerange = $("#slider-2").val();
energyPlot(d,timerange)
});
});
}
The function gets called on "pageinit".
It calls another function "energyPlot" which updates my chart (using flot)
Problem with this solution is, that is re-draws my chart on every change of the value of "#slider-2"
So this works, but looks like crap.
Another solution would be this:
function timerangeslider() {
$(document).ready(function(){
$(document).on("click","#timerangeslider",function(event) {
timerange = $("#slider-2").val();
energyPlot(d,timerange)
});
});
}
Problem here is, that on my device (with Phonegap) it does not recognize touches on the actual slider. You can click the number left to the slider and it get's the touch, but not if you drag the slider.
It works in browser though.
Any ideas how to react to touches on the actual slider (on device with phonegap)
Or any ideas for the first solution on how to re-draw the chart only when the slider stopped?
Just found the solution here jQueryMobile slider change event
It seems there is an event for a slider called "slidestop" and you can listen for it.
So I used this:
function timerangeslider() {
$("#slider-2").on("slidestop",function(event) {
timerange = $("#slider-2").val();
energyPlot(d,timerange);
});
}
I'm developing an extension for FireFox. I use a XUL deck element that contains a XUL browser element. Unfortunately, whenever the page displayed in the browser has an HTML title attribute, the value of this title attribute will not show up as a tooltip.
How can I get tooltips to display correctly?
There is no mechanism to automatically display title attributes in tooltips - the browser window has special code for that and you need to replicate this code in your extension. This means that you need to define a <tooltip> element, e.g.:
<popupset>
<tooltip id="browserTooltip" onpopupshowing="return fillTooltip(this);"/>
</popupset>
You should use this tooltip in your <browser> element, like this:
<browser tooltip="browserTooltip"/>
And you should create a fillTooltip() function that will be called whenever your tooltip shows up. It will need to look at the HTML element that the mouse pointer hovers over, check its title attribute and put the value of the attribute into the tooltip. The function performing this job in Firefox is FillInHTMLTooltip() though you might want to go with a simpler variant like this (untested code):
function fillTooltip(tooltip)
{
// Walk up the DOM hierarchy until we find something with a title attribute
var node = document.tooltipNode;
while (node && !node.hasAttribute("title"))
node = node.parentNode;
// Don't show tooltip if we didn't find anything
if (!node)
return false;
// Fill in tooltip text and show it
tooltip.setAttribute("label", node.getAttribute("title"));
return true;
}
I found the solution for those who are interested, it's by adding a tooltip property to the XUL browser element with the following value:
tooltip="aHTMLTooltip"
Or adding it programmatically using javascript like this:
browser.setAttribute('tooltip','aHTMLTooltip');
for more details check: https://bugzilla.mozilla.org/show_bug.cgi?id=451792#c1
Working example:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window id="mainWindow" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" title="NanoFL" width="800" height="600" persist="screenX screenY width height sizemode">
<script>
<![CDATA[
function fillTooltip(tooltip)
{
var nodes = document.getElementById("browser").contentWindow.document.querySelectorAll(":hover");
for (var i=nodes.length-1; i>=0; i--)
{
if (nodes[i].hasAttribute("title"))
{
tooltip.setAttribute("label", nodes[i].getAttribute("title"));
return true;
}
}
return false;
}
]]>
</script>
<browser id="browser" src="chrome://nanofl/content/index.html" flex="1" disablehistory="true" tooltip="browserTooltip" />
<tooltip id="browserTooltip" onpopupshowing="return fillTooltip(this)"/>
</window>
I have a little problem, and I can't figure out where does it come from.
I'm using jQuery UI (and of course jQuery)
I have the following HTML:
<input type="checkbox" id="test" value="test"/>
<label for="test">Show Test</label>
<div id="checkedDiv"></div>
and the following JS:
function clickChange() {
var currentText = this.nextSibling.innerHTML;
this.nextSibling.innerHTML =
(this.checked) ? currentText.replace("Show","Hide") :
currentText.replace("Hide", "Show");
$("#checkedDiv").text(this.nextSibling.innerHTML);
}
var test=document.getElementById("test")
test.onclick=clickChange;
$("#test").button();
The problem is that on the first click, the innerHTML doesn't change. After that it works.
And to be a little more disappointed, the nextSibling seems to change (at least from what is seen in the #checkedDiv), but doesn't appear on the DOM Tree on firefox/firebug.
Am I missing something ?
Thanks
(if you want to try it yourself, it's here: http://jsfiddle.net/nvNKW/3/ )
EDIT:
The (or at least one) solution is to use label as suggested by Aziz Shaikh:
function clickChange() {
var currentText = $(this).button( "option","label");
$(this).button( "option","label",(this.checked)? currentText.replace("Show","Hide") : currentText.replace("Hide", "Show"));
}
And there is no need to change the html or the button initialisation.
Try setting the label using $("#test").button({ label: newText }); instead of this.nextSibling.innerHTML
Edit: So your fixed JS function would be:
function clickChange() {
var currentText = this.nextSibling.firstChild.innerHTML;
var newText = (this.checked) ? currentText.replace("Show","Hide") : currentText.replace("Hide", "Show");
$("#test").button("option", "label", newText);
$("#checkedDiv").text(this.nextSibling.innerHTML);
}
It's because nextSibling() also returns text nodes. You are changing the blank empty space after the input, not the next tag.
jQuery makes it easy, do
$(this).next('label').html()
I'm trying to get an element to move from right to left in XUL. I am doing this with a toolbar and want one toolbarbutton w/ a label to remain anchored to the right, while one of them moves from right to left, starting to the left of the anchor.
I'm trying to achieve this effect by modifying marginLeft, but my element stays still. I'm not really sure why it does not move.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE overlay >
<overlay id="my-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript">
// Install load handler
var marginLeft = 0;
window.addEventListener("load", function(e) {
function moveIt() {
document.getElementById("moveit").style.marginLeft = marginLeft + "px";
marginLeft -= 30;
}
setInterval(moveIt, 1000);
}, false);
</script>
<vbox id="browser-bottombox">
<toolbar id="theToolbar">
<!-- holds the scrolling items and the refresh time -->
<hbox id="scrollingItemContainer" flex="1" align="end">
<!-- container for our scrolling items -->
<spacer flex="1"/>
<hbox id="movingItems" align="end">
<toolbarbutton id="moveit" label="moving"/>
</hbox>
<hbox>
<toolbarbutton id="rightAnchor" label="right"/>
</hbox>
</hbox>
</toolbar>
</vbox>
</overlay>
Any help you can provide will be helpful. I've tried this on FF4, but I think the problem exists on FF3 as well.
I should note that if I add a spacer with flex=1 after scrollingItemContainer then I see the item move, but it is not anchored to the right.