fake-element.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. var fakeElement = {};
  2. fakeElement.constanants = 'b c d f g k l m n p q r s t v x z'.split(' ');
  3. fakeElement.vowels = 'a e i o u y'.split(' ');
  4. fakeElement.categories = 'alkali alkaline-earth lanthanoid actinoid transition post-transition'.split(' ');
  5. fakeElement.suffices = 'on ium ogen'.split(' ');
  6. fakeElement.getRandom = function( property ) {
  7. var values = fakeElement[ property ];
  8. return values[ Math.floor( Math.random() * values.length ) ];
  9. };
  10. fakeElement.create = function() {
  11. var widthClass = Math.random()*10 > 6 ? 'width2' : 'width1';
  12. heightClass = Math.random()*10 > 6 ? 'height2' : 'height1';
  13. category = fakeElement.getRandom('categories');
  14. className = 'element fake metal ' + category + ' ' + widthClass + ' ' + heightClass;
  15. letter1 = fakeElement.getRandom('constanants').toUpperCase();
  16. letter2 = fakeElement.getRandom('constanants');
  17. symbol = letter1 + letter2;
  18. name = letter1 + fakeElement.getRandom('vowels') + letter2 + fakeElement.getRandom('vowels') + fakeElement.getRandom('constanants') + fakeElement.getRandom('suffices');
  19. number = ~~( 21 + Math.random() * 100 );
  20. weight = ~~( number * 2 + Math.random() * 15 );
  21. return '<div class="' + className + '" data-symbol="' + symbol +
  22. '" data-category="' + category + '"><p class="number">' + number +
  23. '</p><h3 class="symbol">' + symbol + '</h3><h2 class="name">' + name +
  24. '</h2><p class="weight">' + weight + '</p></div>';
  25. };
  26. fakeElement.getGroup = function() {
  27. var i = Math.ceil( Math.random()*3 + 1 ),
  28. newEls = '';
  29. while ( i-- ) {
  30. newEls += fakeElement.create();
  31. }
  32. return newEls;
  33. };