So I'm learning Dojo and seeing what I can do with it - I do apologise if this is a stupid question but I can't find a solution.
My code:
dojo.require("dojo.Stateful");
dojo.declare('W.Model',dojo.Stateful,{
foo:'bar'
});
The error:
Uncaught Error: declare W.Model: unknown base class. Did you use dojo.require to pull it in?
I did use dojo.require to pull it in. What am I missing?
Edit - console.log(dojo.Stateful); returns undefined. I am using Google to hot Dojo for me - here: <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js"></script>
Other classes are loading fine, just dojo.Stateful is a problem.
Do you have the full class declaration in a separate file? Or is this all inline on a page?
If you are doing it inline, wrapping the class until the page has loaded will fix the problem:
dojo.require("dojo.Stateful");
dojo.ready(function() {
var x = new dojo.Stateful();
console.log(x);
dojo.declare('some.class', dojo.Stateful, {
'x':'y'
});
});
Related
I am using mpld3 to convert Matplotlib plots into D3 web embedable graphics. I am then using a JS library written on top of MathJax called svg_mathjax2.js (https://github.com/ichuang/svg_mathjax2) to apply Tex conversions.
The error I get is at this line of svg_mathjax2.js:
var svgmath = mathjaxdiv.getElementsByClassName('MathJax_SVG')
[0].getElementsByTagName('svg')[0];
It gives the error:
Uncaught TypeError: Cannot read property 'getElementsByTagName' of undefined
Everything works fine the first time I load Mathjax, it converts the text appropriately. However, any additional calls (via AJAX) don't work.
I've posted an issue on the github page, but have not heard back. I'm not sure if this is an issue with svg_mathjax2 or mpld3. Perhaps someone familiar with MathJax can help out?
Never mind, I figured this out. It was specific to the svg_mathjax2.js.
I solved it by activating this block of code:
if (1) {
MathJax.Hub.Register.StartupHook("End Typeset", function () {
forEach(items, function (x) {
});
// remove the temporary items
var mathbucket = document.getElementById('mathjax_svg_bucket');
mathbucket.parentNode.removeChild(mathbucket);
});
}
}
Currently using the Parse JavaScript SDK for a web app, but I'm also new to Backbone, and since this particular problem is in functionality that Parse copied over from Backbone, I'm not sure exactly where I'm making my mistake.
I have index.html, with this basic structure & script template tag (to be used by _underscore):
<div id="my-app">
</div>
<script type="text/template" id="album-header-template">
<div id="some-id">
Some Content
</div>
</script>
At the end of <body>, the following script tags, to take care of Parse dependencies, load Parse, & use my own JS file:
<script src="libraries/node_modules/jquery/dist/jquery.min.js"></script>
<script src="libraries/node_modules/underscore/underscore-min.js"></script>
<script src="libraries/node_modules/parse/dist/parse-latest.min.js"></script>
<script src="app/ParseApp.js"></script>
Then in ParseApp.js, where I am trying to get off the ground by creating simple objects and views, I have the following:
$(function () {
var Album = Parse.Object.extend("Album",{
// Default attributes for the album
defaults: {
name: "Album Title"
},
// Ensure that each album created has a title
initialize: function() {
if (!this.get("name")) {
this.set({"name": this.defaults.content});
}
},
});
var HomeView = Parse.View.extend({
el: $("#my-app"),
initialize: function() {
console.log("new instance of HomeView");
this.render();
},
render: function() {
this.$el.html(_.template($("#album-header-template").html()));
}
});
new HomeView;
});
When I run index.html in the browser, I get the following error in console: Uncaught TypeError: Cannot read property 'extend' of undefined (occurring at the var Home View = Parse.View.extend line).
Originally, I had thought this might be because Parse wasn't initiated in time for ParseApp.js to use it, based on my scripts loading. However, I ran the recommended "Test the SDK" script from Parse, and it's indeed initialized (in addition, adding an object with var Album works fine). So I'm really stuck on what's causing either HomeView or Parse.View to be "undefined".
Likely a straightforward answer that I'm overlooking, but any help would be greatly appreciated, and I could provide full files if need be.
Not a very satisfying answer, but thanks to the help from #Yura & #Daniel Blank, discovered that the error was resulting because the most recent versions of the Parse SDK (everything after 1.6.0) no longer include full Backbone functionality. This includes the version I had been using locally from npm.
The best explanation of the Parse SDK direction is in the link given above, and there seem to be three options, for those hoping to continue using Parse and/or Backbone:
Use an old version (1.5.0 being the most recent that includes Backbone functionality) in order to maintain your Backbone functions, such as Parse.Collection or Parse.Router.
Try going Parse SDK-agnostic, while continuing to use Backbone. Can use the basic Parse REST API, or try one of the GitHub projects attempting to do that linking for you.
Give up on Backbone going forward, and use Parse with VanillaJS, or perhaps switch over to React (which is obviously the direction Facebook would want Parse to head)
I'm too inexperienced to recommend one of the three, although #1 seems the easiest, while #3 seems far and away the most maintainable. Still trying to make my own decision, but that's outside the scope of my original question. Thanks for the help, everyone.
2 things jump out at me:
I don't see where you initialize Parse... typically that
produces a different error, but still might be an issue
You are referencing your own local library for Parse... maybe try targeting the officially deployed version.
script src="http://www.parsecdn.com/js/parse-1.2.13.min.js"
I'm trying to implement joss benner's fix as shown here. I need to implement this code:
slider.setOpts = function(opts) {
for (var opt in opts) {
vars[opt] = opts[opt];
}
slider.setup();
}
slider.getOpts = function() {
return vars;
}
I've tried with this fiddle here, but I just get
Uncaught ReferenceError: slider is not defined
in the console. Not really what I'm doing. The other commenters seem to be able to implement it no problem.
Could someone also explain the meaning behind the code... what is slider? A class? A function? Where should I place the above code to add the .setOpts function?
He wrote
I added these public methods to flexslider
To do so, you have to add those lines of code inside the jquery.flexslider.js-file and not in another js-file as you did in the fiddle. The error tells you what the problem is. And in your case, slider is in fact not defined, because the slider-variable is being declared inside a codeblock of the jquery.flexslider.js which means, there is no reference to this variable outside of this block.
The public methods start in line 426, so add your code there.
I'm new to Javascript and have been attempting to use a Slider called noobSlide (mootools) but, after one success with it, have found it broken on my second attempt.
The error that I'm getting reads "Uncaught TypeError: undefined is not a function" in reference to this line of code:
var thumbsFx = new Fx.Style(thumbs_mask7,'left',fxOptions7);
I've included all of the necessary libraries for Mootools and the Slider scripts in the head of my pages, and have combed the HTML, but can't find a solution. It seems to be pointing me to the Mootools library but I know that isn't right since, as I said, I've already succeeded with it once using another example.
If it helps, here is the page housing all of the samples of the Slider (I'm trying to use #7 and have already used #3).
http://www.efectorelativo.net/laboratory/noobSlide/
If anyone can see where the source of the problem may be, I would really appreciate your eyes :)
Thanks,
Juliana
<script type="text/javascript">
window.addEvent('domready',function(){
//SAMPLE 7
var startItem = 0; //or 0 or any
var thumbs_mask7 = $('thumbs_mask7').setStyle('left',(startItem*60-568)+'px').setOpacity(0.8);
var fxOptions7 = {duration:1000, transition:Fx.Transitions.Back.easeOut, wait:false};
var thumbsFx = new Fx.Style(thumbs_mask7,'left',fxOptions7);
var hs7 = new noobSlide({
box: $('box7'),
items: [0,1,2,3,4,5,6,7],
handles: $ES('span','thumbs_handles7'),
fxOptions: fxOptions7,
onWalk: function(currentItem){
thumbsFx.start(currentItem*60-568);
},
startItem: startItem
});
hs7.walk(0);
});
</script>
why you don't use
$ES('span','thumbs_handles7')
as in their example?
$$('#thumbs_handles7 span')
Is this fixing the error?
Note: You need to make sure that you have all the html tags and their related ids as you defined them in the javascript code
I am creating a yui3 widget and I keep getting this error: this.constructor.NAME is undefined.
I am defining a name in my widget:
YUI().add('paginator', function(Y) {
function Paginate(config) {
Paginate.superclass.constructor.apply(this, arguments);
}
Paginate.NAME = "paginate";
...
So, I am not sure what's going on.
Edit:
I also wanted to add that I have just tried to add the default widget skeleton from here and I am still getting the same error.
I thought I would answer this myself in case anyone else comes across this problem. I forgot the new keyword when creating my widget.