PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/src/UI/Components/Error/Error.js

https://github.com/OmarAcero/roBrowser
JavaScript | 78 lines | 35 code | 15 blank | 28 comment | 3 complexity | e526827f5b9096e1ae64f6b6c99101e4 MD5 | raw file
Possible License(s): GPL-3.0
  1. /**
  2. * UI/Components/Error/Error.js
  3. *
  4. * Error screen
  5. * Don't use components class, if there is an error on this module will never be used...
  6. *
  7. * This file is part of ROBrowser, Ragnarok Online in the Web Browser (http://www.robrowser.com/).
  8. *
  9. * @author Vincent Thibault
  10. */
  11. define(function( require )
  12. {
  13. 'use strict';
  14. /**
  15. * Dependencies
  16. */
  17. var _htmlText = require('text!./Error.html');
  18. var _cssText = require('text!./Error.css');
  19. var jQuery = require('Vendors/jquery');
  20. /**
  21. * Error Namespace
  22. */
  23. var Error = {};
  24. /**
  25. * Initialize Metaling
  26. */
  27. Error.init = function init()
  28. {
  29. this.ui = jQuery(_htmlText);
  30. // Add view to html
  31. var style = jQuery('style:first');
  32. if (!style.length) {
  33. style = jQuery('<style type="text/css"></style>').appendTo('head');
  34. }
  35. style.append('\n' + _cssText);
  36. jQuery('body').html(this.ui);
  37. this.ui.css('backgroundImage', 'url('+ require.toUrl('./angeling.png') +')');
  38. };
  39. /**
  40. * Add trace info to UI
  41. *
  42. * @param {Error} error
  43. */
  44. Error.addTrace = function addTrace( error )
  45. {
  46. var url = requirejs.toUrl(''); // global
  47. error = error.stack || error;
  48. url = url.replace(/\/([^\/]+)$/g,'/');
  49. error = error.replace( /\n/g, '<br/>');
  50. error = error.replace( new RegExp(url,'g'), '');
  51. error = error.replace( /\?[^\:]+/g,'');
  52. if (!this.ui) {
  53. this.init();
  54. }
  55. this.ui.find('.trace').append(
  56. error + '<br />'
  57. );
  58. };
  59. /**
  60. * Stored component and return it
  61. */
  62. return Error;
  63. });