Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added ability to extend FiberItem from a project.\n To use this, you mus... #74

Closed
wants to merge 3 commits into from

3 participants

@markotibold

...t create the file static/fiber/js/admin_extend.js in your project.

@markotibold markotibold Added ability to extend FiberItem from a project.\n To use this, you …
…must create the file static/fiber/js/admin_extend.js in your project.
8a38a61
@mvdwaeter

Hi Marko,

If you're not extending the fiber-admin this will produce a 404-error. Because admin_extend.js can not be found.
I see that in this commit:
bdc313f
a file named admin_extra.js is added.

Using both admin_extra.js and admin_extend.js seems a bit messy to me.

What about putting this in header.html:

{% block extra_js %}
    <script src="{{ STATIC_URL }}fiber/js/admin.js" type="text/javascript"></script>
{% endblock %}

And when you want to extend your header.html you can do it like this:

Create a file named "header.html" file in your project root, e.g /project/templates/fiber/header.html that looks like this:

{% extend "fiber/header.html" %}

{% block extend_js %}
    {{ block.super }}
    <script src="{{ STATIC_URL }}fiber/js/admin_extend.js" type="text/javascript"></script>
{% endblock %}

Also, when adding this feature, I'd like to see how I can use this hook in "django-fiber / docs / advanced-usage.rst"

@markotibold

@mvdwaeter

Hi michael. I have taken your advice into account and implemented your proposal. I have also written some docs that describe the functionality as you requested.

Cheers,

Marko

@dbunskoek dbunskoek closed this
@dbunskoek
Owner

Looks like a nice solution to me as well, so I'll close this pull request, ok?

@markotibold

I have managed to accomplished the same without touching fiber. I just had to make sure that my javascript was loaded after admin.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 27, 2012
  1. @markotibold

    Added ability to extend FiberItem from a project.\n To use this, you …

    markotibold authored
    …must create the file static/fiber/js/admin_extend.js in your project.
Commits on Apr 3, 2012
  1. @markotibold

    Processeed recommendation from @mvdwaeter so that extension is being …

    markotibold authored
    …done by writing a header.html template.
  2. @markotibold

    docs for extending

    markotibold authored
This page is out of date. Refresh to see the latest.
View
47 docs/advanced-usage.rst
@@ -150,4 +150,49 @@ You can also override the entire CKEditor toolbar, by setting the variable:
window.CKEDITOR_CONFIG_TOOLBAR
To see how this works, check the fiber.ckeditor.js file in the Django Fiber source:
-https://github.com/ridethepony/django-fiber/blob/master/fiber/static/fiber/js/fiber.ckeditor.js
+https://github.com/ridethepony/django-fiber/blob/master/fiber/static/fiber/js/fiber.ckeditor.js
+
+
+Extending admin.js
+==================
+
+In this example we'll change the behavior of FiberItems. Note that extending Fiber in this way is not
+guranteed to stay functional upon an update of fiber since you're building on the internals of fiber.
+
+
+header.html
+-----------
+
+Create a header.html template inside your app, e.g. `/your_app/templates/fiber/header.html`.
+
+If you want to extend any Jquery classes inside `static/fiber/js/admin.js` you must make sure that your
+javascript is loaded after fiber's `admin.js`. So here's what your `header.html` might look like::
+
+ {% extend "fiber/header.html" %}
+
+ {% block extra_js %}
+ {{ block.super }}
+ <script src="{{ STATIC_URL }}fiber/js/admin_extend.js" type="text/javascript"></script>
+ {% endblock %}
+
+Now you can extend Fiber.FiberItem in your own javascript file `admin_extend.js`. Here's how you would extend
+the `button_podition` method::
+
+ Fiber.FiberItem.prototype.button_position = function() {
+ ...
+ <your code here>
+ ...
+ }
+
+
+Tips
+----
+
+* Make sure your apps are listed _before_ fiber in INSTALLED_APPS
+* Add the path to where fiber is installed to TEMPLATE_DIRS, e.g.:
+
+ import os, fiber
+ TEMPLATE_DIRS = (os.path.dirname(os.path.dirname(fiber.__file__)),
+
+ )
+
View
4 fiber/static/fiber/js/admin.js
@@ -1298,7 +1298,7 @@ var adminPage = {
create_fiber_item: function($fiber_element) {
// create new FiberItem
- var fiber_item = new FiberItem($fiber_element);
+ var fiber_item = new Fiber.FiberItem($fiber_element);
this.all_fiber_items.push(fiber_item);
// find closest parent, and see if it is already a FiberItem
@@ -1852,7 +1852,7 @@ function reloadPage(params) {
// TODO: subclass for specific uses (add / change) and types (page / content / other)
-var FiberItem = Class.extend({
+Fiber.FiberItem = Class.extend({
// TODO: add defaults?
init: function($element) {
View
4 fiber/templates/fiber/header.html
@@ -32,7 +32,9 @@
<script src="{{ STATIC_URL }}fiber/js/file-uploader/fileuploader.js" type="text/javascript"></script>
<script src="{{ STATIC_URL }}fiber/js/admin-extra.js" type="text/javascript"></script>
-<script src="{{ STATIC_URL }}fiber/js/admin.js" type="text/javascript"></script>
+{% block extra_js %}
+ <script src="{{ STATIC_URL }}fiber/js/admin.js" type="text/javascript"></script>
+{% endblock %}
{% endcompress %}
{% if editor_template_js %}
Something went wrong with that request. Please try again.