fe-jsonformat.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * JSON格式化
  3. */
  4. baidu.jsonformat = (function () {
  5. "use strict";
  6. var _bindEvents = function () {
  7. $('#btnFormat').click(function (e) {
  8. var source = $.trim($('#jsonSource').val());
  9. JsonFormatEntrance.clear();
  10. JsonFormatEntrance.format(source);
  11. });
  12. // 点击区块高亮
  13. $('#jfContent').delegate('.kvov', 'click',function (e) {
  14. $('#jfContent .kvov').removeClass('x-outline');
  15. $(this).removeClass('x-hover').addClass('x-outline');
  16. if (!$(e.target).is('.kvov .e')) {
  17. e.stopPropagation();
  18. } else {
  19. $(e.target).parent().trigger('click');
  20. }
  21. }).delegate('.kvov', 'mouseover',function (e) {
  22. $(this).addClass('x-hover');
  23. return false;
  24. }).delegate('.kvov', 'mouseout', function (e) {
  25. $(this).removeClass('x-hover');
  26. });
  27. };
  28. var _init = function () {
  29. $(function () {
  30. //输入框聚焦
  31. jQuery("#jsonSource").focus();
  32. _bindEvents();
  33. });
  34. };
  35. return {
  36. init:_init
  37. };
  38. })();
  39. baidu.jsonformat.init();