Skip to content

Commit f836680

Browse files
committed
Add option to override font size
Also disable auto title fitting and bump to version 1.1.0.
1 parent 8c8d1d3 commit f836680

File tree

13 files changed

+93
-35
lines changed

13 files changed

+93
-35
lines changed

Admin/Controller/Tile.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ public function actionIndex()
1919

2020
protected function tileAddEdit(\Inforge\GridShow\Entity\Tile $tile)
2121
{
22+
$overrideFontSize = 'override';
23+
if ($tile->font_size === null || $tile->font_size === '')
24+
$overrideFontSize = 'use_default';
2225
$viewParams = [
23-
'tile' => $tile
26+
'tile' => $tile,
27+
'override_font_size' => $overrideFontSize
2428
];
2529
return $this->view('Inforge\GridShow:Tile\Edit', 'if_gs_tile_edit', $viewParams);
2630
}
@@ -75,6 +79,7 @@ protected function tileSaveProcess(\Inforge\GridShow\Entity\Tile $tile)
7579
'category' => 'str',
7680
'link' => 'str',
7781
'image_url' => 'str',
82+
'font_size' => 'str',
7883
'display_order' => 'uint',
7984
'active' => 'bool'
8085
]);

Entity/Tile.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public static function getStructure(Structure $structure)
4343
'active' => [
4444
'type' => self::BOOL,
4545
'default' => true
46+
],
47+
'font_size' => [
48+
'type' => self::STR,
49+
'maxLength' => 10,
50+
'required' => false
4651
]
4752
];
4853

@@ -68,6 +73,19 @@ protected function verifyLink($link)
6873
return false;
6974
}
7075

76+
protected function verifyFontSize($fontSize)
77+
{
78+
if ($fontSize === null || $fontSize === '')
79+
return true;
80+
if (preg_match(
81+
'/^[ \t]*[0-9]*\.*[0-9]+(cm|mm|in|px|pt|pc|em|ex|ch|rem|vh|vw|vim|vmax|\%)[ \t]*$/',
82+
$fontSize) !== 1) {
83+
$this->error(\XF::phrase('if_gs_please_enter_valid_font_size_with_unit'));
84+
return false;
85+
}
86+
return true;
87+
}
88+
7189
protected function getTileRepo()
7290
{
7391
return $this->repository('Inforge\GridShow:Tile');

Setup.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use XF\AddOn\StepRunnerUninstallTrait;
88
use XF\AddOn\StepRunnerUpgradeTrait;
99
use XF\Db\Schema\Create;
10+
use XF\Db\Schema\Alter;
1011

1112
class Setup extends AbstractSetup
1213
{
@@ -42,6 +43,14 @@ public function installStep3()
4243
$this->applyGlobalPermission('ifgs', 'view');
4344
}
4445

46+
public function upgrade1010070Step1()
47+
{
48+
$this->schemaManager()->alterTable('xf_if_gs_tiles', function (Alter $table)
49+
{
50+
$table->addColumn('font_size', 'varchar', 10)->nullable();
51+
});
52+
}
53+
4554
public function uninstallStep1()
4655
{
4756
$this->deleteWidget('if_gs_home_gridshow');

_files/js/inforge/gridshow/widget.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
function if_gs_fit_text()
2-
{
3-
var titles = $(".if-gs-widget").find(".if-gs-tile-title");
4-
titles.each(function() {
5-
var size = Math.max(Math.min($(this).width() / (0.5 + 0.2 * $(this).text().length)));
6-
var min_size = 6 + 0.04 * $(this).width();
7-
if (min_size < 9)
8-
min_size = 9;
9-
if (size < min_size)
10-
size = min_size;
11-
if (size > 20)
12-
size = 20;
13-
$(this).css("font-size", size);
14-
});
15-
}
16-
171
function if_gs_set_classes(tiles, pattern)
182
{
193
var spans = pattern.split(" ", tiles.length);
@@ -76,7 +60,4 @@ function if_gs_arrange_tiles()
7660
}
7761
if_gs_set_classes(tiles, pattern);
7862
widget.show();
79-
if_gs_fit_text();
8063
}
81-
82-
window.addEventListener("resize", if_gs_fit_text);

_output/phrases/_metadata.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@
9595
"version_string": "1.0.0",
9696
"hash": "4f397bc35465f1b3662a319c5daff680"
9797
},
98+
"if_gs_please_enter_valid_font_size_with_unit.txt": {
99+
"global_cache": false,
100+
"version_id": 1010070,
101+
"version_string": "1.1.0",
102+
"hash": "29a93c9d571279b746c5e72dadfe875d"
103+
},
98104
"if_gs_repeat_adding_space.txt": {
99105
"global_cache": false,
100106
"version_id": 1000070,
@@ -155,12 +161,30 @@
155161
"version_string": "1.0.0",
156162
"hash": "d9cd0dee0d71d31f68aaeb8ab5fd608a"
157163
},
164+
"if_gs_title_font_size.txt": {
165+
"global_cache": false,
166+
"version_id": 1010070,
167+
"version_string": "1.1.0",
168+
"hash": "f0dead1275554545f746af80dfbd67db"
169+
},
158170
"if_gs_url_contains_disallowed_scheme.txt": {
159171
"global_cache": false,
160172
"version_id": 1000070,
161173
"version_string": "1.0.0",
162174
"hash": "491be8ac06c38c3531c162cb203c78b9"
163175
},
176+
"if_gs_use_custom_font_size.txt": {
177+
"global_cache": false,
178+
"version_id": 1010070,
179+
"version_string": "1.1.0",
180+
"hash": "8f5ca8c0d42a139c77461b6efe6dee03"
181+
},
182+
"if_gs_use_default.txt": {
183+
"global_cache": false,
184+
"version_id": 1000070,
185+
"version_string": "1.0.0",
186+
"hash": "18d2833f3521aae3659901e620253894"
187+
},
164188
"option.ifGsEnable.txt": {
165189
"global_cache": false,
166190
"version_id": 1000070,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Please enter a valid font size with its unit.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Title font size
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use custom font size
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use default

_output/templates/_metadata.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"admin/if_gs_tile_edit.html": {
3-
"version_id": 1000070,
4-
"version_string": "1.0.0",
5-
"hash": "d3f6f762a39abbd6d444b259f7c3f9e8"
3+
"version_id": 1010070,
4+
"version_string": "1.1.0",
5+
"hash": "178ae4e894fc7c97cd2a9b1e926b609f"
66
},
77
"admin/if_gs_tile_list.html": {
88
"version_id": 1000070,
99
"version_string": "1.0.0",
1010
"hash": "91c40ab5a4793fbff30525c346f3c113"
1111
},
1212
"public/if_gs_gridshow_widget.html": {
13-
"version_id": 1000070,
14-
"version_string": "1.0.0",
15-
"hash": "4206170cb29b0cf988f3b4bee88551f0"
13+
"version_id": 1010070,
14+
"version_string": "1.1.0",
15+
"hash": "2a26b6d9d2f79493a6419b819c0ec815"
1616
},
1717
"public/if_gs_gridshow_widget.less": {
1818
"version_id": 1000070,

0 commit comments

Comments
 (0)