Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#847] Add draft of first JavaScript tutorial
- Loading branch information
Sean Hammond
committed
Nov 20, 2013
1 parent
542a72d
commit 983bb02
Showing
7 changed files
with
176 additions
and
17 deletions.
There are no files selected for viewing
Empty file.
8 changes: 8 additions & 0 deletions
8
ckanext/example_theme/v14_initialize_a_javascript_module/fanstatic/favorite.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,8 @@ | ||
ckan.module('favorite', function (jQuery, _) { | ||
return { | ||
initialize: function () { | ||
console.log("I've been initialized for element: %o", this.el); | ||
} | ||
}; | ||
}); | ||
|
14 changes: 14 additions & 0 deletions
14
ckanext/example_theme/v14_initialize_a_javascript_module/plugin.py
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,14 @@ | ||
import ckan.plugins as plugins | ||
import ckan.plugins.toolkit as toolkit | ||
|
||
|
||
class ExampleThemePlugin(plugins.SingletonPlugin): | ||
'''An example theme plugin. | ||
''' | ||
plugins.implements(plugins.IConfigurer) | ||
|
||
def update_config(self, config): | ||
|
||
toolkit.add_template_directory(config, 'templates') | ||
toolkit.add_resource('fanstatic', 'example_theme') |
15 changes: 15 additions & 0 deletions
15
ckanext/example_theme/v14_initialize_a_javascript_module/templates/home/index.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,15 @@ | ||
{% ckan_extends %} | ||
|
||
|
||
{% block content %} | ||
|
||
{{ super() }} | ||
|
||
{# Use Fanstatic to include our custom JavaScript module. #} | ||
{% resource 'example_theme/favorite.js' %} | ||
|
||
<form action="/favorite" method="post" data-module="favorite"> | ||
<button class="btn" name="package" value="101">Submit</button> | ||
</form> | ||
|
||
{% endblock %} |
22 changes: 22 additions & 0 deletions
22
...ext/example_theme/v14_initialize_a_javascript_module/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,22 @@ | ||
{% ckan_extends %} | ||
|
||
{% block package_item_content %} | ||
{{ super() }} | ||
|
||
{# Use Fanstatic to include our custom JavaScript module. | ||
A <script> tag for the module will be inserted in the right place at the | ||
bottom of the page. | ||
#} | ||
{% resource 'example_theme/favorite.js' %} | ||
|
||
{# Apply our JavaScript module to an HTML element. The data-module attribute, | ||
which can be applied to any HTML element, tells CKAN to initialize an | ||
instance of the named JavaScript module for the element. | ||
The initialize() method of our module will be called with this HTML | ||
element as its this.el object. | ||
#} | ||
<form action="/api/3/action/dataset_favorite" method="post" | ||
data-module="favorite"> | ||
<button class="btn" href="#"><i class="icon-star"></i></button> | ||
</form> | ||
{% 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