| Conditions | 1 |
| Paths | 1 |
| Total Lines | 166 |
| Code Lines | 164 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | <?php |
||
| 46 | function tiny_hook_header_javascript () { |
||
| 47 | $code = <<<'EOD' |
||
| 48 | <script type="text/javascript"> |
||
| 49 | document.documentElement.className = 'js'; |
||
| 50 | |||
| 51 | // https://github.com/filamentgroup/loadCSS |
||
| 52 | function loadCSS( href, before, media, callback ){ |
||
| 53 | "use strict"; |
||
| 54 | var ss = window.document.createElement( "link" ); |
||
| 55 | var ref = before || window.document.getElementsByTagName( "script" )[ 0 ]; |
||
| 56 | var sheets = window.document.styleSheets; |
||
| 57 | ss.rel = "stylesheet"; |
||
| 58 | ss.href = href; |
||
| 59 | ss.media = "only x"; |
||
| 60 | if( callback ) { |
||
| 61 | ss.onload = callback; |
||
| 62 | } |
||
| 63 | ref.parentNode.insertBefore( ss, ref ); |
||
| 64 | ss.onloadcssdefined = function( cb ){ |
||
| 65 | var defined; |
||
| 66 | for( var i = 0; i < sheets.length; i++ ){ |
||
| 67 | if( sheets[ i ].href && sheets[ i ].href.indexOf( href ) > -1 ){ |
||
| 68 | defined = true; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | if( defined ){ |
||
| 72 | cb(); |
||
| 73 | } else { |
||
| 74 | setTimeout(function() { |
||
| 75 | ss.onloadcssdefined( cb ); |
||
| 76 | }); |
||
| 77 | } |
||
| 78 | }; |
||
| 79 | ss.onloadcssdefined(function() { |
||
| 80 | ss.media = media || "all"; |
||
| 81 | }); |
||
| 82 | return ss; |
||
| 83 | } |
||
| 84 | |||
| 85 | // script.js |
||
| 86 | (function (name, definition) { |
||
| 87 | if (typeof module != 'undefined' && module.exports) module.exports = definition() |
||
| 88 | else if (typeof define == 'function' && define.amd) define(definition) |
||
| 89 | else this[name] = definition() |
||
| 90 | })('$script', function () { |
||
| 91 | var doc = document |
||
| 92 | , head = doc.getElementsByTagName('head')[0] |
||
| 93 | , s = 'string' |
||
| 94 | , f = false |
||
| 95 | , push = 'push' |
||
| 96 | , readyState = 'readyState' |
||
| 97 | , onreadystatechange = 'onreadystatechange' |
||
| 98 | , list = {} |
||
| 99 | , ids = {} |
||
| 100 | , delay = {} |
||
| 101 | , scripts = {} |
||
| 102 | , scriptpath |
||
| 103 | , urlArgs |
||
| 104 | |||
| 105 | function every(ar, fn) { |
||
| 106 | for (var i = 0, j = ar.length; i < j; ++i) if (!fn(ar[i])) return f |
||
| 107 | return 1 |
||
| 108 | } |
||
| 109 | function each(ar, fn) { |
||
| 110 | every(ar, function (el) { |
||
| 111 | return !fn(el) |
||
| 112 | }) |
||
| 113 | } |
||
| 114 | |||
| 115 | function $script(paths, idOrDone, optDone) { |
||
| 116 | paths = paths[push] ? paths : [paths] |
||
| 117 | var idOrDoneIsDone = idOrDone && idOrDone.call |
||
| 118 | , done = idOrDoneIsDone ? idOrDone : optDone |
||
| 119 | , id = idOrDoneIsDone ? paths.join('') : idOrDone |
||
| 120 | , queue = paths.length |
||
| 121 | function loopFn(item) { |
||
| 122 | return item.call ? item() : list[item] |
||
| 123 | } |
||
| 124 | function callback() { |
||
| 125 | if (!--queue) { |
||
| 126 | list[id] = 1 |
||
| 127 | done && done() |
||
| 128 | for (var dset in delay) { |
||
| 129 | every(dset.split('|'), loopFn) && !each(delay[dset], loopFn) && (delay[dset] = []) |
||
| 130 | } |
||
| 131 | } |
||
| 132 | } |
||
| 133 | setTimeout(function () { |
||
| 134 | each(paths, function loading(path, force) { |
||
| 135 | if (path === null) return callback() |
||
| 136 | path = !force && path.indexOf('.js') === -1 && !/^https?:\/\//.test(path) && scriptpath ? scriptpath + path + '.js' : path |
||
| 137 | if (scripts[path]) { |
||
| 138 | if (id) ids[id] = 1 |
||
| 139 | return (scripts[path] == 2) ? callback() : setTimeout(function () { loading(path, true) }, 0) |
||
| 140 | } |
||
| 141 | |||
| 142 | scripts[path] = 1 |
||
| 143 | if (id) ids[id] = 1 |
||
| 144 | create(path, callback) |
||
| 145 | }) |
||
| 146 | }, 0) |
||
| 147 | return $script |
||
| 148 | } |
||
| 149 | |||
| 150 | function create(path, fn) { |
||
| 151 | var el = doc.createElement('script'), loaded |
||
| 152 | el.onload = el.onerror = el[onreadystatechange] = function () { |
||
| 153 | if ((el[readyState] && !(/^c|loade/.test(el[readyState]))) || loaded) return; |
||
| 154 | el.onload = el[onreadystatechange] = null |
||
| 155 | loaded = 1 |
||
| 156 | scripts[path] = 2 |
||
| 157 | fn() |
||
| 158 | } |
||
| 159 | el.async = 1 |
||
| 160 | el.src = urlArgs ? path + (path.indexOf('?') === -1 ? '?' : '&') + urlArgs : path; |
||
| 161 | head.insertBefore(el, head.lastChild) |
||
| 162 | } |
||
| 163 | |||
| 164 | $script.get = create |
||
| 165 | |||
| 166 | $script.order = function (scripts, id, done) { |
||
| 167 | (function callback(s) { |
||
| 168 | s = scripts.shift() |
||
| 169 | !scripts.length ? $script(s, id, done) : $script(s, callback) |
||
| 170 | }()) |
||
| 171 | } |
||
| 172 | |||
| 173 | $script.path = function (p) { |
||
| 174 | scriptpath = p |
||
| 175 | } |
||
| 176 | $script.urlArgs = function (str) { |
||
| 177 | urlArgs = str; |
||
| 178 | } |
||
| 179 | $script.ready = function (deps, ready, req) { |
||
| 180 | deps = deps[push] ? deps : [deps] |
||
| 181 | var missing = []; |
||
| 182 | !each(deps, function (dep) { |
||
| 183 | list[dep] || missing[push](dep); |
||
| 184 | }) && every(deps, function (dep) {return list[dep]}) ? |
||
| 185 | ready() : !function (key) { |
||
| 186 | delay[key] = delay[key] || [] |
||
| 187 | delay[key][push](ready) |
||
| 188 | req && req(missing) |
||
| 189 | }(deps.join('|')) |
||
| 190 | return $script |
||
| 191 | } |
||
| 192 | |||
| 193 | $script.done = function (idOrDone) { |
||
| 194 | $script([null], idOrDone) |
||
| 195 | } |
||
| 196 | |||
| 197 | return $script |
||
| 198 | }); |
||
| 199 | </script> |
||
| 200 | |||
| 201 | <script async> |
||
| 202 | // loadCSS( 'fontURL' ); |
||
| 203 | // loadCSS( '/wp-content/themes/theme_name/style.css' ); |
||
| 204 | </script> |
||
| 205 | <noscript> |
||
| 206 | <!-- <link rel='stylesheet' id='divi-fonts-css' href='fontURL' type='text/css' media='all' /> --> |
||
| 207 | <!-- <link rel='stylesheet' id='divi-fonts-css' href='themestyleURL' type='text/css' media='all' /> --> |
||
| 208 | </noscript> |
||
| 209 | EOD; |
||
| 210 | |||
| 211 | echo $code; |
||
| 212 | } |
||
| 284 |