Dojotoolkit watch() not working on switch - javascript

I have a very annoying problem with watch() method from Dojo toolkit. I have a loop, that connects every input/widget in settings view (TweetView) with corresponding object. Connecting in my case is setting input to value from object and watch it for changes.
My problem is, that it works great for slider, but doesn't trigger handler for switch at all. Any ideas what could be wrong? I tried to debug it, but still no results. Here is a fiddle and the code:
var widget = registry.byId(namespace + "." + el);
widget.watch("value", handlers[root[el].type]);
widget.set("value", root[el].value);
http://jsfiddle.net/Em8GE/1/
Thanks in advice,
Dracco

this is unfortunately a known issue in dojo 1.9.0 and 1.9.1: https://bugs.dojotoolkit.org/ticket/17295
This is already fixed on dojox main branch and will be released in 1.9.2. The fix is detailed here: https://github.com/dojo/dojox/commit/43af4ba56f7b589f2afffb9161e21cc2cad40ad8

Related

Prevent copy on an empty iFrame (GWT RichTextArea)

I am required to prevent copy from a form. Using a oncopy handler works just fine on all <input/>-type fields.
Yet I fail to apply it to our "richtextarea", which is basically an empty iframe (src="about:blank" for what I have been able to gather; the page is GWT-generated, and the people before me developped quite an extensive framework around it).
I am able to get the iframe in the JavaScript, but I fail to have a correct handler (I tried adding one that logs, but it never does).
I have tried frame.oncopy, frame.contentWindow.oncopy, frame.contentWindow.document.oncopy, frame.contentDocument.oncopy. None of these does log to the console when I copy the iframe's content.
Does somebody have any lead for me? Any help appreciated (I've been stuck on this for some days now).
Having a cross-compatible solution would of course be ideal, but the main target is Firefox (the page is only open via a custom container based on Firefox 10).
Edit 2015-03-24
For those who want to try some debug script, the component I have trouble with is the one demonstrated here.
I have some native methods in the Java project to execute some custom JavaScript on it.
Below is some of the JavaScript I have unsuccessfully tried.
var frame = document.getElementsByTagName('iframe')[0];
function disallowCopy() {
alert('Gotcha!');
return false;
}
frame.oncopy = disallowCopy;
frame.contentWindow.oncopy = disallowCopy;
frame.contentWindow.document.oncopy = disallowCopy;
frame.contentWindow.document.body.oncopy = disallowCopy;
frame.contentDocument.oncopy = disallowCopy;
even though oncopy is a non standard event https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncopy and that there is no reliable way to prevent copying text,
you can check out the following bin
ensure the frame is loaded
use iframe.contentDocument.body to attch the event

Polymer, force core-drawer-panel drawer closed on ready

I am attempting to force the drawer of core-drawer-panel closed on polymer ready. Currently I have a core-drawer-panel as part of a custom element I am defining. I have tried the following:
"drawer" is the ID of the core-drawer-panel element.
<core-drawer-panel id="drawer" drawerWidth="155px" touch-action="pan-y" selected="main" narrow>
Polymer({
ready: function(){
this.$.drawer.togglePanel();
this.$.drawer.closePanel();
}
});
Neither of the two functions above seem to trigger the drawer closed at start, or seem to trigger it at all. They do reference the function correctly. I tried console.log(this.$.drawer.togglePanel); and get the correct function printed. Besides performing some CSS hackery can anyone tell me what I may be doing wrong?
I was able to get this working by forcing narrow layout e.g. forceNarrow="true", but this does not seem to solve my issue efficiently.
EDIT: I have also seen this related post. But forcing responsiveWidth to a large number doesn't seem to solve the problem....
Hmmm, as far as I understand, togglePanel(); and closeDrawer() only work when the core-drawer-panel element is in narrow mode.
To force your component to be in narrow mode, you seem to add the narrowattribute, but as far as I know narrowis only a getter, i.e. to force narrow mode you should use forceNarrow=true
Anyway, the ready() event don't seem the good place to force that kind of behaviour. I tried to do the opposite thing, setting forceNarrow=true and open the drawer on loading.
It didn't work with ready() but it worked well with domReady. See element lifecycle methods in the doc : https://www.polymer-project.org/docs/polymer/polymer.html#lifecyclemethods
Hope it helps...
There's a undocumented hidden property.
Just do:
Polymer({
ready: function(){
this.$.drawer.hidden = true;
}
});

Multiple timepickers in the same page bug

I notice a strange behavior when there are multiple timepickers in the same page.
After switching between the two timepickers, eventually one of them isn't removed/hidden, and will persist till we refresh the page.
I thought it was a problem with my code but then i did a test with a simple bootstrap example i found on google.
Fiddle bug example:
http://jsfiddle.net/kW3G7/282/
The only code that is used is:
`$('.timepicker').timepicker();
Thanks in advance.
Edit: i created a issue in there github project
Edit 2: It seems that the timepicker stops calling the document onclick event(code above)
$(document).on('mousedown.timepicker, touchend.timepicker', function (e) {
// This condition was inspired by bootstrap-datepicker.
// The element the timepicker is invoked on is the input but it has a sibling for addon/button.
if (!(self.$element.parent().find(e.target).length ||
self.$widget.is(e.target) ||
self.$widget.find(e.target).length)) {
self.hideWidget();
}
});
Solution, for now, remove the "touchend.timepicker" from the "on" event trigger.
I don't think it is the proper/final solution but it seams to work.

Dynamic CFTab onClose event

I simply can't find any real documentation on ColdFusion Layout Tabs. For the most part I've got them working, but I'd like to tie some logic to a close event. I was wondering if anyone had a working example they could show me? The catch is that I will need to trigger these events in JavaScript. But if you have a working version in plain ColdFusion, I'd still love to see it!
var tab = ColdFusion.Layout.getTabLayout("innerTabLayout").activeTab._cf_body;
$('#' + tab).on('close', blah); // doesn't work
tab.on('close', blah) // doesn't work
ColdFusion.Layout.getTabLayout("innerTabLayout").activeTab._cf_body.onTabClose( function(), blah ); //doesn't work
I have also tried setting the event on tab creation:
var tab = ColdFusion.Layout.createTab();
tab.onTabClose()
tab.on('close');
However, none of these work either. I've tried looking at EXT.JS which is what CFtabs were created from, but I don't seem to have any luck there either.
The Coldfusion.Layout object has a function for tab closing, so there must be a way to trigger it! (I would think, haha).
So after spending some too much messing around with the tab, I've got a solution.
ColdFusion.Layout.getTabLayout('innerTabLayout').activeTab.on('close', function(e) {
console.log(this) //this will return the tab object
console.log(e)//this also returns the tab object
});
This will trigger the event when the active tab within a parent is closed. I'm interested to see if there's another, better solution.

How to remove an event out of content script scope?

I'm trying to unbind an event from a specific element and upon research, I found this. Which is useful. In itself. I didn't know you could do that. But:
Is there a way to make it work in a browser/Chrome extension? I'm talking about content scripts.
The reason why this doesn't work the way it's described there is that the website which has attached the event in question with its own script is using a different jQuery object than the one in my extension's includes/ folder. And I can try to search the event via jQuery._data(el, 'click'); but that is my jQuery object, not the one of the website where the events are apparently stored. I'm glad I figured that out after hours of fiddling around.
Or maybe it is possible to access the website's jQuery object itself?
EDIT:
What I'm ultimately trying to achieve works in theory but … it's complicated. The original script uses a plugin event and keeps reinstalling it with .on('mouseleave',….
Anyway, this is what I got thanks to you, pdoherty926:
var $el = $('div.slideshow');
$('h2', $el).click(function(){ console.log('ouch!'); }); // test event
var $slides = $('.slides', $el).detach();
$copy = $el.clone(false);
$slides.prependTo($copy);
$el.replaceWith($copy);
The test event doesn't get triggered but the event I'm actually trying to remove still fires. I can imagine figuring it out, though, now that I got closer to my goal.
Okay, the aforementioned re-installation on mouseleave really messed up this otherwise satisfying suggestion. (The site is using the jQuery Timer plug-in by Cyntaxtech). So here's how I solved it instead: I simply changed the class name (-.-' )
Now the re-installation code cannot find the element anymore.
This is how my finished script looks like:
function stop_happening() {
var $el = $('div.fullwall div.slideshow');
$el
// first, stop the current automation.
.timer('stop') // Timer plug-in
// next, change class name in order to prevent the timer
// from being started again.
.removeClass('slideshow').addClass('slideshow-disabled-automation');
//--- copied some extra code from the website itself for the onclick
// events which are supposed to keep working. I wish I could do *that*
// programmatically but I'm glad I got as far as I got. ---//
// […]
}

Categories