Total Complexity | 8 |
Complexity/F | 1.6 |
Lines of Code | 41 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | $(window).on('load', function() { |
||
2 | var editor = window.editors[window.midgard_admin_asgard_shell_identifier], |
||
3 | storage_available = (typeof window.localStorage !== 'undefined' && window.localStorage); |
||
4 | |||
5 | $('#output-wrapper').hide(); |
||
6 | |||
7 | if (storage_available) { |
||
8 | $('#save-script').on('click', function(event) { |
||
9 | event.preventDefault(); |
||
10 | var script = editor.getValue(); |
||
11 | window.localStorage.setItem('saved-script', script); |
||
12 | $('#restore-script').removeClass('disabled'); |
||
13 | }); |
||
14 | $('#restore-script').on('click', function(event) { |
||
15 | event.preventDefault(); |
||
16 | var script = window.localStorage.getItem('saved-script'); |
||
17 | if (script) { |
||
18 | editor.setValue(script); |
||
19 | } |
||
20 | }); |
||
21 | $('#clear-script').on('click', function(event) { |
||
22 | event.preventDefault(); |
||
23 | window.localStorage.removeItem('saved-script'); |
||
24 | $('#restore-script').addClass('disabled'); |
||
25 | editor.setValue(''); |
||
26 | }); |
||
27 | if (!window.localStorage.getItem('saved-script')) { |
||
28 | $('#restore-script').addClass('disabled'); |
||
29 | } |
||
30 | } else { |
||
31 | $('#save-script, #restore-script, #clear-script').hide(); |
||
32 | } |
||
33 | var form_id = window.midgard_admin_asgard_shell_identifier.slice(0, -5); |
||
34 | |||
35 | $("#" + form_id) |
||
36 | .attr('target', 'shell-runner') |
||
37 | .attr('action', $("#" + form_id).attr('action') + '?ajax') |
||
38 | .on('submit', function() { |
||
39 | $('#output-wrapper').show(); |
||
40 | }); |
||
41 | }); |
||
42 |