Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1377] Add this.options and this.el javascript example
- Loading branch information
Sean Hammond
committed
Dec 12, 2013
1 parent
619cc27
commit 11f5cb0
Showing
7 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
35 changes: 35 additions & 0 deletions
35
ckanext/example_theme/v17_popover/fanstatic/example_theme_popover.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* example_theme_popover | ||
* | ||
* This JavaScript module adds a Bootstrap popover with some extra info about a | ||
* dataset to the HTML element that the module is applied to. Users can click | ||
* on the HTML element to show the popover. | ||
* | ||
* title - the title of the dataset | ||
* license - the title of the dataset's copyright license | ||
* num_resources - the number of resources that the dataset has. | ||
* | ||
*/ | ||
ckan.module('example_theme_popover', function (jQuery, _) { | ||
return { | ||
initialize: function () { | ||
|
||
// Access some options passed to this JavaScript module by the calling | ||
// template. | ||
var num_resources = this.options.num_resources; | ||
var license = this.options.license; | ||
|
||
// Format a simple string with the number of resources and the license, | ||
// e.g. "3 resources, Open Data Commons Attribution License". | ||
var content = 'NUM resources, LICENSE' | ||
.replace('NUM', this.options.num_resources) | ||
.replace('LICENSE', this.options.license) | ||
|
||
// Add a Bootstrap popover to the HTML element (this.el) that this | ||
// JavaScript module was initialized on. | ||
this.el.popover({title: this.options.title, | ||
content: content, | ||
placement: 'left'}); | ||
} | ||
}; | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../v16_initialize_a_javascript_module/plugin.py |
16 changes: 16 additions & 0 deletions
16
ckanext/example_theme/v17_popover/templates/snippets/package_item.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% ckan_extends %} | ||
|
||
{% block package_item_content %} | ||
{{ super() }} | ||
{% resource 'example_theme/example_theme_popover.js' %} | ||
|
||
{# Apply out JavaScript module to an HTML <button> element. | ||
The additional data-module-* attributes are options that will be passed | ||
to the JavaScript module. #} | ||
<button data-module="example_theme_popover" | ||
data-module-title="{{ package.title }}" | ||
data-module-license="{{ package.license_title }}" | ||
data-module-num_resources="{{ package.num_resources }}"> | ||
<i class="icon-info-sign"></i> | ||
</button> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters