Replace manual DOM manipulation with one document.createElement and innerHTML
authorJack Allnutt <m2ys4u@gmail.com>
Wed, 22 May 2013 09:04:51 +0000 (10:04 +0100)
committerJack Allnutt <m2ys4u@gmail.com>
Wed, 22 May 2013 09:04:51 +0000 (10:04 +0100)
client/assets/dev/applet_chanlist.js

index 3e1f8ab64d5227697ef7b3c8afb47f616cf59868..698d857f26d362b3c367711dffccae64a76482e6 100644 (file)
                 channels = [channels];\r
             }\r
             _.each(channels, function (chan) {\r
-                var frag, row, name, chanlink, num_users, topic;\r
-                frag = document.createDocumentFragment();\r
+                var row;\r
                 row = document.createElement("tr");\r
-                name = document.createElement("td");\r
-                chanlink = document.createElement("a");\r
-                if (typeof chanlink.dataset !== "undefined") {\r
-                    chanlink.dataset.channel = chan.channel;\r
-                } else {\r
-                    chanlink.setAttribute('data-channel', chan.channel);\r
-                }\r
-                chanlink.textContent = _.escape(chan.channel);\r
-                chanlink.classList.add('chan');\r
-                name.appendChild(chanlink);\r
-                row.appendChild(name);\r
-                num_users = document.createElement("td");\r
-                num_users.textContent = chan.num_users;\r
-                num_users.classList.add("num_users");\r
-                num_users.style.textAlign = 'center';\r
-                row.appendChild(num_users);\r
-                topic = document.createElement("td");\r
-                topic.style.paddingLeft = '2em';\r
-                topic.innerHTML = formatIRCMsg(_.escape(chan.topic));\r
-                row.appendChild(topic);\r
-                frag.appendChild(row);\r
-\r
-                chan.dom = frag;\r
+                row.innerHTML = '<td><a class="chan" data-channel="' + chan.channel + '">' + _.escape(chan.channel) + '</a></td><td class="num_users" style="text-align: center;">' + chan.num_users + '</td><td style="padding-left: 2em;">' + formatIRCMsg(_.escape(chan.topic)) + '</td>';\r
+                chan.dom = row;\r
                 that.view.channels.push(chan);\r
             });\r
 \r