I'm trying to upgrade the old version of cryptoJS that can be found here to a newer version on github that can be found here because, there are some functions on the old version that is going to be deprecated. Unfortunately, the newer don't have rollup files, so im trying to get it to work using the core files but, I keep getting the error(s) that something is "undefined" like "cfg.hasher is undefined".
<script type="text/javascript" src="crypto-js3.1.9-1/core.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/evpkdf.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/x64-core.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/cipher-core.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/aes.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/pbkdf2.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/hmac.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/lib-typedarrays.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/format-hex.js"></script>
I tried adding all the core files and even changing the orders of them, but I think I'm still missing something.
If I use the rollup files, this simple code below works just fine on it, but it fail on the newer version. Hopefully someone with more experience with cryptoJS can help me out.
<script type="text/javascript">
var string = "asdfasdfsadfdsa";
var key = "asdfasfasfs";
var encrypted = CryptoJS.AES.encrypt(string, key);
var decrypted = CryptoJS.AES.decrypt(encrypted, key);
alert(decrypted);
</script>
UPDATE!! I can get SHA256 to work just fine with out uses of require.js so I don't thing the problem is Modular include and the lib should be able to run "without RequireJS", but I'm still running into encryption and decryption error: "cfg.hasher is undefined".
<script type="text/javascript" src="CryptoJS/components/core.js"></script>
<script type="text/javascript" src="CryptoJS/components/sha256.js"></script>
<script type="text/javascript">
console.log(CryptoJS.SHA256("Message"));
</script>
You would have to do modular includes
Modular include using require js:
require.config({
packages: [
{
name: 'crypto-js',
location: 'path-to/bower_components/crypto-js',
main: 'index'
}
]
});
require(["crypto-js/aes", "crypto-js/sha256"], function (AES, SHA256) {
console.log(SHA256("Message"));
});
Here is a full gist
Related
i have a project which is written in MVC3,its a signalR,i got the code to edit some part but i see its gives an error,on the following part which says cant start a null refrence:
$.connection.hub.start().done(FUNCTION....)
meaninf the valu of hub is null,the fowlooing are the scripts which are loading:
<script src="#Url.Content("~/Scripts/jquery-1.7.2.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/leitwind/dateExtension.min.js?ver=1")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/knockout-3.0.0.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/knockout.mapping-latest.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/leitwind/knockoutAutoRefresh.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/DataTables-1.9.2/media/js/jquery.dataTables.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.signalR-0.5.2.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/signalr/hubs")"></script>
when i go to the developer option of the browser its showing the error on the last refrence,signalr/hubs which does not exist!im wondering why the project is running on the server but not on the local pc even thought i have the same scripts and anything has been changed,after one day of investigation i thought maybe i should give the address of the server instead of signalr/hubs,with this work around i that error is not threwing any more but i have the following issue,all in all i dont have any idea where i should look
is there something wrong with the url format?
i need to set the address manually in my code in order to get data from the server,for the follwoing part:
$.connection.hub.url ='https://myserver.com/file/signalr/';
$.connection.hub.start().done()
I am currently working my way through David Sulc's excellent "Backbone.Marionette.js: A Gentle Introduction" and have come unstuck at modules. With the app as it currently stands I am trying to access an API in a module called 'contacts.js' from the index.html script but I get the following error when I try to run the app:
"Handler not found for 'contact: entities' "
I am able to hit the API directly from the console in Chrome and manually get the 'contact' information so I was thinking this was a loading sequence problem where the API might not be available by the time app.js loads, however the loading sequence is as follows:
<script type="text/javascript" src="assets/js/vendor/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="assets/js/vendor/json2.js"></script>
<script type="text/javascript" src="assets/js/vendor/underscore-min.js"></script>
<script type="text/javascript" src="assets/js/vendor/backbone-min.js"></script>
<script type="text/javascript" src="assets/js/vendor/backbone.marionette.min.js"></script>
then the local scripts as follows:
<script type="text/javascript" src="assets/js/app.js"></script>
<script type="text/javascript" src="assets/js/entities/contact.js"></script>
and a script tag below the last two script tags directly runs the following code:
<script type="text/javascript">
... some view code
ContactManager.on("initialize:after", function(){
var contacts = ContactManager.request("contact: entities");
... some more code
</script>
the line beginning var contacts = ..... is the one giving me the error. Any help appreciated
I am as certain as I can be that I have scripted this exactly as per the book.
You have a space in your event name:
<script type="text/javascript">
... some view code
ContactManager.on("initialize:after", function(){
// Remove the space in contact: entities -->
var contacts = ContactManager.request("contact: entities");
... some more code
</script>
I have a designed a website and included some java scripts, they run perfectly locally but on uploading to the server, nothing works!! I tried changing the reference to the pages to //http: but still...nothing. I've tried testing on the server with a simple alert text box,it works. I don't understand why the other .js scripts aren't working. please Help.
<script type="text/javascript">
var shutterSettings = {"msgLoading":"L O A D I N G","msgClose":"Click to Close","imageCount":"1"};
</script>
<script src='http://www.broadigital.co.ke/style/newcss/js/shutter-reloaded.js?ver=1.3.3' type='text/javascript' ></script>
<script src='http://www.broadigital.co.ke/style/newcss/js/jquery.js?ver=1.7.2' type='text/javascript' ></script>
<script src='http://www.broadigital.co.ke/style/newcss/js/jquery.cycle.all.min.js?ver=2.9995' type='text/javascript' ></script>
<script src='http://www.broadigital.co.ke/style/newcss/js/ngg.slideshow.min.js?ver=1.06' type='text/javascript' ></script>
<script src='http://www.broadigital.co.ke/style/newcss/js/jquery.flexslider-min.js?ver=3.4.2' type='text/javascript' ></script>
Uncaught SyntaxError: Unexpected end of input jquery.js:6
Uncaught ReferenceError: jQuery is not defined
Check if you uploaded jQuery correctly. The file might have been truncated in the process.
UPDATE
Checking your jQuery file, the file truncates on line 6 with these as the last few characters.
if(this[0]){var b=f(a,this[0].owne
SOLUTION
Re-upload the jQuery file (jquery.js) again, or
Use jQuery CDN:
Change:
<script src='http://www.broadigital.co.ke/style/newcss/js/jquery.js?ver=1.7.2' type='text/javascript'></script>
To:
<script src='http://code.jquery.com/jquery-1.7.2.min.js' type='text/javascript'></script>
I am trying to update an old cometd javascript wrapper and test client (was 1.3.x) that I have to the newer comet 2.5.1 javascript implementation. I have all of the dependencies and the browser can find them all, yet I am getting errors in Firebug's console (see below)
The head of my HTML is as below:
<head>
<title>CometD Tester</title>
<link rel="stylesheet" type="text/css"href="style/style.css" />
<script type="text/javascript" src="org/cometd/Cometd.js"></script>
<script type="text/javascript" src="org/cometd/AckExtension.js"></script>
<script type="text/javascript" src="org/cometd/ReloadExtension.js"></script>
<script type="text/javascript" src="jquery/jquery-1.9.0.js"></script>
<script type="text/javascript" src="jquery/jquery.cookie.js"></script>
<script type="text/javascript" src="jquery/jquery.cometd.js"></script>
<script type="text/javascript" src="jquery/jquery.cometd-reload.js"></script>
<script type="text/javascript" src="js/myCometd.js"></script>
</head>
All of these are found by the browser. Looking at Cometd.js I see the following:
org.cometd.Cometd = function(name)
{
....
}
So is that not defining org? Note that none of the errors in the Console are from Cometd.js. Otherwise I see no other definition of "org.cometd". I would really appreciate it if anyone can help me out. I am using Tomcat 7 and below is the dir structure:
Thanks.
UPDATE - Further testing
I reduced the header to:
<head>
<title>CometD Tester</title>
<link rel="stylesheet" type="text/css"href="style/style.css" />
<script type="text/javascript" src="org/cometd/Cometd.js"></script>
</head>
And removed ALL JS from the index.html. The only JS now included is the Cometd.js from the comet.org. There is still the same error... coming from the very first line in that script:
org.cometd.Cometd = function(name)
Not sure what I have missed here.
EDIT - Add jquery.cometd-reload.js
This is the contents of the file. It looks like it is "re-binding" functionality from the cometd library to use the jquery one instead (?). I'm not up to speed enough in JS to debug this (I'm a C++ dev really).
(function($)
{
function bind(org_cometd, cookie, ReloadExtension, cometd)
{
// Remap cometd COOKIE functions to jquery cookie functions
// Avoid to set to undefined if the jquery cookie plugin is not present
if (cookie)
{
org_cometd.COOKIE.set = cookie;
org_cometd.COOKIE.get = cookie;
}
var result = new ReloadExtension();
cometd.registerExtension('reload', result);
return result;
}
if (typeof define === 'function' && define.amd)
{
define(['org/cometd', 'jquery.cookie', 'org/cometd/ReloadExtension', 'jquery.cometd'], bind);
}
else
{
bind(org.cometd, $.cookie, org.cometd.ReloadExtension, $.cometd);
}
})(jQuery);
So the problem was that I misunderstood the project layout from the Comet.org site. I should have followed the direction posted at cometd primer for non-maven setups a lot more closely. Basically when you are setting up the project you download the distribution, and then you need to take the code from the war files bundled inside the tarball.
SO, once you have extracted the tarball...
Take the org folder from cometd-javascript-common-2.5.1.war (located in \cometd-2.5.1\cometd-javascript\jquery\target) or cometd-javascript-jquery-2.5.1.war (located in \cometd-2.5.1\cometd-javascript\common\target)
Take the jquery folder from cometd-javascript-jquery-2.5.1.war
The org namespace definition was in the file org/cometd.js which I did not have before, as I wrongly assumed that it had been replace by the org/cometd/Cometd.js file. The namespaces org and comet are defined as below starting on line 17 of that file:
// Namespaces for the cometd implementation
this.org = this.org || {};
org.cometd = {};
org.cometd.JSON = {};
The functions are working correctly now.
Try loading jQuery before any of the other JavaScript files -
<head>
<title>CometD Tester</title>
<link rel="stylesheet" type="text/css"href="style/style.css" />
<script type="text/javascript" src="jquery/jquery-1.9.0.js"></script> <!-- load first -->
<script type="text/javascript" src="org/cometd/Cometd.js"></script>
<script type="text/javascript" src="org/cometd/AckExtension.js"></script>
<script type="text/javascript" src="org/cometd/ReloadExtension.js"></script>
<script type="text/javascript" src="jquery/jquery.cookie.js"></script>
<script type="text/javascript" src="jquery/jquery.cometd.js"></script>
<script type="text/javascript" src="jquery/jquery.cometd-reload.js"></script>
<script type="text/javascript" src="js/myCometd.js"></script>
</head>
I Have usercontrol and i registered the following javascript method in code behind :
changeSelectedMenu(controlID);
the previous method is declared in JScript.js file so i registered it also .
but the following exception has been thrown :
Microsoft JScript runtime error: Object expected
The result page is :
<script src="~/Scripts/JQuery.js" type="text/javascript"></script>
<script src="~/Scripts/JScript.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
changeSelectedMenu('ctl00_ctl00_cntMain_procedureContentHolder_procedureMenu_appointmentsLink');//]]>
</script>
Is There anyone can help me to workaround this issue???
These aren't valid paths to your JavaScript:
<script src="~/Scripts/JQuery.js" type="text/javascript"></script>
<script src="~/Scripts/JScript.js" type="text/javascript"></script>
They need to be relative to the page or to the site root, for example:
<script src="/Scripts/JQuery.js" type="text/javascript"></script>
<script src="/Scripts/JScript.js" type="text/javascript"></script>
While ~/ works for resolving a path on the server-side, the browser doesn't know how to handle this. There are some other work-arounds in this question for making it work and still being app-relative.