Conditions | 1 |
Paths | 10 |
Total Lines | 87 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
7 | (function($, Symphony) { |
||
8 | 'use strict'; |
||
9 | |||
10 | // Set environment |
||
11 | var environment = (function () { |
||
12 | var env = document.getElementById('environment'); |
||
13 | return env ? JSON.parse(env.textContent) : {}; |
||
14 | })(); |
||
15 | Symphony.Context.add(null, environment); |
||
16 | |||
17 | // Get translations |
||
18 | Symphony.Language.add({ |
||
19 | 'Are you sure you want to proceed?': false, |
||
20 | 'Reordering was unsuccessful.': false, |
||
21 | 'Change Password': false, |
||
22 | 'Remove File': false, |
||
23 | 'Untitled Field': false, |
||
24 | 'The field “{$title}” ({$type}) has been removed.': false, |
||
25 | 'Undo?': false, |
||
26 | 'untitled': false, |
||
27 | 'Expand all': false, |
||
28 | 'Collapse all': false, |
||
29 | 'drag to reorder': false, |
||
30 | 'Please reset your password': false, |
||
31 | 'required': false, |
||
32 | 'Click to select': false, |
||
33 | 'Type to search': false, |
||
34 | 'Clear': false, |
||
35 | 'Search for {$item}': false, |
||
36 | 'Add filter': false, |
||
37 | 'filtered': false, |
||
38 | 'None': false, |
||
39 | 'Clear filters': false, |
||
40 | 'Apply filters': false, |
||
41 | 'The Symphony calendar widget has been disabled because your system date format is currently not supported. Try one of the following instead or disable the calendar in the field settings:': false, |
||
42 | 'no leading zero': false |
||
43 | }); |
||
44 | |||
45 | // Initialise backend |
||
46 | $(function() { |
||
47 | |||
48 | // Cache main elements |
||
49 | Symphony.Elements.window = $(window); |
||
50 | Symphony.Elements.html = $('html').addClass('js-active'); |
||
51 | Symphony.Elements.body = $('body'); |
||
52 | Symphony.Elements.wrapper = $('#wrapper'); |
||
53 | Symphony.Elements.header = $('#header'); |
||
54 | Symphony.Elements.nav = $('#nav'); |
||
55 | Symphony.Elements.session = $('#session'); |
||
56 | Symphony.Elements.context = $('#context'); |
||
57 | Symphony.Elements.breadcrumbs = $('#breadcrumbs'); |
||
58 | Symphony.Elements.contents = $('#contents'); |
||
59 | |||
60 | // Create context id |
||
61 | var path = Symphony.Context.get('path'); |
||
62 | var route = Symphony.Context.get('route'); |
||
63 | if (path && route) { |
||
64 | var contextId = (path + route).split('/').filter(function(part) { |
||
65 | return (part != 'edit' && part != 'new' && part != 'created' && part != 'saved' && part != ''); |
||
66 | }).join('.'); |
||
67 | Symphony.Context.add('context-id', contextId); |
||
68 | } |
||
69 | |||
70 | // Render view |
||
71 | Symphony.View.render(); |
||
72 | |||
73 | // Update state to canonical url |
||
74 | if (window.history.replaceState) { |
||
75 | var replaceState = function () { |
||
76 | $('head > link[rel="canonical"][href]').eq(0).each(function () { |
||
77 | var href = $(this).attr('href'); |
||
78 | if (href) { |
||
79 | window.history.replaceState(document.title, null, href); |
||
80 | } |
||
81 | }); |
||
82 | }; |
||
83 | // Let extensions read the window.location when load is completed |
||
84 | if (document.readyState === 'complete') { |
||
85 | replaceState(); |
||
86 | } else { |
||
87 | // Document not loaded, delay change on load |
||
88 | $(window).on('load', replaceState); |
||
89 | } |
||
90 | } |
||
91 | }); |
||
92 | |||
93 | })(window.jQuery, window.Symphony); |
||
94 |