I’m trying to install Noty (a jQuery Notification plugin) on a checkout page (FoxyCart template). I installed the following code in the section of my checkout template:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="http://lavajavamaui.com/js/noty/jquery.noty.js"></script>
<script type="text/javascript" src="http://lavajavamaui.com/js/noty/layouts/top.js"></script>
<script type="text/javascript" src="http://lavajavamaui.com/js/noty/layouts/topLeft.js"></script>
<script type="text/javascript" src="http://lavajavamaui.com/js/noty/layouts/topRight.js"></script>
<!-- You can add more layouts if you want -->
<script type="text/javascript" src="http://lavajavamaui.com/js/noty/themes/default.js">
</script>
<script type="text/javascript">
var noty = noty({text: 'noty - a jquery notification library!'});
</script>
If I understand correctly, this is all that needs to be done to get it to display properly. For some reason, the notification is not popping up. Is there something wrong with this line?
<script type="text/javascript">
var noty = noty({text: 'noty - a jquery notification library!'});
</script>
Here is the page that should have Noty installed.
You are reproducing a bug in the documentation. The line
if run in a global context, redefines
noty, replacing the functionnotywith the result of thenotyfunction. In theory this first call should work but any subsequent calls tonotywill fail because they are trying to call an object as a function. I’m not sure why the first one fails, but it is possible it is related. Try changing the name of the object you are assigning the result to:That might fix it.
If you don’t need to manipulate the notification after you create it you should also be able to just call it without assigning the result to a variable:
Update
If you execute that statement inside a non-global context (such as jQuery’s
readyevent) it will not work because of variable hoisting. Hoisting takes anyvarstatement and moves it to the top of the statement. The statement:Is turned into: