So my example is really basic. Actually not even the basic example from the Timeglider examples is working:
var tg1 = {};
$(function () {
tg1 = $("#placement").timeline({
"icon_folder":"timeglider/icons/",
"data_source":"json/idaho.json"
});
tg_actor = tg1.data("timeline");
tg_actor.zoom(1);
});
It says that tg1.data("timeline")is undefined. Even though there is data in there.
So my issue is that I cannot create an instance of the Timeglider plugin. So I'm not able to use it's functions. Could someone tell me why the data object is always undefined?
Here it is working...
So I found this running example: http://www.avo.alaska.edu/includes/js/timeglider/kitchen_sink.html and here it is working properly. I studied the code and it's nearly the same I have. So what could I have done different?
Working with older jQuery version
http://code.jquery.com/jquery-1.11.2.min.js is working without an error. How can I use the latest jQuery? Even with the migrate plugin I get the same error.
Working with 1.11.2 of jQuery (http://code.jquery.com/jquery-1.11.2.min.js) so it seems like this plugin is just no compatible to the latest version.
Related
I've tried to setup a testing environment with mocha, phantomjs and istanbul (and grunt). It works great so far, but when it comes to angular-testing i got some problems. I want (and need) to use angular-mocks, but as soon as I include it in my test.html, I get the following console-error in my browser:
Uncaught TypeError: (window.beforeEach || window.setup) is not a function
The matching code in angular-mocks.js is the following one:
(window.beforeEach || window.setup)(function() {
annotatedFunctions = [];
currentSpec = this;
});
This happens both for the current version (1.4.3) and for an old version which apparently worked in another project: 1.3.15.
What am I missing?
I fixed it.
The problem was, that i included my librarys (including angular-mocks.js) before mocha.js which apparently doesn't work.
I am using Dojo 1.9.1 and lodash.compat 1.3.1.
I am attempting to replace the deprecated dijit/_Widget.getDescendants() function. The deprecation warning says to use getChildren() instead, but that does not recurse.
This is what I have so far. It works fine in Chrome and Firefox, but results in an unhelpful [object Error] in IE7.
function get_widget_descendants(parent_widget) {
return _(query("[widgetid]", parent_widget.domNode))
.map(registry.byNode)
.value();
}
Here is a JSFiddle demonstrating how it's supposed to work (I don't think JSFiddle itself works in IE7 though, actually it kind of does, see this).
Update: Actually, lodash itself doesn't pass tests under IE7. Never mind that, the lodash.compat build does. However the compat build still has the same problem.
Does anyone have any ideas how to get this working under IE7? Has someone already solved this problem already?
Based on your fiddle, it looks like you are looking for the form widgets that are children of a widget.
dojox/form/Manager has a method called inspectFormWidgets that will do what you are lookiing for.
dijit/form/FormMixin has a method that you can reuse:
_getDescendantFormWidgets: function(/*dijit/_WidgetBase[]?*/ children){
var res = [];
array.forEach(children || this.getChildren(), function(child){
if("value" in child){
res.push(child);
}else{
res = res.concat(this._getDescendantFormWidgets(child.getChildren()));
}
}, this);
return res;
},
You can call it using the following
require(['dijit/form/_FormMixin'], function(DijitFormMixin) {
var widget = ...
var descendants = DijitFormMixin.prototype._getDescendantFormWidgets.call(
widget, widget.getChildren());
});
If you need to get more than just form widgets you can create a function that is similar to the _getDescendantFormWidgets.
I have tried to include a FireBreath plugin object in an AngularJS view, however when I try to render the view I get this error:
TypeError: Cannot read property 'nodeName' of undefined
I am able to successfully include the object in the view with $compile like this:
$("body").append($compile('<object id="plugin" type="application/x-firebreathplugin" width="0" height="0></object>')($scope));
However, after including the object like this I cannot get my plugin to fire an event in the JS.
Doing something like this:
plugin = document.getElementById('plugin');
console.log(plugin);
Returns
TypeError
In the Chrome console. But I can still do:
plugin.callFunction();
And have a FireBreath method execute. The issue is when I try to get an event to fire in the JS. No matter what I try, I cannot get the event to fire. So this code will never execute:
var addEvent = function(obj, name, func) {
obj.addEventListener(name, func, false);
}
addEvent(document.getElementById('plugin'), 'firebreathEvent', function(data) {
console.log('data ' + data);
});
var plugin = document.getElementById('plugin');
plugin.functionThatTriggersFireBreathEvent();
Does anybody know if it has something to do with accessing the object after calling $compile? I noticed that in regular HTML (before using AngularJS) logging the plugin in the console returns this :
<JSAPI-Auto Javascript Object>
So I am thinking that whatever I am getting with document.getElementById after using $compile is not the same.
What would be easier is is if I could just include the <object> tag in the view.html file and have it display in <body class='ng-view'> but I get the top TypeError, so if anyone has any ideas for that, that would be preferred.
Any help is appreciated. Thanks.
If anyone is interested, because I could not get the event to fire, I followed along to this link:
http://colonelpanic.net/2010/12/firebreath-tips-asynchronous-javascript-calls/
(which I think is your blog #taxilian) to get the data back to the JS.
Plugin Code: Great example in the link.
JS Code:
//attach FireBreath Object to AngularJS View
$("body").append($compile('<object id="plugin" type="application/x-firebreathplugin" width="1" height="1"><param name="onload" value="pluginLoaded"/></object>')($scope));
var callback = function(data) {
//data is an object
console.log(data.resultFromFireBreath);
}
plugin = document.getElementById("plugin");
plugin.getData(callback);
This will have to work for now until someone can figure out how to attach an event to the plugin object after $compile.
I ran into the same problem and was able to make the problem go away by creating a read-only nodeName property in my plugin object. I asked about this in a firebreath forum post and taxilian suggested adding this to JSAPIAuto.cpp, which also worked, so I submitted a pull request with the change.
I once spent about 6 hours trying to make FireBreath plugins work with jquery; it was really educational, but ultimately I determined that it wasn't worth the work.
Long story short is that it's not worth it; particularly since even if you could make it work, it would break on IE9 where FireBreath doesn't support addEventListener (IE never gives it the even info, so it's a little hard to support) and you would need to use attachEvent anyway.
I'm using a jQuery fork of Wysihat as a Wysiwig editor in a project of mine. It works perfectly in all browsers apart from (surprise, surprise) IE (specifically IE8). I've got the example files uploaded here:
http://pezholio.co.uk/wysihat/examples/custom_buttons.html
When running the file in IE, I get the error Object expected, and it seems to be occurring within this function:
window.getSelection = (function() {
var selection = new Selection(document);
return function() { return selection; };
})();
Any ideas what may be causing the problem, and what I can do to fix it?
Cheers
Ah, OK. I think I've nailed this now. I've removed the existing IE fallback code and am using selection.js instead. You can see the code in the gist below:
https://gist.github.com/2556956
I've been stuck on this problem for a while now. I'm using jQuery's .data() method to store state in a plugin I'm writing. Everything works fine, except for when I try to retrieve these data values from within a setInterval block. I am able to see the jQuery object inside the setInterval block, but I'm not able to see values stored by the data() method.
tminusStart: function() {
return this.each(function() {
var $tminus = $(this).data("tminus.state", "running");
var intervalId = setInterval(function(tm) {
if ($tminus.tminusIsRunning()) {
$tminus.tminusDecrementCounter();
$tminus.data("tminus.settings").tick_event();
if ($tminus.tminusTimeRemaining() <= 0) {
$tminus.data("tminus.settings").expiration_event();
}
$tminus.text(tminus.tminusTimeRemaining);
}
else {
clearInterval(intervalId);
}
}, 1000, $tminus);
});
}
In the above code, the $tminus does return the jQuery object alright, but the calls to the functions - which are calling the .data() method - return undefined; so does the .data("tminus.settings") call.
Any help in understanding why .data() isn't working here would be greatly appreciated.
Rewrite of function removing cruft:
tminusStart: function() {
var tminus = this;
tminus.data("tminus.state", "running");
return this.each(function() {
console.log(tminus.data("tminus.state")); // "running"
var intervalId = setInterval(function() {
console.log(tminus.data("tminus.state")); // undefined
}, 1000);
});
}
I need to know why it's undefined in the setInterval block
What are tminusIsRunning and tminusDecrementCounter? Did you mean to call that under $tminus? Unless you're extending jQuery, those calls are going to error out. If you're using Chrome, check the Javascript Console, you should see something like: "Uncaught TypeError: Object [object Object] has no method 'tminusIsRunning'"
.data() doesn't work with xhtml + IE (see note in docs).
Alternatively, This looks like a jQ extension, so watch out for that. jQuery has a (IMO) bad habit of aliasing this all over the place. Make sure you don't have a dependency on this being something different than what it is. I suggest installing firebug and using console.log to log this in both the place where you set the value, and where you access it. If it's not the IE issue, I suspect this would locate it.
Finally figured it out. I'm using jasmine to test drive this and the jasmine-jquery library has a fixtures piece which I'm apparently not using correctly. I tested the code in a webpage and everything is now working according to plan. Now I just have to make sure all my tests are passing.
I won't accept my own answer since I didn't provide the necessary information to begin with. I appreciate everyone's time on this. I really wish I could have accepted someone's answer.