PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/system/cms/modules/wysiwyg/js/wysiwyg.js

https://gitlab.com/Riky_Lesmana/SugarSweetCakes
JavaScript | 205 lines | 144 code | 39 blank | 22 comment | 17 complexity | f2a34a9ee2d77f092bd7eaa1744c314c MD5 | raw file
  1. var CKEDITOR = window.parent.CKEDITOR;
  2. var img_float;
  3. function insertImage(file, alt, location, path)
  4. {
  5. if(replace_html)
  6. {
  7. replace_html.remove();
  8. }
  9. var img_width = document.getElementById('insert_width').value;
  10. img_width = ! isNaN(img_width) ? img_width : 0;
  11. if (location == 'local') {
  12. path = '{{ url:site }}files/' + (img_width > 0 ? 'thumb/' + file + '/' + img_width : 'large/' + file);
  13. }
  14. // don't display a width="0" tag
  15. var width_tag = (img_width > 0 ? 'width="'+img_width+'"' : '');
  16. var img_float = $('input[name=insert_float]:checked').val();
  17. var float_tag = (img_float !== 'none' ? 'style="float:'+img_float+'"' : '');
  18. window.parent.instance.insertHtml('<img class="pyro-image alignment-'+img_float+'" '+width_tag+' '+float_tag+' src="'+path+'" alt="' + alt + '" />');
  19. windowClose();
  20. }
  21. function insertFile(id, title, location, path)
  22. {
  23. if (location == 'local') {
  24. var path = '{{ url:site }}files/download/' + id;
  25. }
  26. if(replace_html)
  27. {
  28. replace_html.remove();
  29. }
  30. window.parent.instance.insertHtml('<a class="pyro-file" href="'+path+'">' + title + '</a>');
  31. windowClose();
  32. }
  33. // By default, insert (which will also replace)
  34. var replace_html = null;
  35. $(function()
  36. {
  37. function detectFile()
  38. {
  39. // Get whatever is selected
  40. selection = window.parent.instance.getSelection();
  41. // A Tag has been fuly selected
  42. if(selection.getSelectedElement())
  43. {
  44. element = jQuery( selection.getSelectedElement().$ );
  45. }
  46. // If the cursor is anywhere in the textbox
  47. else(selection.getRanges()[ 0 ])
  48. {
  49. // Find the range of the selection
  50. range = selection.getRanges()[ 0 ];
  51. range.shrink( CKEDITOR.SHRINK_TEXT );
  52. // Have they clicked inside an <img> tag?
  53. maybe_element = range.getCommonAncestor().getAscendant( 'img', true );
  54. if(!maybe_element) return false;
  55. else element = jQuery(maybe_element.$);
  56. // Save this HTML to be replaced up update
  57. replace_html = maybe_element;
  58. }
  59. if( ! element.hasClass('pyro-image')) return false;
  60. $('#current_document').load(SITE_URL + 'admin/wysiwyg/files/ajax_get_file', {
  61. doc_id: element.attr('href').match(/\/download\/([0-9]+)/)[1]
  62. });
  63. return true;
  64. }
  65. detectFile() || $('#current_document h2').hide();
  66. //tooltip
  67. $('#images-container img').hover( function() {
  68. $(this).attr('title', 'Click to insert image');
  69. });
  70. /**
  71. * left files navigation handler
  72. * - handles loading of different folders
  73. * - manipulates dom classes etc
  74. */
  75. $('#files-nav li a').live('click', function(e) {
  76. e.preventDefault();
  77. var href_val = $(this).attr('href');
  78. //remove existing 'current' classes
  79. $('#files-nav li').removeClass('current');
  80. //add class to click anchor parent
  81. $(this).parent('li').addClass('current');
  82. //remove any notifications
  83. $( 'div.notification' ).fadeOut('fast');
  84. if ($(this).attr('title') != 'upload')
  85. {
  86. $('#files_right_pane').load(href_val + ' #files-wrapper', function() {
  87. $(this).children().fadeIn('slow');
  88. });
  89. }
  90. else
  91. {
  92. var box = $('#upload-box');
  93. if (box.is( ":visible" ))
  94. {
  95. // Hide - slide up.
  96. box.fadeOut( 200 );
  97. }
  98. else
  99. {
  100. // Show - slide down.
  101. box.fadeIn( 200 );
  102. }
  103. }
  104. });
  105. $( '#upload-box span.close, #upload-box a.cancel' ).on('click', function(e) {
  106. e.preventDefault();
  107. $( '#upload-box' ).fadeOut( 200, function() {
  108. $(this).find('input[type=text], input[type=file]').val('');
  109. });
  110. });
  111. $('select[name=parent_id]').live('change', function() {
  112. var folder_id = $(this).val();
  113. var controller = $(this).attr('title');
  114. var href_val = SITE_URL + 'admin/wysiwyg/' + controller + '/index/' + folder_id;
  115. $('#files_right_pane').load(href_val + ' #files-wrapper', function() {
  116. $(this).children().fadeIn('slow');
  117. var class_exists = $('#folder-id-' + folder_id).html();
  118. $( 'div.notification' ).fadeOut('fast');
  119. if(class_exists !== null)
  120. {
  121. $('#files-nav li').removeClass('current');
  122. $('li#folder-id-'+folder_id).addClass('current');
  123. }
  124. });
  125. })
  126. //slider
  127. $('#slider').livequery(function() {
  128. $(this).fadeIn('slow');
  129. $(this).slider({
  130. value: 0,
  131. min: 0,
  132. max: 1000,
  133. step: 1,
  134. slide: function( event, ui ) {
  135. if (ui.value > 0) {
  136. $('#insert_width').val(ui.value);
  137. } else {
  138. $('#insert_width').val( $('#insert_width').attr('data-name') );
  139. }
  140. }
  141. });
  142. $('#insert_width').val( $('#insert_width').attr('data-name') );
  143. });
  144. $('#radio-group').livequery(function(){
  145. $(this).children('.set').buttonset();
  146. $(this).fadeIn('slow');
  147. });
  148. $( '#files_right_pane' ).livequery(function() {
  149. $(this).children().fadeIn('slow');
  150. $('#upload-box').hide();
  151. });
  152. // Add the close link to all alert boxes
  153. $('.alert').livequery(function(){
  154. $(this).prepend('<a href="#" class="close">x</a>');
  155. });
  156. // Close the notifications when the close link is clicked
  157. $('a.close').live('click', function(e){
  158. e.preventDefault();
  159. $(this).fadeTo(200, 0); // This is a hack so that the close link fades out in IE
  160. $(this).parent().fadeTo(200, 0);
  161. $(this).parent().slideUp(400, function(){
  162. $(window).trigger('notification-closed');
  163. $(this).remove();
  164. });
  165. });
  166. });