Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-wieschollek committed Jul 4, 2018
1 parent 01d2194 commit 5d9a732
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/js/Manager/SearchManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class SearchManager {
document.querySelector('form.searchbox').style.opacity = '1';
document.getElementById('searchbox').value = '';
this._status.available = true;
setTimeout(() => {this.search(this._status.query)}, 1);
setTimeout(() => {this.search(this._status.query);}, 1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/Manager/SettingsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class SettingsManager {
if(!this._observers.hasOwnProperty(setting)) return;

for(let i = 0; i < this._observers[setting].length; i++) {
this._observers[setting][i]({setting,value});
this._observers[setting][i]({setting, value});
}
}
}
Expand Down
46 changes: 30 additions & 16 deletions src/lib/Helper/Favicon/FaviconGrabberHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,41 @@ protected function analyzeApiResponse(array $json, string $domain): ?string {
$iconData = null;
$sizeOffset = null;
foreach($json['icons'] as $icon) {
$info = pathinfo($icon['src']);
if(!isset($info['extension'])) continue;
$ext = $info['extension'];
if(!in_array($ext, ['png', 'ico', 'gif', 'jpg', 'jpeg'])) continue;

if($iconData === null) {
$iconData = $this->loadIcon($icon['src']);
} else if(isset($icon['sizes'])) {
$size = explode('x', $icon['sizes'])[0];
if(!is_numeric($size)) continue;
$offset = abs(256 - $size);
if($offset < $sizeOffset || $sizeOffset === null) {
$sizeOffset = $offset;
$iconData = $this->loadIcon($icon['src'], $iconData);
}
}
list($iconData, $sizeOffset) = $this->analyzeApiIcon($icon, $iconData, $sizeOffset);
}

return $iconData;
}

/**
* @param $icon
* @param $iconData
* @param $sizeOffset
*
* @return array
*/
protected function analyzeApiIcon($icon, $iconData, $sizeOffset): array {
$info = pathinfo($icon['src']);
if(!isset($info['extension'])) return [$iconData, $sizeOffset];
$ext = $info['extension'];
if(!in_array($ext, ['png', 'ico', 'gif', 'jpg', 'jpeg'])) return [$iconData, $sizeOffset];

if($iconData === null) {
$iconData = $this->loadIcon($icon['src']);
} else if(isset($icon['sizes'])) {
$size = explode('x', $icon['sizes'])[0];
if(!is_numeric($size)) return [$iconData, $sizeOffset];

$offset = abs(256 - $size);
if($offset < $sizeOffset || $sizeOffset === null) {
$sizeOffset = $offset;
$iconData = $this->loadIcon($icon['src'], $iconData);
}
}

return [$iconData, $sizeOffset];
}

/**
* @param string $url
* @param string|null $data
Expand Down
2 changes: 1 addition & 1 deletion tests/codecept/steps/steps.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {crop, thumbnail} = require('easyimage');

function gEP(e) {let $e=$(e);$e[0].scrollIntoView(false);let d=$e.offset();d.width=$e.width();d.height=$e.height();return JSON.stringify(d);}
let window = {width:1280,height:874};
let window = {width:1280, height:874};

module.exports = function() {
return actor(
Expand Down

0 comments on commit 5d9a732

Please sign in to comment.