custom-fields-js.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php if(!defined('__TYPECHO_ADMIN__')) exit; ?>
  2. <script>
  3. $(document).ready(function () {
  4. // 自定义字段
  5. $('#custom-field-expand').click(function() {
  6. var btn = $('i', this);
  7. if (btn.hasClass('i-caret-right')) {
  8. btn.removeClass('i-caret-right').addClass('i-caret-down');
  9. } else {
  10. btn.removeClass('i-caret-down').addClass('i-caret-right');
  11. }
  12. $(this).parent().toggleClass('fold');
  13. return false;
  14. });
  15. function attachDeleteEvent (el) {
  16. $('button.btn-xs', el).click(function () {
  17. if (confirm('<?php _e('确认要删除此字段吗?'); ?>')) {
  18. $(this).parents('tr').fadeOut(function () {
  19. $(this).remove();
  20. });
  21. $(this).parents('form').trigger('field');
  22. }
  23. });
  24. }
  25. $('#custom-field table tbody tr').each(function () {
  26. attachDeleteEvent(this);
  27. });
  28. $('#custom-field button.operate-add').click(function () {
  29. var html = '<tr><td><input type="text" name="fieldNames[]" placeholder="<?php _e('字段名称'); ?>" class="text-s w-100"></td>'
  30. + '<td><select name="fieldTypes[]" id="">'
  31. + '<option value="str"><?php _e('字符'); ?></option>'
  32. + '<option value="int"><?php _e('整数'); ?></option>'
  33. + '<option value="float"><?php _e('小数'); ?></option>'
  34. + '</select></td>'
  35. + '<td><textarea name="fieldValues[]" placeholder="<?php _e('字段值'); ?>" class="text-s w-100" rows="2"></textarea></td>'
  36. + '<td><button type="button" class="btn btn-xs"><?php _e('删除'); ?></button></td></tr>',
  37. el = $(html).hide().appendTo('#custom-field table tbody').fadeIn();
  38. $(':input', el).bind('input change', function () {
  39. $(this).parents('form').trigger('field');
  40. });
  41. attachDeleteEvent(el);
  42. });
  43. });
  44. </script>