Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. window.globalVar = "This is global!";
  2.  
  3. // An object to define utility functions and global variables on:
  4. $.miniMenu = new Object();
  5. // An object to define internal stuff for the plugin:
  6. $.miniMenu.i = new Object();
  7.  
  8. $my_global_var = 'my value';
  9.  
  10. $gallery = $('img');
  11. $current = 0;
  12.  
  13. $gallery.each(function(i,v){
  14. // preload images
  15. (new Image()).src = v;
  16. });
  17. $('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>');
  18. $('.next').click(function(){
  19. $current = ( $current == $gallery.length - 1 ) ? 0 : $current + 1;
  20. $('#gallery').hide().html($gallery[$current]).fadeIn();
  21. });
  22. $('.prev').click(function(){
  23. $current = ( $current == 0 ) ? $gallery.length - 1 : $current - 1;
  24. $('#gallery').hide().html($gallery[$current]).fadeIn();
  25. });
  26.  
  27. var myVariable = 'Hello';
  28. alert('value: ' + myVariable);
  29. myFunction1();
  30. alert('value: ' + myVariable);
  31. myFunction2();
  32. alert('value: ' + myVariable);
  33.  
  34.  
  35. function myFunction1() {
  36. myVariable = 'Hello 1';
  37. }
  38.  
  39. function myFunction2() {
  40. myVariable = 'Hello 2';
  41. }
  42.  
  43. function dosomething(){
  44. var i = 0; // can only be used inside function
  45. }
  46.  
  47. var i = '';
  48. function dosomething(){
  49. i = 0; // can be used inside and outside the function
  50. }
  51.  
  52. <!DOCTYPE html>
  53. <html>
  54. <head>
  55. <script type="text/javascript" src="init.js"></script>
  56. <script type="text/javascript">
  57. MYLIBRARY.init(["firstValue", 2, "thirdValue"]);
  58. </script>
  59. <script src="script.js"></script>
  60. </head>
  61.  
  62. <body>
  63. <h1>Hello !</h1>
  64. </body>
  65. </html>
  66.  
  67. var MYLIBRARY = MYLIBRARY || (function(){
  68. var _args = {}; // private
  69.  
  70. return {
  71. init : function(Args) {
  72. _args = Args;
  73. // some other initialising
  74. },
  75. helloWorld : function(i) {
  76. return _args[i];
  77. }
  78. };
  79. }());
  80.  
  81. // Here you can use the values defined in the html as if it were a global variable
  82. var a = "Hello World " + MYLIBRARY.helloWorld(2);
  83.  
  84. alert(a);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement