From c9146d8adecd32ccb19dc1741df4d2452291dd74 Mon Sep 17 00:00:00 2001 From: Lea Verou Date: Thu, 1 Nov 2018 18:57:40 +0100 Subject: [PATCH] Fix code style --- css3patterns.js | 96 ++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/css3patterns.js b/css3patterns.js index 3320996..7d1cab9 100755 --- a/css3patterns.js +++ b/css3patterns.js @@ -1,80 +1,80 @@ (function(){ -var patterns = document.querySelectorAll('#patterns > li'), +var patterns = document.querySelectorAll("#patterns > li"), recentPattern = null, currentPattern = null; -for(var i=0; i' + title + ''; - - code.value = pattern.getAttribute('style'); - code.setAttribute('data-subject', '#patterns li:nth-child(' + (i+1) + ')'); - code.setAttribute('wrap', 'off'); + + var div = document.createElement("div"), + heading = div.appendChild(document.createElement("h2")), + code = document.createElement("textarea"), + title = pattern.getAttribute("title"), + close = div.appendChild(document.createElement("a")); + + pattern.id = title.toLowerCase().replace(/\s+/g, "-"); + + heading.innerHTML = '' + title + ""; + + code.value = pattern.getAttribute("style"); + code.setAttribute("data-subject", "#patterns li:nth-child(" + (i+1) + ")"); + code.setAttribute("wrap", "off"); code.oninput = function() { - var byteSize = this.parentNode.querySelector('.bytesize'); - - if(byteSize) { + var byteSize = this.parentNode.querySelector(".bytesize"); + + if (byteSize) { byteSize.innerHTML = ByteSize.format(ByteSize.count(this.value), true); } + }; + + close.className = "close"; + close.href = "#"; + close.innerHTML = "✖"; + + if (window.ByteSize) { + heading.innerHTML += ' (' + ByteSize.format(ByteSize.count(code.value), true) + ")"; } - - close.className = 'close'; - close.href = '#'; - close.innerHTML = '✖'; - - if(window.ByteSize) { - heading.innerHTML += ' (' + ByteSize.format(ByteSize.count(code.value), true) + ')'; - } - - var author = pattern.getAttribute('data-author'); - if(author) { - var p = div.appendChild(document.createElement('p')), - authorUrl = pattern.getAttribute('data-author-url'); - p.innerHTML = 'by ' + (authorUrl? '' + author + '' : author); + + var author = pattern.getAttribute("data-author"); + if (author) { + var p = div.appendChild(document.createElement("p")), + authorUrl = pattern.getAttribute("data-author-url"); + p.innerHTML = "by " + (authorUrl? '' + author + "" : author); } - + div.appendChild(code); - + pattern.appendChild(div); - + pattern.onclick = function(evt) { // Firefox has focus issues if we don't restrict this - if(!/textarea/i.test(evt.target.nodeName)) { - location.hash = '#' + this.id; + if (!/textarea/i.test(evt.target.nodeName)) { + location.hash = "#" + this.id; } }; - + pattern.snippet = new CSSSnippet(code); - + window.Incrementable && new Incrementable(code); } (onhashchange = function() { - var pattern = location.hash? document.querySelector('#patterns li' + location.hash) : null; - - if(pattern) { + var pattern = location.hash? document.querySelector("#patterns li" + location.hash) : null; + + if (pattern) { recentPattern = currentPattern = pattern; - document.body.setAttribute('style', pattern.getAttribute('style')); + document.body.setAttribute("style", pattern.getAttribute("style")); pattern.snippet.subjects[1] = document.body; } else { currentPattern = null; - document.body.removeAttribute('style'); - - if(recentPattern) { + document.body.removeAttribute("style"); + + if (recentPattern) { delete recentPattern.snippet.subjects[1]; } } })(); -})(); \ No newline at end of file +})();