Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. // console.log('here2');
  2. function sortCustomLinks(that, condition) {
  3. console.log(condition);
  4. // $(that).closest('ul').find('li').map((index, val) => {
  5. // if (condition) {
  6. // $(val).find('.custom_f').attr('name', $(val).find('.custom_f').attr('name').slice(0, -1) + (index+1))
  7. // } else {
  8. // $(val).find('.title').attr('name', $(val).find('.title').attr('name').slice(0, -1) + (index+1))
  9. // $(val).find('.url').attr('name', $(val).find('.url').attr('name').slice(0, -1) + (index+1))
  10. // $(val).find('select.icon').attr('name', $(val).find('select.icon').attr('name').slice(0, -1) + (index+1))
  11. // }
  12. // })
  13. }
  14. jQuery(document).ready(function($){
  15. $('.mySelect').selectpicker();
  16. // $('.exam')
  17. $('ul.example').sortable({
  18. onDrop: function($item, container, _super) {
  19. $item.find('ol.dropdown-menu').sortable('enable');
  20. _super($item, container);
  21. if ($item.parent().find('.custom_links')) {
  22. console.log('custom links');
  23. sortCustomLinks($item, 'links');
  24. }
  25. if ($item.parent().find('.custom_field')) {
  26. sortCustomLinks($item, 'fields');
  27. console.log('custom fields');
  28. }
  29. console.log('dropped')
  30. }
  31. })
  32.  
  33.  
  34. var maxField = 100; //Input fields increment limitation
  35. var addButton = $('.add_button'); //Add button selector
  36. var addButtonUserProfile = $('.add_button_up');
  37. var wrapper = $('.field_wrapper'); //Input field wrapper
  38. var x = 1; //Initial field counter is 1
  39. $(addButton).click(function(){
  40. // $(this).attr('class','remove_button').find('i').attr('class','fa fa-minus icon-remove');
  41. const div_count = parseInt($(this).siblings('ul').find('li').length)+1;
  42. const user_id = $(this)[0].attributes['id-ref'].value;
  43. if(x < maxField){
  44. x++; //Increment field counter
  45. $( $(this).siblings('ul')).append(
  46. `<li class="item"><div class="user-custom-links" style="display: flex; margin: 10px 0">
  47. <a href='javascript:void(0);'><i class="fa fa-bars fa-lg"></i></a>
  48. <label>Title: <input placeholder='Enter Link Title'" type="text" name="link_title_`+user_id+`_`+div_count+`"/></label>
  49. <label style="display: flex; width: 200px; align-items: center;">Icon:
  50. <select name="link_icon_`+user_id+`_`+(div_count)+`" data-show-content="true" class="form-control mySelect">
  51. <option value="" >Select Icon</option>
  52. <option value="globe" data-content="<i class='fa fa-globe'></i> globe"></option>
  53. <option value="user" data-content="<i class='fa fa-user'></i> user"></option>
  54. <option value="map-marker" data-content="<i class='fa fa-map-marker'></i> map-marker"></option>
  55. <option value="envelope" data-content="<i class='fa fa-envelope'></i>"> envelope</option>
  56. <option value="address-book" data-content="<i class='fa fa-address-book'></i> address-book"></option>
  57. </select>
  58. </label>
  59. <label>URL: <input placeholder='Enter Link Url' type="text" name="link_url_`+user_id+`_`+(div_count)+`"/></label>
  60. <a style="margin-left: 5px;" href="javascript:void(0);" class="remove_button">
  61. <i class="fa fa-minus icon-remove"></i>
  62. </a>
  63. </div></li>`
  64. );
  65. $('.mySelect').selectpicker();
  66. }
  67. });
  68. $(addButtonUserProfile).click(function(){
  69. const div_count = parseInt($(this).siblings('ul').find('li').length)+1;
  70. if(x < maxField){
  71. x++; //Increment field counter
  72. $( $(this).siblings('ul')).append(
  73. `<li class="item"><div class="user-custom-links" style="display: flex; margin: 10px 0"><a href='javascript:void(0);'><i class="fa fa-bars fa-lg"></i></a>
  74. <label>Name: <input class="custom_f" placeholder="Enter name" type="text" name="custom_field_`+div_count+`" value=""/></label>
  75. <a style="margin-left: 5px;" href="javascript:void(0);" class="remove_button">
  76. <i class="fa fa-minus icon-remove"></i>
  77. </a>
  78. </div></li>`
  79. ); //Add field html
  80. }
  81. });
  82.  
  83. $(document).on('click', '.remove_button', function(e){
  84. e.preventDefault();
  85. const user_id = $(this).closest('.user_profile_wrapper').find('.countDeletedFields').attr('ref-id');
  86. $('#countDeletedFields_' + user_id ).val( parseInt($('#countDeletedFields_' + user_id).val())+1 )
  87. $('#fieldsCountDeletedFields').val( parseInt($('#fieldsCountDeletedFields').val())+1 )
  88.  
  89. // const that = $(this);
  90. console.log($(this).closest('li'))
  91. const that = $(this).closest('ul').find('li')
  92. $(this).closest('li').remove(); //Remove field html
  93. sortCustomLinks(that)
  94. // console.log($(this).parent().parent().parent().parent().find('li'))
  95.  
  96. x--;
  97. });
  98. });
  99.  
  100. function makeid(length) {
  101. var result = '';
  102. var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  103. var charactersLength = characters.length;
  104. for ( var i = 0; i < length; i++ ) {
  105. result += characters.charAt(Math.floor(Math.random() * charactersLength));
  106. }
  107. return result;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement