Skip to content

Commit 10ef597

Browse files
committed
Releasing 1.0.21
2 parents 1714695 + f6e199f commit 10ef597

File tree

9 files changed

+53
-146
lines changed

9 files changed

+53
-146
lines changed

css/cropper/cropper-ui.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.cropper-actions {
22
margin-top: 0.5em;
3-
text-align: center;
3+
margin-left: 20px;
44
}
55

66
.cropper-actions label {
@@ -9,6 +9,7 @@
99

1010
.cropper-actions .btn-group {
1111
padding-right: 0.5em;
12+
margin-bottom: 0.5em;
1213
}
1314

1415
.cropper-nav {

js/cropper/cropper-ui.js

Lines changed: 7 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,4 @@
11

2-
// Methods
3-
/*
4-
case 'getCroppedCanvas':
5-
try {
6-
data.option = JSON.parse(data.option);
7-
} catch (e) {
8-
console.log(e.message);
9-
}
10-
11-
if (image.data('uploadedImageType') === 'image/jpeg') {
12-
if (!data.option) {
13-
data.option = {};
14-
}
15-
16-
data.option.fillColor = '#fff';
17-
}
18-
19-
break;
20-
}
21-
22-
result = cropper[data.method](data.option, data.secondOption);
23-
24-
switch (data.method) {
25-
case 'getCroppedCanvas':
26-
if (result) {
27-
// Bootstrap's Modal
28-
$('#getCroppedCanvasModal').modal().find('.modal-body').html(result);
29-
30-
if (!download.disabled) {
31-
download.download = image.data('uploadedImageName');
32-
download.href = result.toDataURL(image.data('uploadedImageType'));
33-
}
34-
}
35-
36-
break;
37-
38-
case 'destroy':
39-
cropper = null;
40-
41-
if (image.data('uploadedImageURL')) {
42-
URL.revokeObjectURL(image.data('uploadedImageURL'));
43-
image.data('uploadedImageURL', '');
44-
image.attr('src') = image.data('originalImageURL');
45-
}
46-
47-
break;
48-
}
49-
50-
if (typeof result === 'object' && result !== cropper && input) {
51-
try {
52-
input.value = JSON.stringify(result);
53-
} catch (e) {
54-
console.log(e.message);
55-
}
56-
}
57-
}
58-
});
59-
60-
jQuery('.cropper .docs-toggles').on('change', function() {
61-
var e = event || window.event;
62-
var target = e.target || e.srcElement;
63-
var cropBoxData;
64-
var canvasData;
65-
var isCheckbox;
66-
var isRadio;
67-
68-
if (target.tagName.toLowerCase() === 'label') {
69-
target = target.querySelector('input');
70-
}
71-
72-
isCheckbox = target.type === 'checkbox';
73-
isRadio = target.type === 'radio';
74-
75-
if (isCheckbox || isRadio) {
76-
if (isCheckbox) {
77-
options[target.name] = target.checked;
78-
cropBoxData = cropper.getCropBoxData();
79-
canvasData = cropper.getCanvasData();
80-
81-
options.ready = function () {
82-
console.log('ready');
83-
cropper.setCropBoxData(cropBoxData).setCanvasData(canvasData);
84-
};
85-
} else {
86-
options[target.name] = target.value;
87-
options.ready = function () {
88-
console.log('ready');
89-
};
90-
}
91-
92-
// Restart
93-
cropper.destroy();
94-
cropper = new Cropper(image, options);
95-
}
96-
}
97-
);
98-
*/
99-
1002
jQuery('.cropper input[type="file"]').on('change', function() {
1013
var files = this.files;
1024
var file;
@@ -245,7 +147,8 @@ class CropperUI {
245147
var elem = jQuery(domElement);
246148
options.destroyed = false;
247149
if (!cropperOptions) cropperOptions = {};
248-
cropperOptions.aspectRatio= 1;
150+
var mainElem = elem.closest('.cropper');
151+
cropperOptions.aspectRatio = mainElem.data('aspect-ratio');
249152
options.cropper = new Cropper(domElement, cropperOptions);
250153
elem.data('upload', options);
251154
this.registerEvents(domElement);
@@ -615,7 +518,11 @@ class SaveImageAjaxController extends WebAppDefaultAjaxController {
615518
};
616519
cropperUI.destroy(this.domElement);
617520
var image = cropperUI.getImage(this.domElement);
618-
cropperUI.createCropper(image[0], options);
521+
image[0].src = data.data.path;
522+
var cropperOptions = {
523+
autoCrop: false,
524+
};
525+
cropperUI.createCropper(image[0], options, cropperOptions);
619526
}
620527
} else {
621528
this.showError();

src/WebApp/BootstrapTheme/DefaultLayout.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,31 @@ protected function getBootstrapUri() {
2121

2222
protected function renderLinks() {
2323
$webroot = $this->app->request->webRoot;
24-
$rc = '<link rel="stylesheet" href="'.$webroot.FontAwesome::getUri().'" rel="stylesheet" type="text/css">'.
25-
'<link rel="stylesheet" href="'.$this->getBootstrapUri().'" rel="stylesheet" type="text/css">';
24+
$rc = '<link rel="stylesheet" href="'.$webroot.FontAwesome::getUri().'" type="text/css">'.
25+
'<link rel="stylesheet" href="'.$this->getBootstrapUri().'" type="text/css">';
2626
if ($this->theme->hasFeature(BootstrapTheme::DATEPICKER)) {
27-
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('bootstrap-datepicker.min.css', TRUE).'" rel="stylesheet" type="text/css">';
27+
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('bootstrap-datepicker.min.css', TRUE).'" type="text/css">';
2828
}
2929
if ($this->theme->hasFeature(BootstrapTheme::MULTISELECT)) {
30-
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('filter-multi-select.css', TRUE).'" rel="stylesheet" type="text/css">';
30+
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('filter-multi-select.css', TRUE).'" type="text/css">';
3131
}
3232
if ($this->theme->hasFeature(BootstrapTheme::FILEUPLOAD)) {
33-
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('bootstrap-datepicker.min.css', TRUE).'" rel="stylesheet" type="text/css">';
33+
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('bootstrap-datepicker.min.css', TRUE).'" type="text/css">';
3434
}
3535
if ($this->theme->hasFeature(BootstrapTheme::MULTIIMAGEUPLOAD) || $this->theme->hasFeature(BootstrapTheme::IMAGEUPLOAD)) {
36-
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('multi-image-upload.css', TRUE).'" rel="stylesheet" type="text/css">';
36+
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('multi-image-upload.css', TRUE).'" type="text/css">';
3737
}
3838
if ($this->theme->hasFeature(BootstrapTheme::REMOTESEARCH)) {
39-
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('remote-search.css', TRUE).'" rel="stylesheet" type="text/css">';
39+
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('remote-search.css', TRUE).'" type="text/css">';
4040
}
4141
if ($this->theme->hasFeature(BootstrapTheme::DYNAMICFIELDS)) {
42-
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('dynamic-fields.css', TRUE).'" rel="stylesheet" type="text/css">';
42+
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('dynamic-fields.css', TRUE).'" type="text/css">';
4343
}
4444
if ($this->theme->hasFeature(BootstrapTheme::CROPPERJS)) {
45-
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('cropper/cropper.min.css', TRUE).'" rel="stylesheet" type="text/css">';
46-
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('cropper/cropper-ui.css', TRUE).'" rel="stylesheet" type="text/css">';
45+
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('cropper/cropper.min.css', TRUE).'" type="text/css">';
46+
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('cropper/cropper-ui.css', TRUE).'" type="text/css">';
4747
}
48-
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('bootstrap.css', TRUE).'" rel="stylesheet" type="text/css">';
48+
$rc .= '<link rel="stylesheet" href="'.Utils::getCssPath('bootstrap.css', TRUE).'" type="text/css">';
4949
$rc .= parent::renderLinks();
5050
return $rc;
5151
}
@@ -92,7 +92,7 @@ protected function renderNavbarBrand() {
9292
}
9393

9494
protected function renderNavbarToggler() {
95-
$rc = '<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-content" aria-controls="navbarContent" aria-expanded="false" aria-label="'.I18N::_('navbar_toggle_label').'"><span class="navbar-toggler-icon"></span></button>';
95+
$rc = '<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-content" aria-controls="navbar-content" aria-expanded="false" aria-label="'.I18N::_('navbar_toggle_label').'"><span class="navbar-toggler-icon"></span></button>';
9696
return $rc;
9797
}
9898

@@ -136,7 +136,7 @@ protected function renderNavbarContent() {
136136
$rc .= '</ul>';
137137
}
138138

139-
$rc .= '</nav>';
139+
$rc .= '</div>';
140140
return $rc;
141141
}
142142

src/WebApp/BootstrapTheme/MenuItemRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function render() {
1717
$target = $this->component->getLinkTarget() != NULL ? ' target="'.$this->component->getLinkTarget().'"' : '';
1818
if ($this->component->hasChildren()) {
1919
$rc .= '<a class="nav-link dropdown-toggle" href="'.$link.'" id="dropDown-'.$this->component->getId().'"'.$target.' role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'.$this->component->getLabel().'</a>'.
20-
'<div class="dropdown-menu bg-dark" aria-labelledby=""dropDown-'.$this->component->getId().'">';
20+
'<div class="dropdown-menu bg-dark" aria-labelledby="dropDown-'.$this->component->getId().'">';
2121
foreach ($this->component->getChildren() AS $child) {
2222
switch(get_class($child)) {
2323
case 'WebApp\Component\MenuItem':

src/WebApp/BootstrapTheme/NewImageUploadRenderer.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ class NewImageUploadRenderer extends \WebApp\DefaultTheme\DivRenderer {
88

99
public function __construct($theme, $component) {
1010
parent::__construct($theme, $component);
11-
$this->addClass('cropper');
11+
$this->addClass('cropper')
12+
->setData('width', $component->getWidth())
13+
->setData('height', $component->getHeight())
14+
->setData('aspect-ratio', $component->getAspectRatio());
1215
$this->theme->addFeature(\WebApp\BootstrapTheme\BootstrapTheme::CROPPERJS);
1316
}
1417

@@ -41,11 +44,13 @@ public function renderEditor() {
4144
$did = $id;
4245
break;
4346
}
44-
$rc = '<div class="cropper-editor" style="max-width: 400px; max-height: 400px; margin: 20px;">'.
45-
'<img data-imgid="'.$did.'" class="cropper-image" style="background-image: url(\'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAAA3NCSVQICAjb4U/gAAAABlBMVEXMzMz////TjRV2AAAACXBIWXMAAArrAAAK6wGCiw1aAAAAHHRFWHRTb2Z0d2FyZQBBZG9iZSBGaXJld29ya3MgQ1M26LyyjAAAABFJREFUCJlj+M/AgBVhF/0PAH6/D/HkDxOGAAAAAElFTkSuQmCC\'); width: 400px; height: 400px;" src="'.$src.'">'.
46-
$this->renderActions().
47+
$width = $this->component->getWidth();
48+
$height = $this->component->getHeight();
49+
$rc = '<div class="cropper-editor" style="max-width: '.$width.'px; max-height: '.$height.'px; margin: 20px;">'.
50+
'<img data-imgid="'.$did.'" class="cropper-image" style="background-image: url(\'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAAA3NCSVQICAjb4U/gAAAABlBMVEXMzMz////TjRV2AAAACXBIWXMAAArrAAAK6wGCiw1aAAAAHHRFWHRTb2Z0d2FyZQBBZG9iZSBGaXJld29ya3MgQ1M26LyyjAAAABFJREFUCJlj+M/AgBVhF/0PAH6/D/HkDxOGAAAAAElFTkSuQmCC\'); width: '.$width.'px; height: '.$height.'px;" src="'.$src.'">'.
4751
//$this->renderDocToggles().
48-
'</div>';
52+
'</div>'.
53+
$this->renderActions();
4954
return $rc;
5055
}
5156

src/WebApp/Component/NewImageUpload.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,19 @@ public function getImages() {
3232
return $this->config->images;
3333
}
3434

35-
36-
/*
37-
public static function isImageRemoved($name) {
38-
$ind = intval(\TgUtils\Request::getRequest()->getPostParam('iu-remove-'.$name, 0)) == 1;
39-
$newFile = isset($_FILES['iu-'.$name]) && ($_FILES['iu-'.$name]['error'] == 0);
40-
return $newFile || $ind;
41-
}
42-
43-
public static function getImage($name) {
44-
return FileInput::getFile('iu-'.$name);
45-
}
46-
47-
public static function handleImageUpload($name, $targetDir) {
48-
$rc = FileInput::handleFileUpload('iu-'.$name, $targetDir);
49-
if (($rc != NULL) && ($rc['filename'] != NULL)) {
50-
$info = getimagesize($targetDir.'/'.$rc['filename']);
51-
$rc['mime'] = $info['mime'];
52-
$rc['width'] = $info[0];
53-
$rc['height'] = $info[1];
54-
$rc['ratio'] = $info[0] / $info[1];
35+
public function getWidth() {
36+
return $this->config->width;
37+
}
38+
39+
public function getHeight() {
40+
return $this->config->height;
41+
}
42+
43+
public function getAspectRatio() {
44+
if (!isset($this->config->aspectRatio)) {
45+
$this->config->aspectRatio = round($this->config->width / $this->config->height, 2);
5546
}
56-
return $rc;
47+
return $this->config->aspectRatio;
5748
}
58-
*/
5949
}
6050

src/WebApp/DefaultTheme/DefaultLayout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public function __construct($theme, $page) {
1010
}
1111

1212
protected function renderLinks() {
13-
$rc = '<link rel="stylesheet" href="'.\WebApp\Utils::getCssBaseUrl().'/app.css" rel="stylesheet" type="text/css">'.
14-
'<link rel="stylesheet" href="'.\TgFontAwesome\FontAwesome::getUri().'" rel="stylesheet" type="text/css">';
13+
$rc = '<link rel="stylesheet" href="'.\WebApp\Utils::getCssBaseUrl().'/app.css" type="text/css">'.
14+
'<link rel="stylesheet" href="'.\TgFontAwesome\FontAwesome::getUri().'" type="text/css">';
1515
$rc .= parent::renderLinks();
1616
return $rc;
1717
}

src/WebApp/Layout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ protected function renderLinks() {
8080
if (!is_array($files)) $files = array($files);
8181
foreach ($files AS $file) {
8282
//if (strpos($file, '://') === FALSE) {
83-
// $rc .= '<link rel="stylesheet" href="'.Utils::getCssBaseUrl().'/'.$file.'" rel="stylesheet" type="text/css">';
83+
// $rc .= '<link rel="stylesheet" href="'.Utils::getCssBaseUrl().'/'.$file.'" type="text/css">';
8484
//} else {
85-
$rc .= '<link rel="stylesheet" href="'.$file.'" rel="stylesheet" type="text/css">';
85+
$rc .= '<link rel="stylesheet" href="'.$file.'" type="text/css">';
8686
//}
8787
}
8888
return $rc;

src/WebApp/Renderer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function getClass() {
3131

3232
public function addClass($class) {
3333
$this->addAttribute('class', $class);
34+
return $this;
3435
}
3536

3637
public function removeClass($class) {
@@ -54,6 +55,7 @@ public function setStyle($name, $value) {
5455
} else {
5556
unset($this->styles[$name]);
5657
}
58+
return $this;
5759
}
5860

5961
protected function getAttribute($name, $combined = FALSE) {
@@ -112,6 +114,7 @@ public function addAttribute($name, $value) {
112114
if (!isset($this->attributes[$name])) $this->attributes[$name] = array();
113115
$this->attributes[$name][] = $value;
114116
}
117+
return $this;
115118
}
116119

117120
public function setAttribute($name, $value) {
@@ -120,6 +123,7 @@ public function setAttribute($name, $value) {
120123
} else {
121124
unset($this->attributes[$name]);
122125
}
126+
return $this;
123127
}
124128

125129
public function removeAttribute($name, $value) {

0 commit comments

Comments
 (0)