nicer js
[plewww.git] / plekit / niftycorner / nifty_init.js
index b927d9e..c412140 100644 (file)
@@ -1,9 +1,9 @@
-/* 
+/*
   $Id$
 
- instead of explicitly calling 
+ instead of explicitly calling
  Nifty ('div#$id','medium');
- on every single element as the original niftycube.js recommends, 
+ on every single element as the original niftycube.js recommends,
  we just do that on every element that has one of the
  the nifty-{small,medium,big} class set
 */
 var nifty_inited = false;
 
 function nifty_init () {
+  
   if ( nifty_inited ) return;
-  var elements=document.getElementsByClassName('nifty-medium');
-  for (var i=0; i<elements.length; i++) {
-    // somehow we catch something with an empty id
-    id = elements[i].id;
-    if (id) {
-      window.console.log('nifty initing id [' + id + ']');
-      Nifty('div#'+id,'medium');
+  const sizes = { 0: 'small', 1: 'medium', 2: 'big', length: 3}
+  for (const [int, size] of Object.entries(sizes)) {
+
+    let elements = document.getElementsByClassName('nifty-'+size)
+    for (const element of elements) {
+      // use Rounded rather than Nifty
+      // the latter needs an id that some elements don't have
+      // plus, it's more efficient anyway
+      pleRounded(element, size)
     }
   }
-  nifty_inited = true;
+  nifty_inited = true
 }
-