/[drupal]/contributions/modules/context/context_ui/context_ui.js
ViewVC logotype

Contents of /contributions/modules/context/context_ui/context_ui.js

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


Revision 1.3 - (show annotations) (download) (as text)
Mon Sep 1 20:21:08 2008 UTC (14 months, 3 weeks ago) by yhahn
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.2: +5 -5 lines
File MIME type: text/javascript
Merging fix for blocks in custom regions from DRUPAL-5 branch
1 // $Id: context_ui.js,v 1.2 2008/07/17 16:57:19 jmiccolis Exp $
2
3 if (typeof(Drupal) == "undefined" || !Drupal.context_ui) {
4 Drupal.context_ui = {};
5 }
6
7 Drupal.context_ui.attach = function() {
8 var item_tools = "<div class='tools'><span class='up'>Up</span><span class='down'>Down</span><span class='remove'>X</span></div>";
9
10 // multiselect handler
11 $("input#edit-block-selector-add").click(function() {
12 var region = $("select#edit-block-selector-regions").val().replace('_', '-');
13 var selected = $("select#edit-block-selector-blocks option:selected");
14 if (selected.size() > 0) {
15 $("div.context-ui-block-regions ul." + region + " li.dummy").remove();
16 selected.each(function() {
17 if (!$(this).attr('disabled')) {
18 // create new block li
19 var block = document.createElement('li');
20 var value = $(this).attr('value');
21 var text = item_tools + $(this).text();
22 $(block).attr('title', value).html(text);
23
24 // attach tool handlers
25 Drupal.context_ui.attachtools(block);
26
27 // remove option
28 $(this).remove();
29
30 // add block item to region
31 $("div.context-ui-block-regions ul."+ region).append(block);
32
33 Drupal.context_ui.regionblocks(region);
34 }
35 });
36 }
37 });
38
39 // attach tool handler to existing context_ui blocks
40 $("div.context-ui-block-regions ul li").each(function() {
41 Drupal.context_ui.attachtools(this);
42 });
43 }
44
45 Drupal.context_ui.attachtools = function(block) {
46 if ($("div.tools", block).size() > 0) {
47 // remove block
48 $("div.tools span.remove", block).click(function() {
49 var item = $(this).parents("li");
50 $("div.tools", item).remove();
51
52 // create new block select option
53 var option = document.createElement('option');
54 var value = $(item).attr('title');
55 var text = item.text();
56 $(option).attr('value', value).text(text);
57
58 // retrieve region info before item is deleted
59 var region = $(item).parents("ul").attr("class");
60
61 // remove block item
62 item.remove();
63
64 // add block option
65 $("select#edit-block-selector-blocks").append(option);
66
67 Drupal.context_ui.regionblocks(region);
68 });
69 // move block up
70 $("div.tools span.up", block).click(function() {
71 var prev = $(this).parents("li").prev();
72 if (prev) {
73 var item = $(this).parents("li");
74 var region = $(this).parents("ul").attr("class");
75 prev.before(item);
76 Drupal.context_ui.regionblocks(region);
77 }
78 });
79 // move block down
80 $("div.tools span.down", block).click(function() {
81 var next = $(this).parents("li").next();
82 if (next) {
83 var item = $(this).parents("li");
84 var region = $(this).parents("ul").attr("class");
85 next.after(item);
86 Drupal.context_ui.regionblocks(region);
87 }
88 });
89 }
90 }
91
92 Drupal.context_ui.regionblocks = function (region) {
93 var serialized = '';
94 if ($("div.context-ui-block-regions ul."+ region +" li").size() > 0) {
95 $("div.context-ui-block-regions ul."+ region +" li").each(function() {
96 if (serialized == '') {
97 serialized = $(this).attr('title');
98 }
99 else {
100 serialized = serialized +","+ $(this).attr('title');
101 }
102 });
103 $("input#edit-block-regions-"+ region).val(serialized);
104 }
105 else if ($("input#edit-block-regions-"+ region).size() > 0) {
106 $("input#edit-block-regions-"+ region).val('');
107 }
108 }
109
110 if (Drupal.jsEnabled) {
111 $(document).ready(function() {
112 if ($('form#context-ui-form').size() > 0) {
113 Drupal.context_ui.attach();
114 }
115 });
116 };

  ViewVC Help
Powered by ViewVC 1.1.2