This commit is contained in:
Salvador de la Puente González 2016-03-18 13:38:56 +01:00
Родитель 44be041698
Коммит 96661ebd72
4 изменённых файлов: 22 добавлений и 13 удалений

Просмотреть файл

@ -72,13 +72,15 @@ class WP_Add_To_Homescreen_Admin {
$explanation = __('Icon to appear in the Home Screen (size must be 144x144px)', 'add-to-homescreen');
?>
<img id="icon-preview" style="width: 144px; height: 144px;"
src="<?php echo $current_icon; ?>"
src="<?php echo $current_icon['url']; ?>"
alt="<?php echo $explanation; ?>"
/>
<p class"small-text"><?php echo $explanation; ?></p>
<p>
<input type="hidden" id="icon-url" name="<?php echo $id; ?>"
value="<?php echo $current_icon; ?>"/>
<input type="hidden" id="icon-mime" name="<?php echo "$id" . '[mime]'; ?>"
value="<?php echo $current_icon['mime']; ?>"/>
<input type="hidden" id="icon-url" name="<?php echo "$id" . '[url]'; ?>"
value="<?php echo $current_icon['url']; ?>"/>
<input type="button" class="button" id="select-icon-button"
value="<?php _e('Select...', 'add-to-homescreen'); ?>" />
</p>
@ -87,15 +89,15 @@ class WP_Add_To_Homescreen_Admin {
public function sanitize_icon($new_icon) {
$current_icon = $this->options->get('icon');
if (!isset($new_icon)) {
if (!isset($new_icon['url'])) {
return $current_icon;
}
if ($current_icon !== $new_icon) {
WebAppManifestGenerator::getInstance()->set_field('icons', array(
array(
'src' => $new_icon,
'src' => $new_icon['url'],
'sizes' => '144x144',
'type' => 'image/png' // TODO: detect automatically
'type' => $new_icon['mime']
)
));
}

Просмотреть файл

@ -8,11 +8,12 @@ class WP_Add_To_Homescreen_Options {
private static $DEFAULTS = array(
);
public static function get_options($defaults=array()) {
public static function get_options() {
if(!self::$instance) {
foreach ($defaults as $name => $value) {
self::$DEFAULTS[$name] = $value;
}
self::$DEFAULTS['icon'] = array(
'url' => plugins_url('/lib/imgs/rocket.png', __FILE__),
'mime' => 'image/png'
);
self::$instance = new self();
}
return self::$instance;

Просмотреть файл

@ -35,7 +35,10 @@ class WP_Add_To_Homescreen_Plugin {
$plugin_main_file = plugin_dir_path(__FILE__) . 'wp-add-to-homescreen.php';
$this->stats = WP_Add_To_Homescreen_Stats::get_stats();
$this->options = WP_Add_To_Homescreen_Options::get_options(array(
'icon' => plugins_url('/lib/imgs/rocket.png', __FILE__)
'icon' => array(
'url' => plugins_url('/lib/imgs/rocket.png', __FILE__),
'mime' => 'image/png'
)
));
$this->set_urls();
$this->generate_sw();
@ -96,7 +99,7 @@ class WP_Add_To_Homescreen_Plugin {
public function add_theme_and_icons() {
$icon_path = plugins_url('/lib/imgs/rocket.png', __FILE__);
echo '<meta name="theme-color" content="#d53c30" />';
echo '<link rel="icon" sizes="144x144" href="' . $this->options->get('icon') . '" />';
echo '<link rel="icon" sizes="144x144" href="' . $this->options->get('icon')['url'] . '" />';
}
public function register_statistics() {

Просмотреть файл

@ -13,7 +13,10 @@
function updateIconUrl() {
var iconPreview = document.getElementById('icon-preview');
var iconUrl = document.getElementById('icon-url');
iconUrl.value = this.state().get('selection').first().toJSON().url;
var iconMime = document.getElementById('icon-mime');
var selection = this.state().get('selection').first();
iconUrl.value = selection.get('url');
iconMime.value = selection.get('mime');
iconPreview.src = iconUrl.value;
}