Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.globalVar = "This is global!";
- // An object to define utility functions and global variables on:
- $.miniMenu = new Object();
- // An object to define internal stuff for the plugin:
- $.miniMenu.i = new Object();
- $my_global_var = 'my value';
- $gallery = $('img');
- $current = 0;
- $gallery.each(function(i,v){
- // preload images
- (new Image()).src = v;
- });
- $('div').eq(0).append('<a style="display:inline-block" class="prev">prev</a> <div id="gallery"></div> <a style="display:inline-block" class="next">next</a>');
- $('.next').click(function(){
- $current = ( $current == $gallery.length - 1 ) ? 0 : $current + 1;
- $('#gallery').hide().html($gallery[$current]).fadeIn();
- });
- $('.prev').click(function(){
- $current = ( $current == 0 ) ? $gallery.length - 1 : $current - 1;
- $('#gallery').hide().html($gallery[$current]).fadeIn();
- });
- var myVariable = 'Hello';
- alert('value: ' + myVariable);
- myFunction1();
- alert('value: ' + myVariable);
- myFunction2();
- alert('value: ' + myVariable);
- function myFunction1() {
- myVariable = 'Hello 1';
- }
- function myFunction2() {
- myVariable = 'Hello 2';
- }
- function dosomething(){
- var i = 0; // can only be used inside function
- }
- var i = '';
- function dosomething(){
- i = 0; // can be used inside and outside the function
- }
- <!DOCTYPE html>
- <html>
- <head>
- <script type="text/javascript" src="init.js"></script>
- <script type="text/javascript">
- MYLIBRARY.init(["firstValue", 2, "thirdValue"]);
- </script>
- <script src="script.js"></script>
- </head>
- <body>
- <h1>Hello !</h1>
- </body>
- </html>
- var MYLIBRARY = MYLIBRARY || (function(){
- var _args = {}; // private
- return {
- init : function(Args) {
- _args = Args;
- // some other initialising
- },
- helloWorld : function(i) {
- return _args[i];
- }
- };
- }());
- // Here you can use the values defined in the html as if it were a global variable
- var a = "Hello World " + MYLIBRARY.helloWorld(2);
- alert(a);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement