Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. String.prototype.toDataProp = function() {
  2. var min = "A".charCodeAt(0),
  3. max = "Z".charCodeAt(0),
  4. res = "data-";
  5. this.split("").forEach(function(char, i) {
  6. var cc = char.charCodeAt(0);
  7. if (cc >= min && cc <= max) {
  8. res += ((i > 0) ? "-" : "") + String.fromCharCode(cc + 32);
  9. } else {
  10. res += char;
  11. }
  12. });
  13. return res;
  14. }
  15.  
  16. String.prototype.fromDataProp = function() {
  17. var min = "A".charCodeAt(0),
  18. max = "Z".charCodeAt(0),
  19. res = "",
  20. temp = this.split('data-')[1];
  21. temp.split("-").forEach(function(word, i) {
  22. if (i > 0) {
  23. res += String.fromCharCode(word.charCodeAt(0) - 32) + word.substr(1, word.length - 1);
  24. } else {
  25. res += word;
  26. }
  27. });
  28. return res;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement