I need to emulate the scroll event on an iframe in my Firefox addon. I used the code below, but it doesn't work and iframe scroll won't move. And another question for me is how initUIEvent knows which direction scroll event must be dispatched for? (Horizontally or Vertically)
var windows = require("window-utils"),
selectedBrowser = windows.activeBrowserWindow.gBrowser.selectedBrowser,
contentWindow = selectedBrowser.contentWindow,
document = selectedBrowser.contentDocument;
obj = document.getElementById("scrollable_frame");
evt = document.createEvent("UIEvents");
evt.initUIEvent("scroll", true, true,
windows.activeBrowserWindow.gBrowser.selectedBrowser.contentWindow, 2);
obj.dispatchEvent(evt);
I think that your code dispatches the event just fine. But it doesn't help solve your problem because it's the frame scrolling that triggers the scroll event, not the other way round. If what you need is to scroll the frame then you can choose the direct route: use window.scrollByLines or window.scrollByPages:
obj = document.getElementById("scrollable_frame");
obj.contentWindow.scrollByLines(1);
To scroll horizontally you can use window.scrollBy. This code will also trigger the scroll event as a side-effect.
Related
Similar to what's being seen here in Google's Material Design Responsive Interaction documentation, I would like to have a button react to being pressed by flashing a color briefly but then returning to the original color gradually.
Can this effect be achieved using the default Xamarin.Forms Button control with a click handler method? Or must a custom renderer be implemented to try and create this effect?
You're looking for the animation methods available on ui components. Essentially you need to add a click handler to your button that runs animations (first your color change, then your gradual fade back using async/await). I have added a link to a sample that animates a size change, but the theory will remain the same.
// add a gester reco
this.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(async (o) =>
{
await this.ScaleTo(0.95, 50, Easing.CubicOut);
await this.ScaleTo(1, 50, Easing.CubicIn);
if (callback != null)
callback.Invoke();
})
});
I am trying to dynamically load images in Snap.svg and then once the image has loaded do some processing to it. The load event is firing in Chrome, Firefox and Opera but is does not fire in Internet Explorer or Safari.
I have this setup in Plunker
var s = null;
var g = null;
var image = null;
//$(document).ready(function($) {
$(window).load(function() {
s = Snap("#svgout");
g = s.g();
$("#baseimage").attr("src", "http://www.customcribboards.com/resources/svgs/preview/29.png");
$("#baseimage").on("load", function() {
console.log("hidden image loaded");
image = g.image($(this).attr("src"), 0,0, 400,400);
image.node.onload = function () {
console.log("svg image loaded 1");
};
$(image.node).on("load", function() {
console.log("svg image loaded 2");
});
});
});
Any ideas how to make the onload event fire on an svg image load in Internet Explorer and Safari?
For a pure SVG document (SVG being the root element), I have found the following.
In IE9+ (IE11, Edge), putting an onload= in the root element doesn't seem to be respected per the spec or expectation. Instead, IE seems to fire the event "right away" i.e. after the opening of the root element is received, but before the DOM is fully loaded. So, your Javascript cannot find elements you'd expect to be there for example. I have experimented with delays etc. but that's a hokey kludge.
In Firefox, onload= in the root element works as expected, when the DOM is complete, the onload fires.
A workaround for IE is to omit the onload= in the root tag, but put one in a child element that is "late" or "last." This seems to defer firing onload= until the DOM is fully loaded. This kludge is not respected in Firefox, and actually seems to maybe break the triggered Javascript, in at least my case.
So the FF and IE approaches are divergent and seem mutually exclusive.
Currently I have a page which on load scatters draggable divs randomly over a page using math.random
Using media queries however the page uses packery to display the same images for browser widths under 769px in a grided fashion.
I had the idea that it could be interesting to create a 'sort/organize' button which would rearrange these divs using packery and remove the draggable class already applied, however i have no idea if this is possible or how to go about it. If there is any method of animating this process that would also be a bonus!
If anyone could at the very least point me in the right direction i would be extremely thankful!!
Hopefully this gives you a bit of a starting point.
I would read up on JQuery as it has some useful helpers for DOM manipulation.
I don't think this is the most efficient way to do it, and I think you will need to rethink your test harness for doing this in the future, but hopefully this gets you started.
Firstly I've added a button to trigger the sort
<div class="rotate" id="contact">Contact</div>
<div id="logo">Andrew Ireland</div>
<button id="sort">sort</button>
Then updated the script to override the css setting to switch between draggable view and item view.
// general wait for jquery syntax
$(function(){
// trigger the layour to sort get the packery container
var container = document.querySelector('#container.packery');
var pckry = new Packery( container );
//button function
$("#sort").click(function(){
//Hide all the dragged divs
//ui-helper-hidden is a jquery ui hider class
if($('.box').css('display') == 'block') {
$('.box').css({'display':'none'});
//Show all the item class's
$('.item').css({'display':'block'});
//show the container
$('#container').css({'display':'block'});
// trigger the layour to sort
pckry.layout();
} else {
//hide all the item class's
$('.item').css({'display':'none'});
//hide the container
$('#container').css({'display':'none'});
//show the draggable box's
$('.box').css({'display':'block'});
}
});
$( ".pstn" ).draggable({ scroll: false });
$(".pstn").each(function(i,el){
var tLeft = Math.floor(Math.random()*1000),
tTop = Math.floor(Math.random()*1000);
$(el).css({position:'absolute', left: tLeft, top: tTop});
});
});
As I said this is more to get started. The packery documentation details how to trigger its layout functions so another approach would be to only have the draggable elements, and put these inside a packery container. Then when you want to sort them you can just trigger that the packery.layout() function.
I hope this is helpful, I am only just getting started on stack overflow so any feedback would be appreciated.
I have a really annoying issue with Autocomplete with Prototype 1.6. I set up and dialog-style div with a form, which contains an Autocomplete. Everything works fine until I click the scroll bar, or drag it; it closes the list of suggestions. I checked this solution but now I got an javascript error
event.srcElement is undefined
I was checking the controls.js and tried to catch the event object inside the onBlur event, but it travels empty. Printed the offsetX property and is undefined. Looks like the event doesn't exist anymore. either way, it prevents that the list closes but, If I click outside the area, the list now doesn't close. And that's kinda of issue too
Anyone with this same issue? Any idea?
Thanks in advance
I was having the exact issue yesterday, but after doing some r&d I got a pretty handy fix for this.
By default this script was hiding the result div (Suggestion List) on the blur event on the search text box so as soon as we click on result div's scroll bar focus gets lost from input element & result div closes. So I did a small edit in controls.js to change the behavior of script, so now result div close method doesn't invoke on blur (focus out) from input element but triggered on the click on the document except the text input element.
For your convenience I've put the edited controls.js here.
If you like to know what has changed in JS file, here it is;
Added a event listener to the document. Just below this line
"Event.observe(this.update, "keypress", this.onKeyPress.bindAsEventListener(this));"
Event.observe($(document), "mouseup", this.onMouseup.bindAsEventListener(this));
Added a new onMouseup method.
onMouseup: function(event) {
if(!this.hasFocus) {
this.hideTimeout = setTimeout(this.hide.bind(this), 250);
this.hasFocus = false;
this.active = false;
}
},
Modify the onBlur method (Comment out two line in block)
onBlur: function(event) {
//this.hideTimeout = setTimeout(this.hide.bind(this), 250);
//this.active = false;
this.hasFocus = false;
}
I hope this will solve your issue.
Thanks
Vinod Kumar
I'm doing some Mac development in a WebView. I want to expand URLs that have been shortened by a url shortener, and display that expanded URL to the user. So, given a link whose src attribute is set to http://is.gd/xizMsr, when the user hovers over the link I want the title tooltip to display http://google.com
My link tag looks like this:
Here's a shortened link to google
And here's the relevant javascript, which will use XMLHttpRequest to fetch the expanded URL and then update the title
var myRequest;
var mousedOverElement;
var isLoading = false;
function myFunction(anObject) {
if (isLoading == false) {
isLoading = true;
mousedOverElement = anObject;
var link = anObject.getAttribute('href');
var encodedURL = encodeURI(link);
var url = 'http://is.gd/forward.php?format=simple&shorturl=' + encodedURL;
myRequest = new XMLHttpRequest();
myRequest.open("GET", url);
myRequest.onreadystatechange = onStateChange;
myRequest.send();
}
}
function onStateChange() {
if (myRequest.readyState==4) {
if (myRequest.status==200) {
mousedOverElement.setAttribute('title',myRequest.responseText);
}
isLoading = false;
}
}
The problem is, when I hover over the link, and then stop moving the cursor, the title attribute is set properly, but the tooltip is not shown. I have to move the mouse again to make the tooltip show up. I don't necessarily have to move the cursor off of the link and then back over it, but simply moving a few pixels while remaining hovered over the link will do the trick.
I know that the title is being set properly from a combination of using the Web Inspector and the Javascript debugger in Safari. In fact, pretty much as soon as I hover over the link, I see the Web Inspector's view of the DOM in the "elements" tab update with the new title. But, if I take my hand off of the mouse, the tooltip never shows.
My assumption here is that WebKit only shows a tooltip when the user is moving the mouse. Is there a way to sort of "wake up" webkit, even if the cursor is not moving? Or am I better off implementing this with some of my own DHTML-ish magic instead of relying on the title attribute?
What about an element (move it over the anchor) or a wrapper (positive z-index) with a transparent background which will (onmouseover):
first add the anchor's title (you will have to modify your function)
and then change its (negative for the covering element) z-index (effectively putting the anchor in the foreground)
This way the title will be readily available. If necessary you can add a setTimeout() between step 1 and 2.
Or you could simply use setAttributeNode to modify the title attribute value.
You said
"The problem is, when I hover over the
link, and then stop moving the cursor,
the title attribute is set properly,
but the tooltip is not shown."
Its likely that because the title did not exist when you started the mouse hover, it could not display any tooltip (there was nothing to display). So no tooltip will appear. When you move the mouse again, this time it does have a title attribute, so it can display a tooltip. Theres not much you can do about that, its just how the browser works.
Instead your could try using a jQuery tooltip: http://www.reynoldsftw.com/2009/03/10-excellent-tooltip-plugins-with-jquery/
With jQuery you should be able control it so that a tooltip appears as soon as the title is set.