Advertisement
kheeper

Do not know why it is not working ...

May 3rd, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. The HTML:
  2. <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  3. <script src="http://example.com/scripts/loader.js"></script>
  4.  
  5. The PHP:
  6. if ($something == $somethingelse) {
  7. echo ("<div id=\"errorMessage\">Some error message</div>);
  8. }
  9.  
  10. The loader.js
  11. function include (filename) {
  12.  
  13. var js = document.createElement('script');
  14.  
  15. js.setAttribute('type', 'text/javascript');
  16. js.setAttribute('src', filename);
  17. js.setAttribute('defer', 'defer');
  18. document.getElementsByTagName('HEAD')[0].appendChild(js);
  19.  
  20. var cur_file = {};
  21. cur_file[window.location.href] = 1;
  22.  
  23. if (!window.php_js) window.php_js = {};
  24. if (!window.php_js.includes) window.php_js.includes = cur_file;
  25. if (!window.php_js.includes[filename]) {
  26. window.php_js.includes[filename] = 1;
  27. } else {
  28. window.php_js.includes[filename]++;
  29. }
  30.  
  31. return window.php_js.includes[filename];
  32.  
  33. }
  34.  
  35. include('http://example.com/scripts/PopUpMessages.js');
  36.  
  37. $(document).ready(function() {
  38. $("#errorMessage").PopUpMessages({
  39. textColor: '#ffffff',
  40. backgroundColor: '#ff5555',
  41. borderColor: '#800000'
  42. });
  43. });
  44.  
  45. The PopUpMessages.js
  46. (function($) {
  47.  
  48. $.fn.PopUpMessages = function(options) {
  49.  
  50. var defaults = {
  51. fadeInTime: '1000',
  52. fadeOutTime: '1000',
  53. textColor: '#333333',
  54. backgroundColor: '#ffdd55',
  55. borderColor: '#aa8800'
  56. };
  57.  
  58. var options = $.extend(defaults, options);
  59.  
  60. $(this).fadeIn(options.fadeInTime);
  61.  
  62. };
  63.  
  64. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement