modal.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <style>
  2. .img-container img {
  3. max-width: 100%;
  4. }
  5. #container_image {max-width: 100%;}
  6. </style>
  7. <div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true" data-backdrop="static">
  8. <div class="modal-dialog modal-lg" role="document">
  9. <div class="modal-content">
  10. <div class="modal-header">
  11. <h5 class="modal-title" id="modalLabel">Фото в заголовок</h5>
  12. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  13. <span aria-hidden="true">&times;</span>
  14. </button>
  15. </div>
  16. <div class="modal-body">
  17. <div class="img-container">
  18. <img id="container_image" src="/img/e.gif">
  19. </div>
  20. </div>
  21. <div class="modal-footer justify-content-between">
  22. <div class="btn-toolbar" role="toolbar" aria-label="Панель инструментов с группами кнопок">
  23. <div class="btn-group mr-2">
  24. <button type="button" class="btn btn-primary" onClick="cropper.zoom(0.1);" disabled>
  25. <span class="docs-tooltip" title="cropper.zoom(0.1)">
  26. <span class="fa fa-search-plus"></span>
  27. </span>
  28. </button>
  29. <button type="button" class="btn btn-primary" onClick="cropper.zoom(-0.1);" disabled>
  30. <span class="docs-tooltip">
  31. <span class="fa fa-search-minus"></span>
  32. </span>
  33. </button>
  34. </div>
  35. <div class="btn-group mr-2">
  36. <button type="button" class="btn btn-primary" onClick="cropper.scaleX(-1)" disabled>
  37. <span class="docs-tooltip" >
  38. <span class="fa fa-arrows-alt-h"></span>
  39. </span>
  40. </button>
  41. <button type="button" class="btn btn-primary" onClick="cropper.scaleY(-1)" disabled>
  42. <span class="docs-tooltip">
  43. <span class="fa fa-arrows-alt-v"></span>
  44. </span>
  45. </button>
  46. </div>
  47. <div class="btn-group mr-2">
  48. <button type="button" class="btn btn-primary" onClick="cropper.rotate(-45)" disabled>
  49. <span class="docs-tooltip">
  50. <span class="fa fa-undo-alt"></span>
  51. </span>
  52. </button>
  53. <button type="button" class="btn btn-primary" onClick="cropper.rotate(45)" disabled>
  54. <span class="docs-tooltip">
  55. <span class="fa fa-redo-alt"></span>
  56. </span>
  57. </button>
  58. </div>
  59. <div class="btn-group mr-2">
  60. <div class="dropdown">
  61. <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" id="dropdownMenuButton">
  62. <span class="docs-tooltip"><span class="fa fa-image"></span></span>
  63. </button>
  64. <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
  65. <a class="dropdown-item" href="javascript:void(0)" onClick="defphoto('/images/d2.jpg')">Хз что случилось</a>
  66. <a class="dropdown-item" href="javascript:void(0)" onClick="defphoto('/images/d1.jpg')">Внимание</a>
  67. <a class="dropdown-item" href="javascript:void(0)" onClick="defphoto('/images/default.jpg')">Всё пропало</a>
  68. </div>
  69. </div>
  70. </div>
  71. <div class="btn-group mr-2">
  72. <button type="button" class="btn btn-primary" onClick="cropper.reset()">
  73. <span class="docs-tooltip">
  74. <span class="fa fa-sync-alt"></span>
  75. </span>
  76. </button>
  77. <span class="btn btn-primary btn-upload" for="inputImage" title="Upload image file">
  78. <input type="file" class="sr-only" id="inputImage" name="<?=$this->context->file?>" accept="image/*" index="1">
  79. <span class="docs-tooltip" title="загрузить" onClick="$('#inputImage').click();">
  80. <span class="fa fa-upload"></span>
  81. </span>
  82. </span>
  83. </div>
  84. </div>
  85. <div class="btn-toolbar">
  86. <button type="button" class="btn btn-secondary mr-3" data-dismiss="modal">Close</button>
  87. <button type="button" class="btn btn-primary" onClick="phsave(this)" >Сохранить изменения</button>
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. <input type="hidden" id="news-photo-x" name="<?=$this->context->post?>[x]" value="">
  94. <input type="hidden" id="news-photo-y" name="<?=$this->context->post?>[y]" value="">
  95. <input type="hidden" id="news-photo-width" name="<?=$this->context->post?>[width]" value="">
  96. <input type="hidden" id="news-photo-height" name="<?=$this->context->post?>[height]" value="">
  97. <input type="hidden" id="news-photo-url" name="<?=$this->context->post?>[url]" value="">
  98. <script>
  99. var cropper;
  100. window.addEventListener('DOMContentLoaded', function () {
  101. var image = document.getElementById('container_image');
  102. var cropBoxData;
  103. var canvasData;
  104. $('#modal').on('shown.bs.modal', function () {
  105. cropper = new Cropper(image, {
  106. autoCropArea: 1,
  107. viewMode:1,
  108. modal:true,
  109. aspectRatio: <?=$this->context->aspectRatio?>,
  110. zoomOnWheel: true,
  111. guides: true,
  112. center: true,
  113. ready: function () {
  114. //Should set crop box data first here
  115. cropper.setCropBoxData(cropBoxData).setCanvasData(canvasData);
  116. }
  117. });
  118. //$(document).ready(function(){setTimeout( function(){document.getElementById("inputImage").click()}, 1000 )});
  119. }).on('hidden.bs.modal', function () {
  120. cropBoxData = cropper.getCropBoxData();
  121. canvasData = cropper.getCanvasData();
  122. cropper.destroy();
  123. });
  124. });
  125. function phsave( obj ){
  126. console.log(cropper.getData());
  127. var data = cropper.getData();
  128. $("#news-photo-x").val(data.x);
  129. $("#news-photo-y").val(data.y);
  130. $("#news-photo-width").val(data.width);
  131. $("#news-photo-height").val(data.height);
  132. $("#news-photo-url").val(window.urlimg);
  133. // $("#image").src = uploadedImageURL;
  134. // console.log(uploadedImageURL);
  135. // $("#image").canvas = cropper.getCroppedCanvas();
  136. var $pcimg = $('#<?=$this->context->image?>');
  137. croppedImage = cropper.getCroppedCanvas();
  138. croppedImage.toBlob(function(blob) {
  139. var newImg = document.createElement('img'),
  140. url = URL.createObjectURL(blob);
  141. $(newImg).attr('id','himg');
  142. newImg.onload = function() {
  143. URL.revokeObjectURL(url);
  144. };
  145. newImg.src = url;
  146. $pcimg.prop('src', url).show();
  147. }, 'image/jpeg', 0.95);
  148. $('#modal').modal('hide');
  149. }
  150. // Import image
  151. var inputImage = document.getElementById('inputImage');
  152. var uploadedImageType = 'image/jpeg';
  153. var uploadedImageName = 'cropped.jpg';
  154. var uploadedImageURL;
  155. var container = document.querySelector('.img-container');
  156. var image = container.getElementsByTagName('img').item(0);
  157. var originalImageURL = image.src;
  158. var URL = window.URL || window.webkitURL;
  159. if (URL) {
  160. $("#inputImage").on('change', function (e) {
  161. var files = this.files;
  162. var file;
  163. //console.log(this);
  164. if (files && files.length) {
  165. file = files[0];
  166. if (/^image\/\w+/.test(file.type)) {
  167. uploadedImageType = file.type;
  168. uploadedImageName = file.name;
  169. if (uploadedImageURL) {
  170. URL.revokeObjectURL(uploadedImageURL);
  171. }
  172. image.src = uploadedImageURL = URL.createObjectURL(file);
  173. var o = cropper.options;
  174. if (cropper) {
  175. cropper.destroy();
  176. }
  177. cropper = new Cropper(image, o);
  178. //inputImage.value = null;
  179. } else {
  180. window.alert('Please choose an image file.');
  181. }
  182. }
  183. });
  184. } else {
  185. inputImage.disabled = true;
  186. inputImage.parentNode.className += ' disabled';
  187. }
  188. function defphoto(urlimg){
  189. cropper.replace(urlimg,false);
  190. window.urlimg = urlimg;
  191. cropper.reset();
  192. }
  193. </script>
  194. <?