Elgg  Version 5.1
crop.js
Go to the documentation of this file.
1 define(['jquery', 'jquery-cropper/jquery-cropper'], function($) {
2  function Cropper() {
3  var $field;
4  var $fieldWrapper;
5  var $img;
6  var $imgWrapper;
7  var $inputWrapper;
8  var $messagesWrapper;
9  var that = this;
10 
11  this.init = function(selector) {
12  $field = $(selector);
13  $fieldWrapper = $field.closest('.elgg-field');
14  $imgWrapper = $fieldWrapper.siblings('.elgg-entity-edit-icon-crop-wrapper');
15  $img = $imgWrapper.find('> img').eq(0);
16  $inputWrapper = $fieldWrapper.siblings('.elgg-entity-edit-icon-crop-input').eq(0);
17 
18  $messagesWrapper = $fieldWrapper.siblings('.elgg-entity-edit-icon-crop-messages');
19 
20  // we need to register on document to work in the correct order with change event from input/file.js
21  $(document).on('change', selector, this.replaceImg);
22 
23  var $remove = $fieldWrapper.siblings('.elgg-entity-edit-icon-remove').find('input[type="checkbox"]');
24  $remove.on('change', this.checkRemoveState);
25 
26  if ($img[0].hasAttribute('src')) {
27  this.reload();
28  }
29 
30  $img.on('ready', function() {
31  // enable/disable on tab changes
32  if ($field.not(':visible')) {
33  $field.data('resetNeeded', true);
34  }
35 
36  $field.parents('.elgg-tabs-component').find(' > .elgg-body > .elgg-menu-navigation-tabs-container > ul > li').on('open', function() {
37  if ($field.is(':visible')) {
38  $img.cropper('enable');
39  $img.cropper('resize');
40 
41  if ($field.data('resetNeeded')) {
42  $img.cropper('reset');
43 
44  // only need a reset once
45  $field.data('resetNeeded', false);
46  }
47  } else {
48  $img.cropper('disable');
49  }
50  });
51  });
52  };
53 
54  this.replaceImg = function() {
55  var oFReader = new FileReader();
56  oFReader.readAsDataURL(this.files[0]);
57 
58  // remove previous state
59  $imgWrapper.addClass('hidden');
60  $img.off('crop.iconCropper');
61  $img.cropper('destroy');
62  $img.attr('src', '');
63 
64  var data = $img.data().iconCropper;
65  data.aspectRatio = data.initialAspectRatio;
66 
67  that.resetMessages();
68 
69  // validate image
70  oFReader.onload = function (oFREvent) {
71  var image = new Image();
72  image.src = this.result;
73 
74  image.onload = function(imageEvent) {
75  $img.attr('src', this.src);
76 
77  $inputWrapper.find('input[name="_entity_edit_icon_crop_guid"], input[name="_entity_edit_icon_crop_type"], input[name="_entity_edit_icon_crop_name"]').remove();
78 
79  that.reload({
80  data: {}
81  });
82  };
83  };
84  };
85 
86  this.reload = function(extra_data) {
87  extra_data = extra_data || {};
88 
89  $imgWrapper.removeClass('hidden');
90 
91  var data = $img.data().iconCropper;
92  $.extend(data, extra_data);
93 
94  $img.cropper(data);
95  $img.on('crop.iconCropper', this.crop);
96  };
97 
98  this.crop = function(event) {
99  var cropDetails = $img.cropper('getData', true);
100 
101  that.resetMessages();
102 
103  var minWidth = $messagesWrapper.find('.elgg-entity-edit-icon-crop-error-width').data('minWidth');
104  if (minWidth > 0 && cropDetails.width < minWidth) {
105  that.showMessage('width');
106  }
107 
108  var minHeight = $messagesWrapper.find('.elgg-entity-edit-icon-crop-error-height').data('minHeight');
109  if (minHeight > 0 && cropDetails.height < minHeight) {
110  that.showMessage('height');
111  }
112 
113  $inputWrapper.find('input[name$="x1"]').val(cropDetails.x);
114  $inputWrapper.find('input[name$="y1"]').val(cropDetails.y);
115  $inputWrapper.find('input[name$="x2"]').val(cropDetails.x + cropDetails.width);
116  $inputWrapper.find('input[name$="y2"]').val(cropDetails.y + cropDetails.height);
117  };
118 
119  this.resetMessages = function() {
120  if (!$messagesWrapper.length) {
121  return;
122  }
123 
124  $messagesWrapper.addClass('hidden');
125  $messagesWrapper.find('.elgg-entity-edit-icon-crop-error-generic').addClass('hidden');
126  $messagesWrapper.find('.elgg-entity-edit-icon-crop-error-width').addClass('hidden');
127  $messagesWrapper.find('.elgg-entity-edit-icon-crop-error-height').addClass('hidden');
128  };
129 
130  this.showMessage = function(message_type) {
131  if ($.inArray(message_type, ['width', 'height']) < 0) {
132  return;
133  }
134 
135  if (!$messagesWrapper.length) {
136  return;
137  }
138 
139  $messagesWrapper.removeClass('hidden');
140  $messagesWrapper.find('.elgg-entity-edit-icon-crop-error-generic').removeClass('hidden');
141  $messagesWrapper.find('.elgg-entity-edit-icon-crop-error-' + message_type).removeClass('hidden');
142  };
143 
144  this.show = function() {
145  $fieldWrapper.removeClass('hidden');
146  this.reload();
147  $img.trigger('crop.iconCropper');
148  };
149 
150  this.hide = function() {
151  $fieldWrapper.addClass('hidden');
152  $imgWrapper.addClass('hidden');
153  this.resetMessages();
154  };
155 
156  this.checkRemoveState = function() {
157  if ($(this).is(':checked')) {
158  that.hide();
159  } else {
160  that.show();
161  }
162  };
163  };
164 
165  return Cropper;
166 });
define(['jquery', 'jquery-cropper/jquery-cropper'], function($){function Cropper(){var $field;var $fieldWrapper;var $img;var $imgWrapper;var $inputWrapper;var $messagesWrapper;var that=this;this.init=function(selector){$field=$(selector);$fieldWrapper=$field.closest('.elgg-field');$imgWrapper=$fieldWrapper.siblings('.elgg-entity-edit-icon-crop-wrapper');$img=$imgWrapper.find('> img').eq(0);$inputWrapper=$fieldWrapper.siblings('.elgg-entity-edit-icon-crop-input').eq(0);$messagesWrapper=$fieldWrapper.siblings('.elgg-entity-edit-icon-crop-messages');$(document).on('change', selector, this.replaceImg);var $remove=$fieldWrapper.siblings('.elgg-entity-edit-icon-remove').find('input[type="checkbox"]');$remove.on('change', this.checkRemoveState);if($img[0].hasAttribute('src')){this.reload();}$img.on('ready', function(){if($field.not(':visible')){$field.data('resetNeeded', true);}$field.parents('.elgg-tabs-component').find(' >.elgg-body >.elgg-menu-navigation-tabs-container > ul > li').on('open', function(){if($field.is(':visible')){$img.cropper('enable');$img.cropper('resize');if($field.data('resetNeeded')){$img.cropper('reset');$field.data('resetNeeded', false);}}else{$img.cropper('disable');}});});};this.replaceImg=function(){var oFReader=new FileReader();oFReader.readAsDataURL(this.files[0]);$imgWrapper.addClass('hidden');$img.off('crop.iconCropper');$img.cropper('destroy');$img.attr('src', '');var data=$img.data().iconCropper;data.aspectRatio=data.initialAspectRatio;that.resetMessages();oFReader.onload=function(oFREvent){var image=new Image();image.src=this.result;image.onload=function(imageEvent){$img.attr('src', this.src);$inputWrapper.find('input[name="_entity_edit_icon_crop_guid"], input[name="_entity_edit_icon_crop_type"], input[name="_entity_edit_icon_crop_name"]').remove();that.reload({data:{}});};};};this.reload=function(extra_data){extra_data=extra_data||{};$imgWrapper.removeClass('hidden');var data=$img.data().iconCropper;$.extend(data, extra_data);$img.cropper(data);$img.on('crop.iconCropper', this.crop);};this.crop=function(event){var cropDetails=$img.cropper('getData', true);that.resetMessages();var minWidth=$messagesWrapper.find('.elgg-entity-edit-icon-crop-error-width').data('minWidth');if(minWidth > 0 &&cropDetails.width< minWidth){that.showMessage('width');}var minHeight=$messagesWrapper.find('.elgg-entity-edit-icon-crop-error-height').data('minHeight');if(minHeight > 0 &&cropDetails.height< minHeight){that.showMessage('height');}$inputWrapper.find('input[name $="x1"]').val(cropDetails.x);$inputWrapper.find('input[name $="y1"]').val(cropDetails.y);$inputWrapper.find('input[name $="x2"]').val(cropDetails.x+cropDetails.width);$inputWrapper.find('input[name $="y2"]').val(cropDetails.y+cropDetails.height);};this.resetMessages=function(){if(!$messagesWrapper.length){return;}$messagesWrapper.addClass('hidden');$messagesWrapper.find('.elgg-entity-edit-icon-crop-error-generic').addClass('hidden');$messagesWrapper.find('.elgg-entity-edit-icon-crop-error-width').addClass('hidden');$messagesWrapper.find('.elgg-entity-edit-icon-crop-error-height').addClass('hidden');};this.showMessage=function(message_type){if($.inArray(message_type, ['width', 'height'])< 0){return;}if(!$messagesWrapper.length){return;}$messagesWrapper.removeClass('hidden');$messagesWrapper.find('.elgg-entity-edit-icon-crop-error-generic').removeClass('hidden');$messagesWrapper.find('.elgg-entity-edit-icon-crop-error-'+message_type).removeClass('hidden');};this.show=function(){$fieldWrapper.removeClass('hidden');this.reload();$img.trigger('crop.iconCropper');};this.hide=function(){$fieldWrapper.addClass('hidden');$imgWrapper.addClass('hidden');this.resetMessages();};this.checkRemoveState=function(){if($(this).is(':checked')){that.hide();}else{that.show();}};};return Cropper;})
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition files
Definition: LICENSE.txt:210
if(elgg_extract('required', $vars)) if(elgg_extract('disabled', $vars)) $field
Definition: field.php:38
Bundled plugins(the contents of the"/mod"directory) are available only under the GPLv2 license.The remainder of the project is available under either MIT or GPLv2.Both licenses can be found below.More info and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed on
Definition: LICENSE.txt:96
if($entity instanceof ElggEntity &&$entity->hasIcon('master', $icon_type)) if(isset($cropper_data['existingAspectRatio'], $cropper_data['aspectRatio'])) $img
Definition: crop.php:129