Guest User

Untitled

a guest
Sep 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.53 KB | None | 0 0
  1. $(document).ready(function(){
  2. $('#custom_images_tab a').click(function(){
  3. if (!(picker = $('#page_image_picker')).data('size-applied')){
  4. wym_box = $('.page_part:first .wym_box');
  5. iframe = $('.page_part:first iframe');
  6. picker.css({
  7. height: wym_box.height()
  8. , width: wym_box.width()
  9. }).data('size-applied', true).corner('tr 5px').corner('bottom 5px').find('.wym_box').css({
  10. backgroundColor: 'white'
  11. , height: iframe.height() + $('.page_part:first .wym_area_top').height() - parseInt($('.wym_area_top .label_inline_with_link a').css('lineHeight'))
  12. , width: iframe.width() - 20
  13. , 'border-color': iframe.css('border-top-color')
  14. , 'border-style': iframe.css('border-top-style')
  15. , 'border-width': iframe.css('border-top-width')
  16. , padding: '0px 10px 0px 10px'
  17. });
  18. }
  19. });
  20.  
  21. // Webkit browsers don't like the textarea being moved around the DOM,
  22. // they ignore the new contents. This is fixed below by adding a hidden
  23. // field that stays in place.
  24. $('#content #page_images li textarea:hidden').each(function(index) {
  25. var old_name = $(this).attr('name');
  26. $(this).attr('data-old-id', $(this).attr('id'));
  27. $(this).attr('name', 'ignore_me_' + index);
  28. $(this).attr('id', 'ignore_me_' + index);
  29.  
  30. var hidden = $('<input>')
  31. .addClass('caption')
  32. .attr('type', 'hidden')
  33. .attr('name', old_name)
  34. .attr('id', $(this).attr('data-old-id'))
  35. .val($(this).val());
  36.  
  37. $(this).parents('li').first().append(hidden);
  38. });
  39.  
  40. reset_functionality();
  41. });
  42.  
  43. reset_functionality = function() {
  44. WYMeditor.onload_functions.push(function(){
  45. $('.wym_box').css({'width':null});
  46. });
  47.  
  48. $("#page_images").sortable({
  49. 'tolerance': 'pointer'
  50. , 'placeholder': 'placeholder'
  51. , 'cursor': 'drag'
  52. , 'items': 'li'
  53. , stop: reindex_images
  54. });
  55.  
  56. $('#content #page_images li:not(.empty)').live('hover', function(e) {
  57. if (e.type == 'mouseenter' || e.type == 'mouseover') {
  58. if ((image_actions = $(this).find('.image_actions')).length == 0) {
  59. image_actions = $("<div class='image_actions'></div>");
  60. img_delete = $("<img src='/images/refinery/icons/delete.png' width='16' height='16' />");
  61. img_delete.appendTo(image_actions);
  62. img_delete.click(function() {
  63. $(this).parents('li').first().remove();
  64. reindex_images();
  65. });
  66.  
  67. if ($(this).find('textarea.page_caption').length > 0) {
  68. img_caption = $("<img src='/images/refinery/icons/user_comment.png' width='16' height='16' class='caption' />");
  69. img_caption.appendTo(image_actions);
  70. img_caption.click(open_image_caption);
  71. } else {
  72. image_actions.addClass('no_captions');
  73. }
  74.  
  75. image_actions.appendTo($(this));
  76. }
  77.  
  78. image_actions.show();
  79. } else if (e.type == 'mouseleave' || e.type == 'mouseout') {
  80. $(this).find('.image_actions').hide();
  81. }
  82. });
  83.  
  84. reindex_images();
  85. }
  86.  
  87. image_added = function(images) {
  88. for (x in images) {
  89. image = images[x]
  90. new_list_item = (current_list_item = $('li.empty')).clone();
  91. image_id = $(image).attr('id').replace('image_', '');
  92. image_field = current_list_item.find('input:hidden:first')
  93. image_field.attr('id', 'listing_images_' + x + '_id');
  94. image_field.attr('name', 'listing[images_attributes][' + x + '][id]');
  95. image_field.val(image_id);
  96.  
  97.  
  98. $("<img />").attr({
  99. title: $(image).attr('title')
  100. , alt: $(image).attr('alt')
  101. , src: $(image).attr('data-grid') // use 'grid' size that is built into Refinery CMS (135x135#c).
  102. }).appendTo(current_list_item);
  103.  
  104. current_list_item.attr('id', 'image_' + image_id).removeClass('empty');
  105.  
  106. new_list_item.appendTo($('#page_images'));
  107. }
  108. reset_functionality();
  109. }
  110.  
  111. open_image_caption = function(e) {
  112. // move the textarea out of the list item, and then move the textarea back into it when we click done.
  113. (list_item = $(this).parents('li').first()).addClass('current_caption_list_item');
  114. textarea = list_item.find('.textarea_wrapper_for_wym > textarea');
  115.  
  116. textarea.after($("<div class='form-actions'><div class='form-actions-left'><a class='button'>"+I18n.t('js.admin.page_images.done')+"</a></div></div>"));
  117. textarea.parent().dialog({
  118. title: I18n.t('js.admin.page_images.add_caption')
  119. , modal: true
  120. , resizable: false
  121. , autoOpen: true
  122. , width: 928
  123. , height: 530
  124. });
  125.  
  126. $('.ui-dialog:visible .ui-dialog-titlebar-close, .ui-dialog:visible .form-actions a.button')
  127. .bind('click',
  128. $.proxy(function(e) {
  129. // first, update the editor because we're blocking event bubbling (third argument to bind set to false).
  130. $(this).data('wymeditor').update();
  131. $(this).removeClass('wymeditor')
  132. .removeClass('active_rotator_wymeditor');
  133.  
  134. $this_parent = $(this).parent();
  135. $this_parent.appendTo('li.current_caption_list_item').dialog('close').data('dialog', null);
  136. $this_parent.find('.form-actions').remove();
  137. $this_parent.find('.wym_box').remove();
  138. $this_parent.css('height', 'auto');
  139. $this_parent.removeClass('ui-dialog-content').removeClass('ui-widget-content');
  140.  
  141. $('li.current_caption_list_item').removeClass('current_caption_list_item');
  142.  
  143. $('.ui-dialog, .ui-widget-overlay:visible').remove();
  144.  
  145. $('#' + $(this).attr('data-old-id')).val($(this).val());
  146. }, textarea)
  147. , false);
  148.  
  149. textarea.addClass('wymeditor active_rotator_wymeditor widest').wymeditor(wymeditor_boot_options);
  150. }
  151.  
  152. reindex_images = function() {
  153. $('#page_images li textarea:hidden').each(function(i, input){
  154. // make the image's name consistent with its position.
  155. parts = $(input).attr('name').split('_');
  156. parts[2] = ('' + i);
  157. $(input).attr('name', parts.join('_'));
  158.  
  159. // make the image's id consistent with its position.
  160. $(input).attr('id', $(input).attr('id').replace(/_\d/, '_' + i));
  161. $(input).attr('data-old-id', $(input).attr('data-old-id').replace(/_\d_/, '_'+i+'_').replace(/_\d/, '_' + i));
  162. });
  163. $('#page_images li').each(function(i, li){
  164. $('input:hidden', li).each(function() {
  165. // make the image's name consistent with its position.
  166. parts = $(this).attr('name').split(']');
  167. parts[1] = ('[' + i);
  168. $(this).attr('name', parts.join(']'));
  169.  
  170. // make the image's id consistent with its position.
  171. $(this).attr('id', $(this).attr('id').replace(/_\d_/, '_'+i+'_').replace(/_\d/, '_'+i));
  172. });
  173. });
  174. }
Add Comment
Please, Sign In to add comment