Login

All snippets written in JavaScript

60 snippets

Snippet List

Django Drag and Drop Using YUI

I was trying to implement the django inline drag & drop, I cudn't understand. Then I have try with YUI library Copy the above code in the respective .py & download the YUI library and add the JS in your media folder. This will do..., Try this our , it's easy to use..,

  • django
  • yui
  • drag
  • drop
  • and
Read More

generateChart() for creating a Google Chart API pie chart from JavaScript

I ended up not needing this (there's a good reason it's in JS and not Python, but most people would probably want to do this server-side instead) but I'm stashing it here in case I need it later. It uses jQuery for the .each() method - which is very easy to replace if you need it to work without that dependency. Usage: var src = generateChart({ "foo": 5, "bar": 3, "baz": 6 });

  • javascript
  • googlechartapi
  • piechart
  • graphs
Read More

XFN Assist

This code assumes your XFN field is called 'rel' in models. See the last call (addLoadEvent down the bottom) for the two lines requiring modification; otherwise, aside from the Django-styling involved, it can be used anywhere. The accompanying model.py and admin.py information can be found here: [http://www.djangosnippets.org/snippets/1265/](http://www.djangosnippets.org/snippets/1265/). I'm no master programmer, so feedback/comments/criticism is more than welcome. EDIT: Fixed my esoteric dev. comments and removed references to spawning more overlords.

  • xfn
  • microformats
Read More

Admin Input Field Character Count via jQuery

Use this code in *change_form.html* in your projects admin templates to add a character counter beside the input field(s) in admin to let users know how many characters they have remaining for a particular input field. The total number of characters allowed is determined by the max_length in your model for the models.CharField you're using this with. This code is designed to add the counter after the input field, but could easily be customized to fit the style of any admin. If the number of characters remaining is 10 or less the background color changes to yellow to visually warn the user. **Usage Examples:** In this example only the input field with id=id_pull_quote will receive the counter: $(document).ready(function() { $("#id_pull_quote").counter(); }); You could also apply the counter to all input fields on a page: $(document).ready(function() { $("form input[@maxlength]").counter(); }); **Note:** *You have to download jQuery to your project and place the appropriate call in order for this to work. The best place to do this is in the extrahead block. I left my call in as an example but your path and file name will probably vary.* Credit for base jQuery code goes to Brad Landis at [bradlis7.com](http://www.bradlis7.com).

  • template
  • javascript
  • admin
  • jquery
  • form
  • input
Read More

Add extra form elements in your contib admin

Add extra form elements in your contib admin Install add this in header of base.html <script type="text/javascript" src="/static/jquery-1.2.6.min.js"></script> http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.6.min.js

  • form
  • extra
  • elements
Read More

FilterManager

Save a filter in admin app Example: http://localhost:8000/admin/org/registrationprofile/?title__exact=Dr&ot=asc&o=4&speciality__exact=gynaecology you can save this path org/registrationprofile/?title__exact=Dr&ot=asc&o=4&speciality__exact=gynaecology as your filter with name like "DrGynecologySortedCyty" and then select this filter from selectbox include JavaScript file FilterManager.js and jQuery in all admin templates. === Install === 1. Add this in header of base.html for contrib.admin You can download this files from http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.6.min.js 2. Change path for your model that you will save in javaScript file FilterManager.js Example: /admin/org/registrationprofile/ 3. Add models and views. see code

  • filtermanager
Read More

Integrate Wymeditor with filebrowser plugin

In order to integrate Wymeditor with the Django filebrowser, put the code in a file, set the fb_url variable to point to your filebrowser instance and add the file to your Javascript headers: <script type="text/javascript" src="/media/wymeditor/plugins/jquery.wymeditor.filebrowser.js"></script> or in your admin.py: class Media: js = ('/media/wymeditor/plugins/jquery.wymeditor.filebrowser.js',) Add the postInitDialog parameter to the Wymeditor initialization: $('textarea').wymeditor({ postInitDialog: wymeditor_filebrowser }); If you already have a postInitDialog function, you need to put a call to wymeditor_filebrowser inside that function. Then you should be able to click on the Filebrowser link to select an image.

  • javascript
  • images
  • wymeditor
  • filebrowser
Read More

FCKEditor replace all vLargeTextField in admin

If you want to add an fckeditor for every vLargeTextField (the input class used by models.TextField) you can use this javascript. you can load that in all admin pages overriding templates/admin/base_site.html with this: {% extends "admin/base.html" %} {% load i18n %} {% block title %}{{ title }} | {% trans "Administrative Area" %}{% endblock %} {% block branding %} <h1 id="site-name">{% trans "Administrative Area" %}</h1> {% endblock %} {% block nav-global %}{% endblock %} {% block extrahead %}{{ block.super }} <script src="{{media_url}}js/jquery.js" type="text/javascript"></script> <script src="{{media_url}}fckeditor/fckeditor.js" type="text/javascript"></script> <script src="{{media_url}}fckeditor/custom/vTextField.js" type="text/javascript"></script> {% endblock %}

  • admin
  • textfield
  • rich-text-editor
  • fckeditor
  • vlargtextfield
Read More

Search Docs with Shortwave

. . For use with [Shortwave](http://shortwaveapp.com/). Add this to your hosted `wave.txt` for a search of the current Django docs.

  • search
  • documentation
  • shortwave
Read More

Disable fields in oldforms admin using jQuery

This snippet shows how to disable fields in a edit page in the oldforms admin using jquery. The idea is to add the javascript to the edit page using the `js` attribute of the model's `Admin` class. In this case jQuery and a custom javascript file are added. The javascript sets the `disabled` attribute of the `name` field to `true` as soon as the document is ready.

  • admin
  • jquery
  • oldforms
  • disable
Read More

simple jquery example

Displays an input with an add button. Clicking the add button creates a simple form - input with a submit button. Clicking the submit button will send the output to the server and return a value which is displayed.

  • ajax
  • jquery
Read More

Who's helping a lot in IRC

We had some fun today on the #django IRC channel searching and counting through past logs for people saying "thanks" to [a known very helpful person](http://djangopeople.net/magus/). Here's a unix shell script for checking your own score if you're using Pidgin and have logging turned on. Replace ".purple" with ".gaim" in the script if you're using Gaim (an older version of Pidgin).

  • log
  • help
  • irc
  • thanks
  • score
Read More

Dynamical formsets

If you need dynamical formsets you can use `{{ empty_form }}` in template and even makeup it.

  • formset
Read More

Allow editing of the selected object of the filter_vertical/filter_horizontal widget with jquery

This patch allows to open a popup to edit the selected object of either the left or right select input of a filter_horizontal or filter_vertical field, when pressing the "Insert" key. Being a noob with general client-side issue, it's served as a patch that suits my needs. Maybe it's possible to do it cleaner by overloading the javascript methods, or get rid of the jquery dependency in order to integrate it into django trunk ... Any contribution is welcome! It's licensed under WTFPL license. Requires jquery.

  • admin
  • jquery
  • widget
  • filter_horizontal
  • filter_vertical
Read More