/[drupal]/contributions/modules/jsnippets/jsnippets.js
ViewVC logotype

Contents of /contributions/modules/jsnippets/jsnippets.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Mon Mar 2 19:58:08 2009 UTC (8 months, 4 weeks ago) by karthik
Branch: MAIN
CVS Tags: DRUPAL-6--1-1-ALPHA1, HEAD
Branch point for: DRUPAL-6--1
Changes since 1.3: +19 -20 lines
File MIME type: text/javascript
D6 migration: Get JS working.
1 // $Id: jsnippets.js,v 1.3 2007/02/20 14:03:22 karthik Exp $
2
3 Drupal.behaviors.jsnippets_onload = function() {
4 if (typeof jsnippets_get_all != 'undefined') {
5 var s = jsnippets_get_all();
6 jsnippets_add_selects(s);
7 }
8 }
9
10 function jsnippets_add_selects(jsnippets) {
11 for (var id in jsnippets) {
12 var textarea = $('#' + id).get(0);
13 var select = jsnippets_add_select(textarea, jsnippets[id], 'jsnippet-' + id);
14 select.change(
15 function() {
16 if (this.value != 'none') {
17 select.addClass('throbbing');
18 $.getJSON(Drupal.settings.basePath + "jsnippets/retrieve/" + this.value, null, function(json) {
19 if (textarea.value.length > 0) {
20 textarea.value += '\n\n' + json[select.get(0).value];
21 }
22 else {
23 textarea.value = json[select.get(0).value];
24 }
25 textarea.scrollTop = textarea.scrollHeight - textarea.clientHeight;
26 select.removeClass('throbbing');
27 });
28 }
29 }
30 );
31 }
32 }
33
34 function jsnippets_add_select(textarea, jsnippet, jsnippet_id) {
35 var div = document.createElement('div');
36 div.className = 'jsnippet';
37 div.id = jsnippet_id;
38 var select = div.appendChild(document.createElement('select'));
39 for (var o in jsnippet) {
40 var opt = select.appendChild(document.createElement('option'));
41 opt.value = o;
42 opt.innerHTML = jsnippet[o];
43 }
44 document.body.appendChild(div);
45 select = $('#' + jsnippet_id);
46 select_element = select.get(0);
47 select.addClass('autocomplete');
48
49 p = $(textarea).offset();
50 select.css('right', (p.left + textarea.clientWidth - select_element.clientWidth) + 'px');
51 select.css('top', (p.top - select_element.clientHeight) + 'px');
52 select = $('#' + jsnippet_id + ' select');
53
54 return select;
55 }

  ViewVC Help
Powered by ViewVC 1.1.2