Skip to content

Commit

Permalink
Add more settings and default values
Browse files Browse the repository at this point in the history
  • Loading branch information
madnh committed Nov 8, 2016
1 parent 083f97c commit 5b7d83a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
9 changes: 5 additions & 4 deletions components/Disqus.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ protected function getData()
$disqus = [
'page_url' => $this->property('page_url'),
'page_id_prefix' => $this->property('page_id_prefix'),
'page_id' => $this->property('page_id')
'page_id' => $this->property('page_id'),
'enable' => Settings::get('enable'),
'sub_domain' => Settings::get('sub_domain'),
'noscript_content' => Settings::get('noscript_content'),
'disabled_content' => Settings::get('disabled_content')
];

$disqus['sub_domain'] = Settings::get('sub_domain');
$disqus['noscript_content'] = Settings::get('noscript_content');

return $disqus;
}

Expand Down
39 changes: 25 additions & 14 deletions components/disqus/default.htm
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
{% set disqus = __SELF__.disqus %}
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = '{{ disqus.page_url }}' || window.location.href;
this.page.identifier = "{{ (disqus.page_id_prefix ? disqus.page_id_prefix ~ '_' : '') ~ disqus.page_id }}" || window.location.href;
};
{% if disqus.enable %}
{% if not disqus.sub_domain %}
<div class="alert alert-warning" role="alert">
<strong>Warning!</strong> please config Disqus sub domain first!
</div>
{% else %}
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = '{{ disqus.page_url }}' || window.location.href;
this.page.identifier = "{{ (disqus.page_id_prefix ? disqus.page_id_prefix ~ '_' : '') ~ disqus.page_id }}" || window.location.href;
};

(function () {
var d = document, s = d.createElement('script');
s.src = '//{{ disqus.sub_domain }}.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>{{ disqus.noscript_content | raw }}</noscript>
{% endif %}
{% else %}
{{ disqus.disabled_content | raw }}
{% endif %}

(function () {
var d = document, s = d.createElement('script');
s.src = '//{{ disqus.sub_domain }}.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>{{ disqus.noscript_content | raw }}</noscript>
7 changes: 7 additions & 0 deletions models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ class Settings extends Model

// Reference to field configuration
public $settingsFields = 'fields.yaml';

public function initSettingsData()
{
$this->enable = '1';
$this->noscript_content = '<div class="alert alert-warning" role="alert"><strong>Disqus:</strong> Your browser does not support JavaScript!</div>';
$this->disabled_content = '<div class="alert alert-success" role="alert"><strong>Hi,</strong> Disqus is off</div>';
}
}
18 changes: 16 additions & 2 deletions models/settings/fields.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
fields:
enable:
label: Enable
span: auto
default: '1'
type: switch
comment: 'Enable Disqus or not?'
sub_domain:
label: 'Disqus subdomain'
oc.commentPosition: ''
span: full
cssClass: ''
required: 1
type: text
noscript_content:
label: 'Message when JS is turn off'
oc.commentPosition: ''
size: giant
size: huge
language: html
span: full
span: left
type: codeeditor
disabled_content:
label: 'Disabled content'
oc.commentPosition: ''
size: huge
language: php
span: right
type: codeeditor
5 changes: 4 additions & 1 deletion updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
- Initialize plugin.

1.0.2:
- Add plugin execution life cycle handler name, remove page variable, add LICENCE.md file.
- Add plugin execution life cycle handler name, remove page variable, add LICENCE.md file.

1.0.3:
- Add more settings and default values

0 comments on commit 5b7d83a

Please sign in to comment.