PageRenderTime 34ms CodeModel.GetById 25ms app.highlight 6ms 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
 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 */
11define(function( require )
12{
13	'use strict';
14
15
16	/**
17	 * Dependencies
18	 */
19	var _htmlText    = require('text!./Error.html');
20	var _cssText     = require('text!./Error.css');
21	var jQuery       = require('Vendors/jquery');
22
23
24	/**
25	 * Error Namespace
26	 */
27	var Error = {};
28
29
30	/**
31	 * Initialize Metaling
32	 */
33	Error.init = function init()
34	{
35		this.ui = jQuery(_htmlText);
36
37		// Add view to html
38		var style = jQuery('style:first');
39		if (!style.length) {
40			style = jQuery('<style type="text/css"></style>').appendTo('head');
41		}
42		style.append('\n' + _cssText);
43		jQuery('body').html(this.ui);
44
45		this.ui.css('backgroundImage', 'url('+ require.toUrl('./angeling.png') +')');
46	};
47
48
49	/**
50	 * Add trace info to UI
51	 *
52	 * @param {Error} error
53	 */
54	Error.addTrace = function addTrace( error )
55	{
56		var url = requirejs.toUrl(''); // global
57		error   = error.stack || error;
58
59		url   = url.replace(/\/([^\/]+)$/g,'/');
60		error = error.replace( /\n/g, '<br/>');
61		error = error.replace( new RegExp(url,'g'), '');
62		error = error.replace( /\?[^\:]+/g,'');
63
64		if (!this.ui) {
65			this.init();
66		}
67
68		this.ui.find('.trace').append(
69			error  + '<br />'
70		);
71	};
72
73
74	/**
75	 * Stored component and return it
76	 */
77	return Error;
78});