I keep reading that it is possible to load javascript files, and then use those functions in other files. Unfortunately I can't get this to work. Here is my current path:
<script src="js/bootstrap.min.js"></script>
<script src="js/twitter_crypt.js"></script>
<script src="js/scripts.js"></script>
<script src="http://platform.twitter.com/widgets.js"></script>
<script src="js/interactive.js"></script>
I am using functions from the twitter_crypt.js
file in my interactive.js
file (last in path).
When I console.log(nameOfFunction) in interactive.js
which is in twitter_crypt.js
it tells me that function is not defined.
I ran into this posts but I am not looking to use something like require.js .
I am just trying to call functions from the other files. I assume the must be available since I am using jquery, bootstra.min.js and other files that are being loaded.
I believe I have everything in order as well which is what this post talks about.
//Twitter_Crypt JS file:
function decoder(key, encodedMessage){
var coded = "";
var ch;
var index;
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for(var i = 0; i < encodedMessage.length; i++){
ch = encodedMessage.charAt(i);
index = key.indexOf(ch);
if(index === -1){
coded = coded + ch;
} else {
coded = coded + alphabet.charAt(index);
}
}
return coded;
}
InteractivJS File:
$('#decodeSubmit').on("click", function(ev){
if($("#encryptText").val() === ""){
alert("Please Enter a Decrypted Tweet");
} else {
ev.preventDefault();
var decodedTweet = decoder("zipsunxmogdkfabrhcylvqewtj", $("#encryptText").val());
$("#decode_form").fadeOut("fast");
$("#decode").fadeIn("fast");
$('#decode_progress').progressbar({
display_text: 'center',
use_percentage: false,
refresh_speed: 10,
done: function($this) {
$(".modal-body").append(decodedTweet).css('color', 'black');
$("#decodeNewTweet").fadeIn("slow");
$(".modal").modal("show");
}
});
}
});
When I put the function decoder inside the interactiveJS file it works fine. When it is in the twitter_crypt.js file I keep getting a decoder is not defined.
Originally I had both scripts wrapped in a document ready, which helped but didn't solve everything. Why isn't my decoder function in global scope though? It isn't wrapped in any other functions?
Do I have to do something like window.decoder =function(){}