Is there anyway to identify when the mathjax is fully loaded to process mathematics. I need to hide my mathematics equations before mathjax is fully loaded and show 'loading' message in mean time.
For those who might be looking for the answer, this is the response i got from Mathjax developer
The way to synchronize with MathJax's startup actions it to register a StartupHook that will fire when the startup is complete. For example, you can use
MathJax.Hub.Register.StartupHook("End",function () { ... your startup code here ... });
at the end of the tag that configures MathJax, or in a
separate tag just after loading MathJax if you are using the
default MathJax configuration file in MathJax/config/MathJax.js. That
should let you hook into MathJax's initialization sequence so you can
do your own setup at the right time.
Thanks David
If you have Jquery loaded you can use getScript()
var mjaxURL = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML,Safe.js';
// load mathjax script
$.getScript(mjaxURL, function() {
// mathjax successfully loaded, let it render
MathJax.Hub.Queue(["Typeset", MathJax.Hub, 'c'+parentid+'_list']);
});
Related
I'm getting this error when I browse my webapp for the first time (usually in a browser with disabled cache).
Error: Mismatched anonymous define() module: function (require) {
HTML:
<html>
.
.
.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script> var require = { urlArgs: "v=0.4.1.32" }; </script>
<script data-main="assets/js/main" src="assets/js/libs/require.js"></script>
<script src="assets/js/ace/ace.js?v=0.4.1.32"></script>
</body>
</html>
JS:
$(function () {
define(function (require) {
// do something
});
});
Anyone know exactly what this error means and why its happening?
source file, a short discussion about it in the github issues page
Like AlienWebguy said, per the docs, require.js can blow up if
You have an anonymous define ("modules that call define() with no string ID") in its own script tag (I assume actually they mean anywhere in global scope)
You have modules that have conflicting names
You use loader plugins or anonymous modules but don't use require.js's optimizer to bundle them
I had this problem while including bundles built with browserify alongside require.js modules. The solution was to either:
A. load the non-require.js standalone bundles in script tags before require.js is loaded, or
B. load them using require.js (instead of a script tag)
In getting started with require.js I ran into the issue and as a beginner the docs may as well been written in greek.
The issue I ran into was that most of the beginner examples use "anonymous defines" when you should be using a "string id".
anonymous defines
define(function() {
return { helloWorld: function() { console.log('hello world!') } };
})
define(function() {
return { helloWorld2: function() { console.log('hello world again!') } };
})
define with string id
define('moduleOne',function() {
return { helloWorld: function() { console.log('hello world!') } };
})
define('moduleTwo', function() {
return { helloWorld2: function() { console.log('hello world again!') } };
})
When you use define with a string id then you will avoid this error when you try to use the modules like so:
require([ "moduleOne", "moduleTwo" ], function(moduleOne, moduleTwo) {
moduleOne.helloWorld();
moduleTwo.helloWorld2();
});
I had this error because I included the requirejs file along with other librairies included directly in a script tag. Those librairies (like lodash) used a define function that was conflicting with require's define. The requirejs file was loading asynchronously so I suspect that the require's define was defined after the other libraries define, hence the conflict.
To get rid of the error, include all your other js files by using requirejs.
Per the docs:
If you manually code a script tag in HTML to load a script with an
anonymous define() call, this error can occur.
Also seen if you
manually code a script tag in HTML to load a script that has a few
named modules, but then try to load an anonymous module that ends up
having the same name as one of the named modules in the script loaded
by the manually coded script tag.
Finally, if you use the loader
plugins or anonymous modules (modules that call define() with no
string ID) but do not use the RequireJS optimizer to combine files
together, this error can occur. The optimizer knows how to name
anonymous modules correctly so that they can be combined with other
modules in an optimized file.
To avoid the error:
Be sure to load all scripts that call define() via the RequireJS API.
Do not manually code script tags in HTML to load scripts that have
define() calls in them.
If you manually code an HTML script tag, be
sure it only includes named modules, and that an anonymous module that
will have the same name as one of the modules in that file is not
loaded.
If the problem is the use of loader plugins or anonymous
modules but the RequireJS optimizer is not used for file bundling, use
the RequireJS optimizer.
The existing answers explain the problem well but if including your script files using or before requireJS is not an easy option due to legacy code a slightly hacky workaround is to remove require from the window scope before your script tag and then reinstate it afterwords. In our project this is wrapped behind a server-side function call but effectively the browser sees the following:
<script>
window.__define = window.define;
window.__require = window.require;
window.define = undefined;
window.require = undefined;
</script>
<script src="your-script-file.js"></script>
<script>
window.define = window.__define;
window.require = window.__require;
window.__define = undefined;
window.__require = undefined;
</script>
Not the neatest but seems to work and has saved a lot of refractoring.
Be aware that some browser extensions can add code to the pages.
In my case I had an "Emmet in all textareas" plugin that messed up with my requireJs.
Make sure that no extra code is beign added to your document by inspecting it in the browser.
Or you can use this approach.
Add require.js in your code base
then load your script through that code
<script data-main="js/app.js" src="js/require.js"></script>
What it will do it will load your script after loading require.js.
I was also seeing the same error on browser console for a project based out of require.js. As stated under MISMATCHED ANONYMOUS DEFINE() MODULES at https://requirejs.org/docs/errors.html, this error has multiple causes, the interesting one in my case being: If the problem is the use of loader plugins or anonymous modules but the RequireJS optimizer is not used for file bundling, use the RequireJS optimizer. As it turns out, Google Closure compiler was getting used to merge/minify the Javascript code during build. Solution was to remove the Google closure compiler, and instead use require.js's optimizer (r.js) to merge the js files.
I am trying to set up a tree view using an entity framework data object (EF 6 in MVC 5). I've run into a problem when I try to Render() my tree.... I receive the 'Object doesn't support property or method 'igTree'' error.
My code to set up the tree (in my view):
#(Html.Infragistics()
.Tree()
.Bindings(bindings =>
{
bindings.
TextKey("L1Name").
PrimaryKey("L1TODSID").
ValueKey("L1TODSID").
ChildDataProperty("L2Name").
Bindings(b1 =>
{
b1.
TextKey("L2Name").
ValueKey("L2TODSID").
PrimaryKey("L2TODSID");
});
})
.DataSource(Model)
.DataBind()
.Render()
)
I get no errors until I add in the 'Render()' call.
I read a post on the Infragistics forum asking if they will be supporting MVC 5... Are they not doing that? Is that my issue?
Also, these are my calling scripts:
<!-- Ignite UI Required Combined CSS Files -->
<link href="#Url.Content("~/igniteui/css/themes/infragistics/infragistics.theme.css")" rel="stylesheet" />
<link href="#Url.Content("~/igniteui/css/structure/infragistics.css")" rel="stylesheet" />
<script src="#Url.Content("~/Scripts/modernizr-2.7.2.js")"></script>
<script src="#Url.Content("~/Scripts/jquery-2.0.3.min.js")"></script>
<script src="#Url.Content("~/Scripts/jquery-ui-1.10.3.min.js")"></script>
<!-- Ignite UI Required Combined JavaScript Files -->
<script src=#Url.Content("~/igniteui/js/infragistics.core.js")></script>
<script src=#Url.Content("~/igniteui/js/infragistics.lob.js")></script>
#(Html.Infragistics()
.Loader()
.ScriptPath("~/igniteui/js/")
.CssPath("~/igniteui/css/")
.Render()
)
Thanks in advance!
EDIT: Final Resolve.
Just in case anyone else ever runs accross this situation...
I knew this error ('Object doesn't support property or method...') could be caused by jquery loading twice. Thought I had thoroughly checked all script calls. However, being new to .NET and MVC 5 (razor), I completely missed this line at the end of my layout page (I didn't set up the project originally):
#Scripts.Render("~/bundles/jquery")
So...
In the end, I was initiallizing JQuery in my script block at the top (with a call to the minified file), then I was calling it again, which is what caused the error.
A big thanks to #nemesv, because the fact that he explained the loading process in greater detail than I could find online gave me the confidence to know that I was doing things correctly on that side. Then I just needed to hunt down the second call to initialize JQ.
Thanks again!
By default (if you are not using the loader infrastructure)
The .Render() call will render the following HTML:
<script type="text/javascript">
$(function () {$('#Tree1').igTree({ dataSource: ... });});
</script>
So you get the exception on the igTree function call which would initialize the tree.
Your igTree function can be undefined:
If you are not loading the necessary igniteui scripts:
<script src=#Url.Content("~/igniteui/js/infragistics.core.js")></script>
<script src=#Url.Content("~/igniteui/js/infragistics.lob.js")></script>
Make sure that these scripts are included in your view or in your Layour file
If you are not using the rigth path or the scripts file are not there on the server:
Check for broken link in your browsers network console (F12 in IE/Chrome FireBug in FF):
If you 404 error next to your script you will know that they are not loaded correctly and you need to fix the paths.
If you are referencing jQuery more than once can cause this error too:
Foe example you have the <script src="#Url.Content("~/Scripts/jquery-2.0.3.min.js")"></script> in a partial which is loaded by Ajax multiple times, etc.
Make sure that you are referencing all your scripts once.
In the case of using the loader
When using the Loader infrasturure the .Render() call will render the a different HTML:
<script type="text/javascript">
$.ig.loader('igTree', function() {$('#Tree1').igTree({ dataSource: });});
</script>
So the loader will load the necessary script required by the tree so you don't need to include infragistics.core.js and infragistics.lob.js.
When using the loader in theory you could not the get the exception.
But if you call: #(Html.Infragistics().Loader()... after your Html.Infragistics().Tree() then the MVC wrapper does not that you are using the loader so it renders the HTML like when you don't use the loader so if you rightfully not referenced the infragistics.core.js and infragistics.lob.js. then you get the exception even if you are "using" the loader.
So make sure that you call #(Html.Infragistics().Loader()... before using any of the Infragistics controls.
I was also facing the same issue with MVC 4 and Ignite UI. Removing #Scripts.Render("~/bundles/jquery")
from the _Layout.cshtml resolved the issue.
I'm trying to use Almond.js and the Require.js optimizer to make a standalone file that can be used without Require.js. I've been able to successfully compile the file, and all the code runs, but there's one problem: the code executes in the wrong order.
Let's say my main file (the one that's in the include= option passed to the optimizer) has the following:
console.log('outside');
require(['someFile'], function(someModule) {
console.log('inside');
window.foo = someModule.rightValue;
});
and then out in my HTML I have:
<script src="myCompiledFile.js"></script>
<script>
console.log('out in the HTML');
</script>
Since I'm using almond.js and a compiled file (and therefore there's no file loading going on) I would expect to get the output:
outside
inside
out in the HTML
However, it turns out there's still some asynchronicity going on, because what I actually see is:
outside
out in the HTML
inside
and if I try to check window.foo from the HTML it's not there.
So, my question is, how can I get the code to be more like a normal/synchronous JS file, which runs all its code first before passing things on to the next script block? I can't exactly tell my users "wrap all your code in a window.setTimeout".
By default Almond replicates the timing semantics of RequireJS' require call. Since require is asynchronous in RequireJS, it is also asynchronous in Almond. This can be readily observed in the source: Almond uses a setTimeout to schedule the execution of a module even though it could execute it right away. It makes sense because in the general case developers don't expect that the code they've crafted to work asynchronously will suddenly become synchronous just because they are using Almond. It does not matter in every project but in a project where the UI (for instance) should be refreshed in a certain order, changing the timing semantics could break the code.
Two options:
As the comment just before the setTimeout states, using require('id') works globally with Almond. This is because once your bundle is loaded, everything is guaranteed to have been loaded (since Almond does not load dynamically).
There's also a way to call require with extra arguments. If the fourth argument is true, the call is going to be synchronous:
require(['someFile'], function(someModule) {
console.log('inside');
window.foo = someModule.rightValue;
}, undefined, true);
This can be ascertained by reading the code of Almond. There's no documentation I could find on forceSync (that's the name of the parameter in question) but some bug reports mention it and I've not seen any comment there that it is meant to be a private functionality.
I'm working on a page that is in progress of transitioning from script tags to require.js. This means that some dependencies are loaded via <script> and others via require.
For the most part, in my require modules I can still treat global scripts as modoules (and thereby help the transition) by doing something like this in my bootstrapping file
define('Globalize', Globalize);
define('knockout', ko);
However this won't work with jQuery since it is a function and require will try to invoke it as a callback. Is there a way to tell require "yes this is a function but return it directly, don't try to invoke it"?
And yeah, I can't just load jquery twice because I've got bootstrap modifying it, and things depending on bootstrap
Oh...
define('jquery', function() { return window.jQuery});
duh.
I am facing an issue in declaring a fucation in block which I have added . I am calling a function by including an file which ia placed in the theme. I have also tried it by placing out of the theme folder. The function is alredy being user in front page. But when I am using the same function in that block. The screen gets blank and nothing displays. some part of my block coding is written below. Please help me.
<?php
global $base_url;
include($_SERVER['DOCUMENT_ROOT']."/travellar/geoiploc.php"); // indluded file
$ip = "203.189.25.0"; // Australia IP test
$country_code = getCountryFromIP($ip, "code");
I've had no problems loading functions from modules into custom blocks, but I've never tried loading one from a theme before. It's not clear to me whether or not theme functions are loaded before the page content is loaded.
You might have to create a custom module or include file to hold the function. Check out the module_load_include() function for how to load a specific include file.
A custom module would be a good approach as it is loaded before the theme layer and can be accessed from almost anywhere in Drupal except other modules with a lower weight than the custom module. It is also likely to come in handy for hooks and other overrides.
However, if you must have it in the theme layer, another option is adding it to template.php of your theme which should make it available within page.tpl.php and such, but not blocks I don't believe.
/sites/all/modules/mymodule/mymodule.info
name = My Module
package = !
description = It is MY module, not yours!
core = 6.x
The package "!" will make this module appear at the top of the modules page
/sites/all/modules/mymodule/mymodule.module
<?php
// Load mymodule.morePHP.inc
module_load_include('inc', 'mymodule', 'mymodule.morePHP');
// A custom function
function mymodule_my_custom_function($args) {
/* do custom stuff here */
return 'output';
}
/sites/all/modules/mymodule/mymodule.morePHP.inc
<?php
// An included custom function
function mymodule_other_custom_stuff() {
}