From 6e50e82fb40c77b059c4ff2eae936cb779303a63 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Wed, 13 Apr 2011 21:06:13 -0400 Subject: Javascript hack to make HTML in JSON work. --- leafymiracle/static/js/searchbar_html_support.js | 14 ++++++++++++++ leafymiracle/widgets.py | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 leafymiracle/static/js/searchbar_html_support.js diff --git a/leafymiracle/static/js/searchbar_html_support.js b/leafymiracle/static/js/searchbar_html_support.js new file mode 100644 index 0000000..4d07901 --- /dev/null +++ b/leafymiracle/static/js/searchbar_html_support.js @@ -0,0 +1,14 @@ +// Add the hook in for catcomplete. +// We add it here instead of a tw2.jquery_ui template because it must +// be executed before *any* other plugins reference jquery ui proper + +$(document).ready(function() { + $.widget( "custom.catcomplete", $.ui.autocomplete, { + _renderItem: function( ul, item) { + return $( "
  • " ) + .data( "item.autocomplete", item ) + .append( $( "" ).html( item.label ) ) + .appendTo( ul ); + } + }); +}); diff --git a/leafymiracle/widgets.py b/leafymiracle/widgets.py index 91b06d5..bf96e3a 100644 --- a/leafymiracle/widgets.py +++ b/leafymiracle/widgets.py @@ -18,6 +18,7 @@ from tw2.jqplugins.ui import DialogWidget from tw2.jqplugins.ui import CategoryAutocompleteWidget from tw2.core.resources import JSSymbol +from tw2.core.resources import JSLink import docutils.examples @@ -88,7 +89,16 @@ class LeafyDialog(DialogWidget): } value = leafy_readme() +searchbar_html_support_js = JSLink( + link='/static/js/searchbar_html_support.js') + class LeafySearchbar(CategoryAutocompleteWidget): + def prepare(self): + # Add this javascript hack into the client that makes jquery-ui + # render html embedding in JSON. :D:D:D:D:D + self.resources.append(searchbar_html_support_js) + super(LeafySearchbar, self).prepare() + id = 'leafy_searchbar' value = "Leafy Searchbar" tags = [] -- cgit