Merge lp:~robbyoconnor/sahana-eden/surveytool into lp:sahana-eden
- surveytool
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 1168 |
Proposed branch: | lp:~robbyoconnor/sahana-eden/surveytool |
Merge into: | lp:sahana-eden |
Diff against target: |
14613 lines (+14129/-292) 27 files modified
controllers/budget.py (+2/-2) controllers/survey.py (+460/-0) models/000_config.py (+295/-288) models/survey.py (+142/-0) modules/validators.py (+1/-1) modules/widgets.py (+1/-1) static/scripts/survey/jquery-ui-1.8.4.custom.js (+11241/-0) static/scripts/survey/jquery.bsmselect.js (+481/-0) static/scripts/survey/jquery.selectboxes.js (+533/-0) static/scripts/survey/jquery.selectboxes.min.js (+14/-0) static/styles/survey/jquery.bsmselect.css (+64/-0) views/question_create.html (+21/-0) views/survey/index.html (+16/-0) views/survey/layout.html (+98/-0) views/survey/layout_popup.html (+102/-0) views/survey/question_options_create.html (+117/-0) views/survey/question_options_update.html (+111/-0) views/survey/question_popup.html (+26/-0) views/survey/question_update.html (+21/-0) views/survey/questions.html (+82/-0) views/survey/section_layout.html (+184/-0) views/survey/table.html (+26/-0) views/survey/table_create.html (+21/-0) views/survey/table_list.html (+3/-0) views/survey/table_update.html (+21/-0) views/survey/template_create.html (+23/-0) views/survey/template_update.html (+23/-0) |
To merge this branch: | bzr merge lp:~robbyoconnor/sahana-eden/surveytool |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Fran Boon | Pending | ||
Review via email: mp+34371@code.launchpad.net |
Commit message
merge survey tool into trunk. Incredibly buggy...people are advised to *NOT* use this code in a production instance of sahana as it may or may not work properly!
Description of the change
Fran,
I'm allowing you to (finally) merge in the survey tool. I've got a full plate right now and won't have the time to make the changes necessary.
There are bugs:
All on the "Add Questions" page (this page is very buggy).
* the CSS on the multiselect widget is busted and acts weird with long Questions
* It doesn't update properly
* It doesn't seem to reload the questions correctly -- probably on account of a bad query
Sections have yet to be implemented but should be done using subheadings. I want to do this, but if somebody gets to it first, oh well.
You may also want to peek at http://
Preview Diff
1 | === modified file 'VERSION' (properties changed: +x to -x) | |||
2 | === modified file 'controllers/budget.py' | |||
3 | --- controllers/budget.py 2010-08-28 09:44:22 +0000 | |||
4 | +++ controllers/budget.py 2010-09-02 01:18:42 +0000 | |||
5 | @@ -153,7 +153,7 @@ | |||
6 | 153 | "Module's Home Page" | 153 | "Module's Home Page" |
7 | 154 | 154 | ||
8 | 155 | module_name = deployment_settings.modules[module].name_nice | 155 | module_name = deployment_settings.modules[module].name_nice |
10 | 156 | 156 | ||
11 | 157 | return dict(module_name=module_name) | 157 | return dict(module_name=module_name) |
12 | 158 | 158 | ||
13 | 159 | def parameters(): | 159 | def parameters(): |
14 | @@ -1418,7 +1418,7 @@ | |||
15 | 1418 | budget = int(request.args(0)) | 1418 | budget = int(request.args(0)) |
16 | 1419 | except TypeError, ValueError: | 1419 | except TypeError, ValueError: |
17 | 1420 | session.error = T("Need to specify a Budget!") | 1420 | session.error = T("Need to specify a Budget!") |
19 | 1421 | redirect(URL(r=request, f="budget")) | 1421 | redirect(URL(r=reqest, f="budget")) |
20 | 1422 | 1422 | ||
21 | 1423 | tables = [db.budget_budget_staff, db.budget_budget_bundle] | 1423 | tables = [db.budget_budget_staff, db.budget_budget_bundle] |
22 | 1424 | authorised = shn_has_permission("update", tables[0]) and shn_has_permission("update", tables[1]) | 1424 | authorised = shn_has_permission("update", tables[0]) and shn_has_permission("update", tables[1]) |
23 | 1425 | 1425 | ||
24 | === modified file 'controllers/default.py' (properties changed: +x to -x) | |||
25 | === modified file 'controllers/pr.py' (properties changed: +x to -x) | |||
26 | === added file 'controllers/survey.py' | |||
27 | --- controllers/survey.py 1970-01-01 00:00:00 +0000 | |||
28 | +++ controllers/survey.py 2010-09-02 01:18:42 +0000 | |||
29 | @@ -0,0 +1,460 @@ | |||
30 | 1 | # -*- coding: utf-8 -*- | ||
31 | 2 | |||
32 | 3 | """ | ||
33 | 4 | Survey Module -- a tool to create surveys. | ||
34 | 5 | |||
35 | 6 | @author: Robert O'Connor | ||
36 | 7 | """ | ||
37 | 8 | from gluon.html import * | ||
38 | 9 | from gluon.sqlhtml import SQLFORM | ||
39 | 10 | |||
40 | 11 | module = "survey" | ||
41 | 12 | |||
42 | 13 | |||
43 | 14 | # Will populate later on. | ||
44 | 15 | response.menu_options = [ | ||
45 | 16 | [T("Template"), False, URL(r=request, f="template"),[ | ||
46 | 17 | [T("List"), False, URL(r=request, f="template")], | ||
47 | 18 | [T("Add"), False, URL(r=request, f="template", args="create")] | ||
48 | 19 | ]], | ||
49 | 20 | [T("Series"), False, URL(r=request, f="series"),[ | ||
50 | 21 | [T("List"), False, URL(r=request, f="series")], | ||
51 | 22 | [T("Add"), False, URL(r=request, f="series", args="create")] | ||
52 | 23 | ]]] | ||
53 | 24 | def template_link(): | ||
54 | 25 | response.s3.prep = response.s3.prep = lambda jr: jr.representation in ("xml", "json") and True or False | ||
55 | 26 | return shn_rest_controller("survey", "template_link") | ||
56 | 27 | |||
57 | 28 | def index(): | ||
58 | 29 | "Module's Home Page" | ||
59 | 30 | module_name = deployment_settings.modules[module].name_nice | ||
60 | 31 | return dict(module_name=module_name) | ||
61 | 32 | |||
62 | 33 | def template(): | ||
63 | 34 | """ RESTlike CRUD controller """ | ||
64 | 35 | resource = "template" | ||
65 | 36 | def _prep(jr): | ||
66 | 37 | crud.settings.create_next = URL(r = request, c="survey", f="questions") | ||
67 | 38 | crud.settings.update_next = URL(r = request, c="survey", f="questions") | ||
68 | 39 | return True | ||
69 | 40 | response.s3.prep = _prep | ||
70 | 41 | |||
71 | 42 | tablename = "%s_%s" % (module, resource) | ||
72 | 43 | table = db[tablename] | ||
73 | 44 | table.uuid.requires = IS_NOT_IN_DB(db,"%s.uuid" % tablename) | ||
74 | 45 | table.name.requires = IS_NOT_EMPTY() | ||
75 | 46 | table.name.label = T("Survey Name") | ||
76 | 47 | table.name.comment = SPAN("*", _class="req") | ||
77 | 48 | table.description.label = T("Description") | ||
78 | 49 | |||
79 | 50 | |||
80 | 51 | # CRUD Strings | ||
81 | 52 | s3.crud_strings[tablename] = Storage( | ||
82 | 53 | title_create = T("Add Survey Template"), | ||
83 | 54 | title_display = T('Survey Template Details'), | ||
84 | 55 | title_list = T("List Survey Templates"), | ||
85 | 56 | title_update = T('Edit Survey Template'), | ||
86 | 57 | subtitle_create = T('Add New Survey Template'), | ||
87 | 58 | subtitle_list = T('Survey Templates'), | ||
88 | 59 | label_list_button = T("List Survey Templates"), | ||
89 | 60 | label_create_button = T("Add Survey Template"), | ||
90 | 61 | msg_record_created = T('Survey Template added'), | ||
91 | 62 | msg_record_modified = T('Survey Template updated'), | ||
92 | 63 | msg_record_deleted = T('Survey Template deleted'), | ||
93 | 64 | msg_list_empty = T('No Survey Template currently registered')) | ||
94 | 65 | |||
95 | 66 | output = shn_rest_controller(module,resource,listadd=False) | ||
96 | 67 | return transform_buttons(output,next=True,cancel=True) | ||
97 | 68 | |||
98 | 69 | def questions(): | ||
99 | 70 | """ | ||
100 | 71 | At this stage, the user the following workflow will be implemented: | ||
101 | 72 | |||
102 | 73 | - User adds questions via the drop down or clicks "Add Question" to add a new one. | ||
103 | 74 | """ | ||
104 | 75 | table = db["survey_questions"] | ||
105 | 76 | record = request.args(0) | ||
106 | 77 | template = db(db.survey_template.id == session.rcvars.survey_template).select().first() | ||
107 | 78 | if not record: | ||
108 | 79 | questions_query = (db.survey_template_link.survey_questions_id == db.survey_questions.id) & (template.id == db.survey_template_link.survey_template_id) | ||
109 | 80 | record = db(questions_query).select(db.survey_questions.id).first() | ||
110 | 81 | if record: | ||
111 | 82 | redirect(URL(r=request,f="questions",args=[record.id])) | ||
112 | 83 | questions_form = SQLFORM(table,record,deletable=True,keepvalues=True) | ||
113 | 84 | all_questions = db().select(db.survey_question.ALL) | ||
114 | 85 | output = dict(all_questions=all_questions) | ||
115 | 86 | # Let's avoid blowing up -- this loads questions | ||
116 | 87 | try: | ||
117 | 88 | query = (template.id == db.survey_template_link.survey_template_id) | ||
118 | 89 | contained_questions = db(query).select(db.survey_question.id) | ||
119 | 90 | if len(contained_questions) > 0: | ||
120 | 91 | output.update(contained_questions=contained_questions) | ||
121 | 92 | else: | ||
122 | 93 | output.update(contained_questions=contained_questions) | ||
123 | 94 | except: | ||
124 | 95 | output.update(contained_questions=[]) | ||
125 | 96 | pass # this means we didn't pass an id, e.g., making a new section! | ||
126 | 97 | if questions_form.accepts(request.vars,session,keepvalues=True): | ||
127 | 98 | questions = request.post_vars.questions | ||
128 | 99 | if questions: | ||
129 | 100 | for question in questions: | ||
130 | 101 | if not has_dupe_questions(template.id,question): | ||
131 | 102 | db.survey_template_link.insert(survey_template_id=session.rcvars.survey_template,survey_questions_id=questions_form.vars.id, | ||
132 | 103 | survey_question_id=question) | ||
133 | 104 | elif questions_form.errors: | ||
134 | 105 | response.flash= T("Please correct all errors.") | ||
135 | 106 | output.update(form=questions_form) | ||
136 | 107 | return output | ||
137 | 108 | def table(): | ||
138 | 109 | if not "series_id" in request.vars: | ||
139 | 110 | response.error = "You must provide both a series id to proceed." | ||
140 | 111 | return dict() # empty dict! | ||
141 | 112 | |||
142 | 113 | # store the necessary information -- we're safe at this point. | ||
143 | 114 | series_id = request.vars.series_id | ||
144 | 115 | |||
145 | 116 | # first solely check the series exists. | ||
146 | 117 | series = db(db.survey_series.id == series_id).select().first() | ||
147 | 118 | if not series: | ||
148 | 119 | response.error = T("A survey series with id %s does not exist. Please go back and create one.") % (series_id) | ||
149 | 120 | return dict() | ||
150 | 121 | # query for the template to get the table name | ||
151 | 122 | template = db(db.survey_template.id == series.survey_template_id).select().first() | ||
152 | 123 | |||
153 | 124 | |||
154 | 125 | # everything is good at this point! | ||
155 | 126 | table = get_table_for_template(template.id) | ||
156 | 127 | resource = "template_%s" % (template.id) | ||
157 | 128 | table.uuid.requires = IS_NOT_IN_DB(db, "%s.uuid" % template.table_name) | ||
158 | 129 | table.id.represent = lambda id: A(id,_href=URL(r=request,f="table",args=[id,"update"], vars={"series_id":request.vars.series_id})) | ||
159 | 130 | # CRUD Strings | ||
160 | 131 | s3.crud_strings[template.table_name] = Storage( | ||
161 | 132 | title_create = T("Add Survey Answer"), | ||
162 | 133 | title_display = T("Survey Answer Details"), | ||
163 | 134 | title_list = T("List Survey Answers"), | ||
164 | 135 | title_update = T("Edit Survey Answer"), | ||
165 | 136 | subtitle_create = T("Add New Survey Answer"), | ||
166 | 137 | subtitle_list = T("Survey Answer"), | ||
167 | 138 | label_list_button = T("List Survey Answers"), | ||
168 | 139 | label_create_button = T("Add Survey Answer"), | ||
169 | 140 | msg_record_created = T("Survey Answer added"), | ||
170 | 141 | msg_record_modified = T("Survey Answer updated"), | ||
171 | 142 | msg_record_deleted = T("Survey Answer deleted"), | ||
172 | 143 | msg_list_empty = T("No Survey Answers currently registered")) | ||
173 | 144 | response.s3.filter = (table.series_id == series_id) | ||
174 | 145 | output = shn_rest_controller("survey", resource,listadd=False) | ||
175 | 146 | authorised = shn_has_permission("create", table) | ||
176 | 147 | if authorised: | ||
177 | 148 | output.update(add_btn=A(Tstr("Add Survey Answer"), _href=URL(r=request,f="table", args=["create"], vars={"series_id":request.vars.series_id}), | ||
178 | 149 | _class="action-btn")) | ||
179 | 150 | else: | ||
180 | 151 | output.update(add_btn="") | ||
181 | 152 | return output | ||
182 | 153 | |||
183 | 154 | def series(): | ||
184 | 155 | """ RESTlike CRUD controller """ | ||
185 | 156 | resource = "series" | ||
186 | 157 | tablename = "%s_%s" % (module, resource) | ||
187 | 158 | table = db[tablename] | ||
188 | 159 | table.uuid.requires = IS_NOT_IN_DB(db,"%s.uuid" % tablename) | ||
189 | 160 | table.name.requires = IS_NOT_EMPTY() | ||
190 | 161 | table.name.label = T("Survey Series Name") | ||
191 | 162 | table.name.comment = SPAN("*", _class="req") | ||
192 | 163 | table.description.label = T("Description") | ||
193 | 164 | table.survey_template_id.label = T("Survey Template") | ||
194 | 165 | table.survey_template_id.requires = IS_ONE_OF(db, "survey_template.id", "%(name)s") | ||
195 | 166 | table.survey_template_id.represent = lambda id: (id and [db(db.survey_template.id==id).select()[0].name] or [""])[0] | ||
196 | 167 | table.survey_template_id.comment = SPAN("*", _class="req") | ||
197 | 168 | table.from_date.label = T("Start of Period") | ||
198 | 169 | table.from_date.requires = IS_NOT_EMPTY() | ||
199 | 170 | table.from_date.comment = SPAN("*", _class="req") | ||
200 | 171 | table.to_date.label = T("End of Period") | ||
201 | 172 | table.to_date.requires = IS_NOT_EMPTY() | ||
202 | 173 | table.to_date.comment = SPAN("*", _class="req") | ||
203 | 174 | |||
204 | 175 | # CRUD Strings | ||
205 | 176 | s3.crud_strings[tablename] = Storage( | ||
206 | 177 | title_create = T("Add Survey Series"), | ||
207 | 178 | title_display = T("Survey Series Details"), | ||
208 | 179 | title_list = T("List Survey Series"), | ||
209 | 180 | title_update = T("Edit Survey Series"), | ||
210 | 181 | subtitle_create = T("Add New Survey Series"), | ||
211 | 182 | subtitle_list = T("Survey Series"), | ||
212 | 183 | label_list_button = T("List Survey Series"), | ||
213 | 184 | label_create_button = T("Add Survey Series"), | ||
214 | 185 | msg_record_created = T("Survey Series added"), | ||
215 | 186 | msg_record_modified = T("Survey Series updated"), | ||
216 | 187 | msg_record_deleted = T("Survey Series deleted"), | ||
217 | 188 | msg_list_empty = T("No Survey Series currently registered")) | ||
218 | 189 | def _postp(jr, output): | ||
219 | 190 | shn_action_buttons(jr, deletable=False) | ||
220 | 191 | return output | ||
221 | 192 | response.s3.postp = _postp | ||
222 | 193 | |||
223 | 194 | output = shn_rest_controller(module, resource,listadd=False) | ||
224 | 195 | |||
225 | 196 | return output | ||
226 | 197 | |||
227 | 198 | #def section(): | ||
228 | 199 | # """ RESTlike CRUD controller """ | ||
229 | 200 | # resource = "section" | ||
230 | 201 | # tablename = "%s_%s" % (module, resource) | ||
231 | 202 | # table = db[tablename] | ||
232 | 203 | # table.uuid.requires = IS_NOT_IN_DB(db,"%s.uuid" % tablename) | ||
233 | 204 | # table.name.requires = IS_NOT_EMPTY() | ||
234 | 205 | # table.name.comment = SPAN("*", _class="req") | ||
235 | 206 | # table.name.label = T("Survey Section Display Name") | ||
236 | 207 | # table.description.label = T("Description") | ||
237 | 208 | # | ||
238 | 209 | # | ||
239 | 210 | # # CRUD Strings | ||
240 | 211 | # s3.crud_strings[tablename] = Storage( | ||
241 | 212 | # title_create = T("Add Survey Section"), | ||
242 | 213 | # title_display = T("Survey Section Details"), | ||
243 | 214 | # title_list = T("List Survey Sections"), | ||
244 | 215 | # title_update = T("Edit Survey Section"), | ||
245 | 216 | # subtitle_create = T("Add New Survey Section"), | ||
246 | 217 | # subtitle_list = T("Survey Section"), | ||
247 | 218 | # label_list_button = T("List Survey Sections"), | ||
248 | 219 | # label_create_button = T("Add Survey Section"), | ||
249 | 220 | # msg_record_created = T("Survey Section added"), | ||
250 | 221 | # msg_record_modified = T("Survey Section updated"), | ||
251 | 222 | # msg_record_deleted = T("Survey Section deleted"), | ||
252 | 223 | # msg_list_empty = T("No Survey Sections currently registered")) | ||
253 | 224 | # output = shn_rest_controller(module, resource,listadd=False) | ||
254 | 225 | # | ||
255 | 226 | # return transform_buttons(output,save=True,cancel=True) | ||
256 | 227 | |||
257 | 228 | def question(): | ||
258 | 229 | # Question data, e.g., name,description, etc. | ||
259 | 230 | resource = "question" | ||
260 | 231 | tablename = "%s_%s" % (module, resource) | ||
261 | 232 | table = db[tablename] | ||
262 | 233 | table.uuid.requires = IS_NOT_IN_DB(db,"%s.uuid" % tablename) | ||
263 | 234 | table.name.requires = IS_NOT_EMPTY() | ||
264 | 235 | table.name.label = T("Survey Question Display Name") | ||
265 | 236 | table.name.comment = SPAN("*", _class="req") | ||
266 | 237 | table.description.label = T("Description") | ||
267 | 238 | # table.tf_ta_columns.label = T("Number of Columns") | ||
268 | 239 | # table.ta_rows.label = T("Number of Rows") | ||
269 | 240 | # table.aggregation_type.writable = False | ||
270 | 241 | # table.aggregation_type.readable = False | ||
271 | 242 | |||
272 | 243 | question_types = { | ||
273 | 244 | # 1:T("Multiple Choice (Only One Answer)"), | ||
274 | 245 | # 2:T("Multiple Choice (Multiple Answers)"), | ||
275 | 246 | # 3:T("Matrix of Choices (Only one answer)"), | ||
276 | 247 | # 4:T("Matrix of Choices (Multiple Answers)"), | ||
277 | 248 | # 5:T("Rating Scale"), | ||
278 | 249 | 6:T("Text"), | ||
279 | 250 | # 7:T("Multiple Text Fields"), | ||
280 | 251 | # 8:T("Matrix of Text Fields"), | ||
281 | 252 | 9:T("Long Text"), | ||
282 | 253 | 10:T("Number"), | ||
283 | 254 | 11:T("Date"), | ||
284 | 255 | # 12:T("Image"), | ||
285 | 256 | # 13:T("Descriptive Text (e.g., Prose, etc)"), | ||
286 | 257 | # 14:T("Location"), | ||
287 | 258 | # 15:T("Organisation"), | ||
288 | 259 | # 16:T("Person"), | ||
289 | 260 | ## 16:T("Custom Database Resource (e.g., anything defined as a resource in Sahana)") | ||
290 | 261 | } | ||
291 | 262 | |||
292 | 263 | table.question_type.requires = IS_IN_SET(question_types) | ||
293 | 264 | table.question_type.comment = SPAN("*", _class="req") | ||
294 | 265 | # CRUD Strings | ||
295 | 266 | s3.crud_strings[tablename] = Storage( | ||
296 | 267 | title_create = T("Add Survey Question"), | ||
297 | 268 | title_display = T("Survey Question Details"), | ||
298 | 269 | title_list = T("List Survey Questions"), | ||
299 | 270 | title_update = T("Edit Survey Question"), | ||
300 | 271 | subtitle_create = T("Add New Survey Question"), | ||
301 | 272 | subtitle_list = T("Survey Question'"), | ||
302 | 273 | label_list_button = T("List Survey Questions"), | ||
303 | 274 | label_create_button = T("Add Survey Question"), | ||
304 | 275 | msg_record_created = T("Survey Question added"), | ||
305 | 276 | msg_record_modified = T("Survey Question updated"), | ||
306 | 277 | msg_record_deleted = T("Survey Question deleted"), | ||
307 | 278 | msg_list_empty = T("No Survey Questions currently registered")) | ||
308 | 279 | output = shn_rest_controller(module, resource,listadd=False) | ||
309 | 280 | |||
310 | 281 | return transform_buttons(output,cancel=True,save=True) | ||
311 | 282 | |||
312 | 283 | #def question_options(): | ||
313 | 284 | # resource = "question" | ||
314 | 285 | # tablename = "%s_%s" % (module, resource) | ||
315 | 286 | # table = db[tablename] | ||
316 | 287 | # table.uuid.requires = IS_NOT_IN_DB(db,"%s.uuid" % tablename) | ||
317 | 288 | # table.tf_ta_columns.label = T("Number of Columns") | ||
318 | 289 | # table.ta_rows.label = T("Number of Rows") | ||
319 | 290 | ## table.answer_choices.label = T("Answer Choices (One Per Line)") | ||
320 | 291 | # table.aggregation_type.writable = False | ||
321 | 292 | # table.aggregation_type.readable = False | ||
322 | 293 | ## table.row_choices.label = T("Row Choices (One Per Line)") | ||
323 | 294 | ## table.column_choices.label = T("Column Choices (One Per Line") | ||
324 | 295 | ## table.tf_choices.label = T("Text before each Text Field (One per line)") | ||
325 | 296 | # output = shn_rest_controller(module, resource,listadd=False) | ||
326 | 297 | # output.update(question_type=question_type) | ||
327 | 298 | # return transform_buttons(output,prev=True,finish=True,cancel=True) | ||
328 | 299 | |||
329 | 300 | def add_buttons(form, save = None, prev = None, next = None, finish = None,cancel=None): | ||
330 | 301 | """ | ||
331 | 302 | Utility Function to reduce code duplication as this deals with: | ||
332 | 303 | |||
333 | 304 | 1) removing the save button | ||
334 | 305 | 2) adding the following: Cancel, Next, Previous and Finish(shown on the last step *ONLY*) | ||
335 | 306 | """ | ||
336 | 307 | form[0][-1][1][0] = "" # remove the original Save Button | ||
337 | 308 | if save: | ||
338 | 309 | form[-1][-1][1].append(INPUT(_type="submit",_name = "save",_value=T("Save"), _id="save")) | ||
339 | 310 | |||
340 | 311 | if cancel: | ||
341 | 312 | form[-1][-1][1].append(INPUT(_type="button",_name = "cancel",_value=T("Cancel"), _id="cancel")) | ||
342 | 313 | |||
343 | 314 | if prev: | ||
344 | 315 | form[-1][-1][1].append(INPUT(_type="submit",_name = "prev",_value=T("Previous"), _id="prev")) | ||
345 | 316 | |||
346 | 317 | if next: | ||
347 | 318 | form[-1][-1][1].append(INPUT(_type="submit", _value=T("Next"),_name="next",_id="next")) | ||
348 | 319 | |||
349 | 320 | if finish: | ||
350 | 321 | form[-1][-1][1].append(INPUT(_type="submit", _value=T("Finish"),_name="finish",_id="finish")) | ||
351 | 322 | return form | ||
352 | 323 | |||
353 | 324 | def transform_buttons(output,save = None, prev = None, next = None, finish = None,cancel=None): | ||
354 | 325 | # fails when output is not HTML (e.g., JSON) | ||
355 | 326 | if isinstance(output, dict): | ||
356 | 327 | form = output.get("form",None) | ||
357 | 328 | if form: | ||
358 | 329 | add_buttons(form,save,prev,next,finish,cancel) | ||
359 | 330 | return output | ||
360 | 331 | |||
361 | 332 | def has_dupe_questions(template_id,question_id): | ||
362 | 333 | question_query = (db.survey_template_link.survey_template_id == template_id) \ | ||
363 | 334 | & (question_id == db.survey_template_link.survey_question_id) | ||
364 | 335 | questions = db(question_query).select(db.survey_question.ALL) | ||
365 | 336 | if len(questions) > 1: | ||
366 | 337 | |||
367 | 338 | return True | ||
368 | 339 | else: | ||
369 | 340 | return False | ||
370 | 341 | |||
371 | 342 | def prune_questions(questions_id, questions,all_questions): | ||
372 | 343 | if not questions_id: | ||
373 | 344 | return # do nothing | ||
374 | 345 | if not questions: | ||
375 | 346 | return # nothing to act on. | ||
376 | 347 | for question in all_questions: | ||
377 | 348 | if not question in questions: | ||
378 | 349 | question_query = (db.survey_template_link.survey_questions_id == questions_id) \ | ||
379 | 350 | & (question.id == db.survey_template_link.survey_question_id) | ||
380 | 351 | db(question_query).delete() | ||
381 | 352 | db.commit() | ||
382 | 353 | return questions | ||
383 | 354 | |||
384 | 355 | def get_contained_questions(questions_id): | ||
385 | 356 | question_query = (db.survey_template_link.survey_questions_id == questions_id) & \ | ||
386 | 357 | (db.survey_question.id == db.survey_template_link.survey_question_id) & \ | ||
387 | 358 | (db.survey_template.id == db.survey_template_link.survey_template_id) | ||
388 | 359 | contained_questions = db(question_query).select(db.survey_question.ALL) | ||
389 | 360 | return contained_questions | ||
390 | 361 | |||
391 | 362 | def get_table_for_template(template_id): | ||
392 | 363 | """ Returns the table for the given template and if it doesn't exist -- creates and returns that""" | ||
393 | 364 | |||
394 | 365 | # get the template first -- we need to get the table name | ||
395 | 366 | template = db(db.survey_template.id == template_id).select().first() | ||
396 | 367 | |||
397 | 368 | tbl = None | ||
398 | 369 | |||
399 | 370 | if template: # avoid blow ups! | ||
400 | 371 | fields = [Field("series_id", db.survey_series, writable=False, readable=False) | ||
401 | 372 | ] # A list of Fields representing the questions | ||
402 | 373 | |||
403 | 374 | questions = db((db.survey_template_link.survey_template_id == template_id) & \ | ||
404 | 375 | (db.survey_question.id == db.survey_template_link.survey_question_id)).select(db.survey_question.ALL) | ||
405 | 376 | # for each question, depending on its type create a Field | ||
406 | 377 | for question in questions: | ||
407 | 378 | question_type = question.question_type | ||
408 | 379 | |||
409 | 380 | if question_type == 6: # Single TF -- simple for now -- will introduce more types later. | ||
410 | 381 | fields.append(Field("question_%s" % (question.id), label=question.name)) | ||
411 | 382 | |||
412 | 383 | |||
413 | 384 | elif question_type == 9: | ||
414 | 385 | fields.append(Field("question_%s" % (question.id), "text", label=question.name)) | ||
415 | 386 | |||
416 | 387 | elif question_type == 10: | ||
417 | 388 | fields.append(Field("question_%s" % (question.id), "integer", label=question.name)) | ||
418 | 389 | |||
419 | 390 | elif question_type == 11: | ||
420 | 391 | fields.append(Field("question_%s" % (question.id), "date", label=question.name)) | ||
421 | 392 | |||
422 | 393 | tbl = db.define_table("survey_template_%s" % (template_id), uuidstamp, deletion_status, authorstamp, | ||
423 | 394 | *fields, migrate=True) | ||
424 | 395 | # now add the table name to the template record so we can reference it later. | ||
425 | 396 | db(db.survey_template.id == template_id).update(table_name="survey_template_%s" % (template.id)) | ||
426 | 397 | db.commit() | ||
427 | 398 | |||
428 | 399 | # set up onaccept for this table. | ||
429 | 400 | def _onaccept(form): | ||
430 | 401 | db(tbl.id == form.vars.id).update(series_id=request.vars.series_id) | ||
431 | 402 | db.commit() | ||
432 | 403 | |||
433 | 404 | s3xrc.model.configure(tbl, | ||
434 | 405 | onaccept=lambda form: _onaccept(form)) | ||
435 | 406 | # finally we return the newly created or existing table. | ||
436 | 407 | return tbl | ||
437 | 408 | |||
438 | 409 | def shn_action_buttons(jr, deletable=True): | ||
439 | 410 | |||
440 | 411 | """ Provide the usual Action Buttons for Column views. Designed to be called from a postp """ | ||
441 | 412 | |||
442 | 413 | if jr.component: | ||
443 | 414 | args = [jr.component_name, "[id]"] | ||
444 | 415 | else: | ||
445 | 416 | args = ["[id]"] | ||
446 | 417 | if auth.is_logged_in(): | ||
447 | 418 | # Provide the ability to delete records in bulk | ||
448 | 419 | if deletable: | ||
449 | 420 | response.s3.actions = [ | ||
450 | 421 | dict(label=str(UPDATE), _class="action-btn", url=str(URL(r=request, args = args + ["update"]))), | ||
451 | 422 | dict(label=str(DELETE), _class="action-btn", url=str(URL(r=request, args = args + ["delete"]))) | ||
452 | 423 | ] | ||
453 | 424 | else: | ||
454 | 425 | url = URL(r=request,f="table",vars= {"series_id":args}) | ||
455 | 426 | response.s3.actions = [ | ||
456 | 427 | dict(label=str(UPDATE), _class="action-btn", url=str(URL(r=request, args = args + ["update"]))), | ||
457 | 428 | dict(label="Answer", _class="action-btn", url=str( URL(r=request,f="table",args="create", vars= {"series_id":"[id]"}))), | ||
458 | 429 | dict(label="Results", _class="action-btn", url=str( URL(r=request,f="table",vars= {"series_id":"[id]"}))) ] | ||
459 | 430 | else: | ||
460 | 431 | response.s3.actions = [ | ||
461 | 432 | dict(label=str(READ), _class="action-btn", url=str(URL(r=request, args = args))) | ||
462 | 433 | ] | ||
463 | 434 | |||
464 | 435 | return | ||
465 | 436 | #def get_options_for_questions(template_id): | ||
466 | 437 | # questions = db((db.survey_template_link.survey_template_id == template_id) & \ | ||
467 | 438 | # (db.survey_question.id == db.survey_template_link.survey_question_id)).select(db.survey_question.ALL) | ||
468 | 439 | # opt_map = {} | ||
469 | 440 | # for question in questions: | ||
470 | 441 | # question_type = question.question_type | ||
471 | 442 | # if question_type == 6: # Single TF -- simple for now -- will introduce more types later. | ||
472 | 443 | # opt_map[question.id] = {"allow_comments":question.allow_comments,\ | ||
473 | 444 | # "comment_display_label":question.comment_display_label,\ | ||
474 | 445 | # "required":question.required} | ||
475 | 446 | # | ||
476 | 447 | # elif question_type == 9: | ||
477 | 448 | # opt_map[question.id] = { "allow_comments":question.allow_comments,\ | ||
478 | 449 | # "comment_display_label":question.comment_display_label,\ | ||
479 | 450 | # "required":question.required} | ||
480 | 451 | # elif question_type == 10: | ||
481 | 452 | # opt_map[question.id] = {"allow_comments":question.allow_comments,\ | ||
482 | 453 | # "comment_display_label":question.comment_display_label,\ | ||
483 | 454 | # "required":question.required} | ||
484 | 455 | # | ||
485 | 456 | # elif question_type == 11: | ||
486 | 457 | # opt_map[question.id] = {"allow_comments":question.allow_comments,\ | ||
487 | 458 | # "comment_display_label":question.comment_display_label,\ | ||
488 | 459 | # "required":question.required} | ||
489 | 460 | # return opt_map | ||
490 | 0 | \ No newline at end of file | 461 | \ No newline at end of file |
491 | 1 | 462 | ||
492 | === modified file 'models/000_config.py' | |||
493 | --- models/000_config.py 2010-09-02 00:15:55 +0000 | |||
494 | +++ models/000_config.py 2010-09-02 01:18:42 +0000 | |||
495 | @@ -1,288 +1,295 @@ | |||
496 | 1 | # -*- coding: utf-8 -*- | ||
497 | 2 | |||
498 | 3 | """ | ||
499 | 4 | Deployment settings | ||
500 | 5 | All settings which are typically edited for a deployment should be done here | ||
501 | 6 | Deployers shouldn't typically need to edit any other files. | ||
502 | 7 | """ | ||
503 | 8 | |||
504 | 9 | def Tstr(text): | ||
505 | 10 | """ | ||
506 | 11 | Convenience function for non-Web2Py modules | ||
507 | 12 | (latest web2py no longer needs this) | ||
508 | 13 | """ | ||
509 | 14 | return str(T(text)) | ||
510 | 15 | |||
511 | 16 | s3cfg = local_import("s3cfg") | ||
512 | 17 | deployment_settings = s3cfg.S3Config(T) | ||
513 | 18 | |||
514 | 19 | # Database settings | ||
515 | 20 | deployment_settings.database.db_type = "sqlite" | ||
516 | 21 | deployment_settings.database.host = "localhost" | ||
517 | 22 | deployment_settings.database.port = "" # use default | ||
518 | 23 | deployment_settings.database.database = "sahana" | ||
519 | 24 | deployment_settings.database.username = "sahana" | ||
520 | 25 | deployment_settings.database.password = "password" | ||
521 | 26 | deployment_settings.database.pool_size = 30 | ||
522 | 27 | |||
523 | 28 | # Authentication settings | ||
524 | 29 | # This setting should be changed _before_ registering the 1st user | ||
525 | 30 | deployment_settings.auth.hmac_key = "akeytochange" | ||
526 | 31 | # These settings should be changed _after_ the 1st (admin) user is | ||
527 | 32 | # registered in order to secure the deployment | ||
528 | 33 | deployment_settings.auth.registration_requires_verification = False | ||
529 | 34 | deployment_settings.auth.registration_requires_approval = False | ||
530 | 35 | deployment_settings.auth.openid = False | ||
531 | 36 | |||
532 | 37 | # Base settings | ||
533 | 38 | # Set this to the Public URL of the instance | ||
534 | 39 | deployment_settings.base.public_url = "http://127.0.0.1:8000" | ||
535 | 40 | |||
536 | 41 | # Switch to "False" in Production for a Performance gain | ||
537 | 42 | # (need to set to "True" again when Table definitions are changed) | ||
538 | 43 | deployment_settings.base.migrate = True | ||
539 | 44 | |||
540 | 45 | # Enable/disable pre-population of the database. | ||
541 | 46 | # Set to False during first run for manual DB migration in case this | ||
542 | 47 | # is explicitly required for a code upgrade, otherwise leave at True | ||
543 | 48 | # NOTE: the web UI will not be accessible while the DB is empty, | ||
544 | 49 | # instead run: | ||
545 | 50 | # python web2py.py -S eden -M | ||
546 | 51 | # to create the db structure, then exit and re-import the data. | ||
547 | 52 | deployment_settings.base.prepopulate = True | ||
548 | 53 | |||
549 | 54 | # Email settings | ||
550 | 55 | # Outbound server | ||
551 | 56 | deployment_settings.mail.server = "127.0.0.1:25" | ||
552 | 57 | # Useful for Windows Laptops: | ||
553 | 58 | #deployment_settings.mail.server = "smtp.gmail.com:587" | ||
554 | 59 | #deployment_settings.mail.login = "username:password" | ||
555 | 60 | # From Address | ||
556 | 61 | deployment_settings.mail.sender = "'Sahana' <sahana@your.org>" | ||
557 | 62 | # Address to which mails get sent to approve new users | ||
558 | 63 | deployment_settings.mail.approver = "useradmin@your.org" | ||
559 | 64 | |||
560 | 65 | # L10n settings | ||
561 | 66 | # Uncomment this if the deployment is just in a few countries | ||
562 | 67 | # (used in the GIS Location Selector & maybe in future: Messaging) | ||
563 | 68 | #deployment_settings.L10n.countries = ["PK"] | ||
564 | 69 | # Languages used in the deployment (used for Language Toolbar & GIS Locations) | ||
565 | 70 | # http://www.loc.gov/standards/iso639-2/php/code_list.php | ||
566 | 71 | deployment_settings.L10n.languages = { | ||
567 | 72 | "en":T("English"), | ||
568 | 73 | "es":T("Spanish"), | ||
569 | 74 | "pa":T("Punjabi"), | ||
570 | 75 | "ps":T("Pashto"), | ||
571 | 76 | "sd":T("Sindhi"), | ||
572 | 77 | "ur":T("Urdu"), | ||
573 | 78 | "zh-tw":T("Chinese (Taiwan)"), | ||
574 | 79 | "seraiki":T("Seraiki"), | ||
575 | 80 | "balochi":T("Balochi"), | ||
576 | 81 | } | ||
577 | 82 | # Default language for Language Toolbar (& GIS Locations in future) | ||
578 | 83 | deployment_settings.L10n.default_language = "en" | ||
579 | 84 | # Display the language toolbar | ||
580 | 85 | deployment_settings.L10n.display_toolbar = True | ||
581 | 86 | # Default timezone for users | ||
582 | 87 | deployment_settings.L10n.utc_offset = "UTC +0000" | ||
583 | 88 | |||
584 | 89 | # GIS (Map) settings | ||
585 | 90 | # Provide a tool to select locations via a map on all forms with location_id | ||
586 | 91 | deployment_settings.gis.map_selector = True | ||
587 | 92 | # Display Resources recorded to Admin-Level Locations on the map | ||
588 | 93 | deployment_settings.gis.display_L0 = False | ||
589 | 94 | # Currently unused | ||
590 | 95 | #deployment_settings.gis.display_L1 = True | ||
591 | 96 | # Allow non-MapAdmins to edit Admin locations? | ||
592 | 97 | # (defaults to True, if not set) | ||
593 | 98 | deployment_settings.gis.edit_L0 = False | ||
594 | 99 | deployment_settings.gis.edit_L1 = True | ||
595 | 100 | #deployment_settings.gis.edit_L2 = True | ||
596 | 101 | deployment_settings.gis.locations_hierarchy = { | ||
597 | 102 | "L0":T("Country"), | ||
598 | 103 | "L1":T("Province"), | ||
599 | 104 | "L2":T("District"), | ||
600 | 105 | "L3":T("Town"), | ||
601 | 106 | "L4":T("Village") | ||
602 | 107 | } | ||
603 | 108 | # Do we have a spatial DB available? (currently unused. Will support PostGIS & Spatialite.) | ||
604 | 109 | deployment_settings.gis.spatialdb = False | ||
605 | 110 | # GeoServer (currently unused. Will allow REST control of GeoServer.) | ||
606 | 111 | deployment_settings.gis.geoserver_url = "http://localhost/geoserver" | ||
607 | 112 | deployment_settings.gis.geoserver_username = "admin" | ||
608 | 113 | deployment_settings.gis.geoserver_password = "password" | ||
609 | 114 | |||
610 | 115 | |||
611 | 116 | # Security Policy settings | ||
612 | 117 | # Lock-down access to Map Editing | ||
613 | 118 | #deployment_settings.security.map = True | ||
614 | 119 | # Currently unused | ||
615 | 120 | #deployment_settings.security.policy = 2 # Editor | ||
616 | 121 | |||
617 | 122 | # Comment/uncomment modules here to disable/enable them | ||
618 | 123 | # Modules menu is defined in 01_menu.py | ||
619 | 124 | from gluon.storage import Storage | ||
620 | 125 | deployment_settings.modules = Storage( | ||
621 | 126 | default = Storage( | ||
622 | 127 | name_nice = Tstr("Home"), | ||
623 | 128 | access = None, # All Users (inc Anonymous) can see this module in the default menu & access the controller | ||
624 | 129 | module_type = 0 # This item is always 1st in the menu | ||
625 | 130 | ), | ||
626 | 131 | admin = Storage( | ||
627 | 132 | name_nice = Tstr("Administration"), | ||
628 | 133 | description = Tstr("Site Administration"), | ||
629 | 134 | access = "|1|", # Only Administrators can see this module in the default menu & access the controller | ||
630 | 135 | module_type = 0 # This item is handled separately in the menu | ||
631 | 136 | ), | ||
632 | 137 | gis = Storage( | ||
633 | 138 | name_nice = Tstr("Map"), | ||
634 | 139 | description = Tstr("Situation Awareness & Geospatial Analysis"), | ||
635 | 140 | module_type = 1, # 1st item in the menu | ||
636 | 141 | resources = Storage( | ||
637 | 142 | gis_location = {'importer' : True} | ||
638 | 143 | ) | ||
639 | 144 | ), | ||
640 | 145 | mpr = Storage( | ||
641 | 146 | name_nice = Tstr("Missing Persons"), | ||
642 | 147 | description = Tstr("Helps to report and search for Missing Persons"), | ||
643 | 148 | module_type = 2, | ||
644 | 149 | ), | ||
645 | 150 | rms = Storage( | ||
646 | 151 | name_nice = Tstr("Requests"), | ||
647 | 152 | description = Tstr("Tracks requests for aid and matches them against donors who have pledged aid"), | ||
648 | 153 | module_type = 3, | ||
649 | 154 | resources = Storage( | ||
650 | 155 | rms_req = {'importer' : True}, | ||
651 | 156 | ) | ||
652 | 157 | ), | ||
653 | 158 | hms = Storage( | ||
654 | 159 | name_nice = Tstr("Hospitals"), | ||
655 | 160 | description = Tstr("Helps to monitor status of hospitals"), | ||
656 | 161 | module_type = 4, | ||
657 | 162 | resources = Storage( | ||
658 | 163 | hms_hospital = {'importer' : True} | ||
659 | 164 | ) | ||
660 | 165 | ), | ||
661 | 166 | vol = Storage( | ||
662 | 167 | name_nice = Tstr("Volunteers"), | ||
663 | 168 | description = Tstr("Manage volunteers by capturing their skills, availability and allocation"), | ||
664 | 169 | module_type = 5, | ||
665 | 170 | ), | ||
666 | 171 | logs = Storage( | ||
667 | 172 | name_nice = Tstr("Logistics Management"), | ||
668 | 173 | description = Tstr("Managing, Storing and Distributing Relief Items"), | ||
669 | 174 | module_type = 10 | ||
670 | 175 | ), | ||
671 | 176 | project = Storage( | ||
672 | 177 | name_nice = Tstr("Project Management"), | ||
673 | 178 | description = Tstr("Project Activities"), | ||
674 | 179 | module_type = 10 | ||
675 | 180 | ), | ||
676 | 181 | msg = Storage( | ||
677 | 182 | name_nice = Tstr("Messaging"), | ||
678 | 183 | description = Tstr("Sends & Receives Alerts via Email & SMS"), | ||
679 | 184 | module_type = 10, | ||
680 | 185 | ), | ||
681 | 186 | flood = Storage( | ||
682 | 187 | name_nice = Tstr("Flood Alerts"), | ||
683 | 188 | description = Tstr("Flood Alerts show water levels in various parts of the country"), | ||
684 | 189 | module_type = 10 | ||
685 | 190 | ), | ||
686 | 191 | sitrep = Storage( | ||
687 | 192 | name_nice = Tstr("Assessments"), | ||
688 | 193 | description = Tstr("Assessments are structured reports done by Professional Organisations - data includes WFP Assessments"), | ||
689 | 194 | module_type = 10 | ||
690 | 195 | ), | ||
691 | 196 | rat = Storage( | ||
692 | 197 | name_nice = Tstr("Rapid Assessments"), | ||
693 | 198 | description = Tstr("Assessments are structured reports done by Professional Organisations"), | ||
694 | 199 | module_type = 10 | ||
695 | 200 | ), | ||
696 | 201 | pr = Storage( | ||
697 | 202 | name_nice = Tstr("Person Registry"), | ||
698 | 203 | description = Tstr("Central point to record details on People"), | ||
699 | 204 | module_type = 10, | ||
700 | 205 | resources = Storage( | ||
701 | 206 | pr_address = {'importer' : True}, | ||
702 | 207 | pr_pe_contact = {'importer' : True}, | ||
703 | 208 | pr_presence = {'importer' : True}, | ||
704 | 209 | pr_identity = {'importer' : True}, | ||
705 | 210 | pr_person = {'importer' : True}, | ||
706 | 211 | pr_group = {'importer' : True}, | ||
707 | 212 | pr_group_membership = {'importer' : True}, | ||
708 | 213 | ) | ||
709 | 214 | ), | ||
710 | 215 | dvi = Storage( | ||
711 | 216 | name_nice = Tstr("Disaster Victim Identification"), | ||
712 | 217 | description = Tstr("Disaster Victim Identification"), | ||
713 | 218 | module_type = 10, | ||
714 | 219 | resources = Storage( | ||
715 | 220 | dvi_recreq = {'importer' : True}, | ||
716 | 221 | ) | ||
717 | 222 | ), | ||
718 | 223 | #dvr = Storage( | ||
719 | 224 | # name_nice = Tstr("Disaster Victim Registry"), | ||
720 | 225 | # description = Tstr("Traces internally displaced people (IDPs) and their needs"), | ||
721 | 226 | # module_type = 10 | ||
722 | 227 | # ), | ||
723 | 228 | budget = Storage( | ||
724 | 229 | name_nice = Tstr("Budgeting Module"), | ||
725 | 230 | description = Tstr("Allows a Budget to be drawn up"), | ||
726 | 231 | module_type = 10, | ||
727 | 232 | resources = Storage( | ||
728 | 233 | budget_item = {'importer' : True}, | ||
729 | 234 | budget_kit = {'importer' : True}, | ||
730 | 235 | budget_bundle = {'importer' : True}, | ||
731 | 236 | ) | ||
732 | 237 | ), | ||
733 | 238 | cr = Storage( | ||
734 | 239 | name_nice = Tstr("Shelter Registry"), | ||
735 | 240 | description = Tstr("Tracks the location, distibution, capacity and breakdown of victims in Shelters"), | ||
736 | 241 | module_type = 10, | ||
737 | 242 | resources = Storage( | ||
738 | 243 | cr_shelter = {'importer' : True } | ||
739 | 244 | ) | ||
740 | 245 | ), | ||
741 | 246 | delphi = Storage( | ||
742 | 247 | name_nice = Tstr("Delphi Decision Maker"), | ||
743 | 248 | description = Tstr("Supports the decision making of large groups of Crisis Management Experts by helping the groups create ranked list."), | ||
744 | 249 | module_type = 10, | ||
745 | 250 | ), | ||
746 | 251 | doc = Storage( | ||
747 | 252 | name_nice = Tstr("Documents and Photos"), | ||
748 | 253 | description = Tstr("A library of digital resources, such as photos, documents and reports"), | ||
749 | 254 | module_type = 10, | ||
750 | 255 | ), | ||
751 | 256 | irs = Storage( | ||
752 | 257 | name_nice = Tstr("Incident Reporting"), | ||
753 | 258 | description = Tstr("Incident Reporting System"), | ||
754 | 259 | module_type = 10 | ||
755 | 260 | ), | ||
756 | 261 | org = Storage( | ||
757 | 262 | name_nice = Tstr("Organization Registry"), | ||
758 | 263 | description = Tstr('Lists "who is doing what & where". Allows relief agencies to coordinate their activities'), | ||
759 | 264 | module_type = 10, | ||
760 | 265 | resources = Storage( | ||
761 | 266 | org_organisation = {'importer' : True}, | ||
762 | 267 | org_office = {'importer' : True}, | ||
763 | 268 | org_project = {'importer' : True}, | ||
764 | 269 | org_staff = {'importer' : True}, | ||
765 | 270 | org_task = {'importer' : True} | ||
766 | 271 | ) | ||
767 | 272 | ), | ||
768 | 273 | ticket = Storage( | ||
769 | 274 | name_nice = Tstr("Ticketing Module"), | ||
770 | 275 | description = Tstr("Master Message Log to process incoming reports & requests"), | ||
771 | 276 | module_type = 10, | ||
772 | 277 | ), | ||
773 | 278 | importer = Storage( | ||
774 | 279 | name_nice = "Spreadsheet Importer", | ||
775 | 280 | description = "Used to import data from spreadsheets into the database", | ||
776 | 281 | module_type = 10, | ||
777 | 282 | ) | ||
778 | 283 | #lms = Storage( | ||
779 | 284 | # name_nice = Tstr("Logistics Management System"), | ||
780 | 285 | # description = Tstr("An intake system, a warehouse management system, commodity tracking, supply chain management, procurement and other asset and resource management capabilities."), | ||
781 | 286 | # module_type = 10 | ||
782 | 287 | # ), | ||
783 | 288 | ) | ||
784 | 289 | \ No newline at end of file | 1 | \ No newline at end of file |
785 | 2 | |||
786 | 3 | # -*- coding: utf-8 -*- | ||
787 | 4 | |||
788 | 5 | """ | ||
789 | 6 | Deployment settings | ||
790 | 7 | All settings which are typically edited for a deployment should be done here | ||
791 | 8 | Deployers shouldn't typically need to edit any other files. | ||
792 | 9 | """ | ||
793 | 10 | |||
794 | 11 | def Tstr(text): | ||
795 | 12 | """ | ||
796 | 13 | Convenience function for non-Web2Py modules | ||
797 | 14 | (latest web2py no longer needs this) | ||
798 | 15 | """ | ||
799 | 16 | return str(T(text)) | ||
800 | 17 | |||
801 | 18 | s3cfg = local_import("s3cfg") | ||
802 | 19 | deployment_settings = s3cfg.S3Config(T) | ||
803 | 20 | |||
804 | 21 | # Database settings | ||
805 | 22 | deployment_settings.database.db_type = "sqlite" | ||
806 | 23 | deployment_settings.database.host = "localhost" | ||
807 | 24 | deployment_settings.database.port = "" # use default | ||
808 | 25 | deployment_settings.database.database = "sahana" | ||
809 | 26 | deployment_settings.database.username = "sahana" | ||
810 | 27 | deployment_settings.database.password = "password" | ||
811 | 28 | deployment_settings.database.pool_size = 30 | ||
812 | 29 | |||
813 | 30 | # Authentication settings | ||
814 | 31 | # This setting should be changed _before_ registering the 1st user | ||
815 | 32 | deployment_settings.auth.hmac_key = "akeytochange" | ||
816 | 33 | # These settings should be changed _after_ the 1st (admin) user is | ||
817 | 34 | # registered in order to secure the deployment | ||
818 | 35 | deployment_settings.auth.registration_requires_verification = False | ||
819 | 36 | deployment_settings.auth.registration_requires_approval = False | ||
820 | 37 | deployment_settings.auth.openid = False | ||
821 | 38 | |||
822 | 39 | # Base settings | ||
823 | 40 | # Set this to the Public URL of the instance | ||
824 | 41 | deployment_settings.base.public_url = "http://127.0.0.1:8000" | ||
825 | 42 | |||
826 | 43 | # Switch to "False" in Production for a Performance gain | ||
827 | 44 | # (need to set to "True" again when Table definitions are changed) | ||
828 | 45 | deployment_settings.base.migrate = True | ||
829 | 46 | |||
830 | 47 | # Enable/disable pre-population of the database. | ||
831 | 48 | # Set to False during first run for manual DB migration in case this | ||
832 | 49 | # is explicitly required for a code upgrade, otherwise leave at True | ||
833 | 50 | # NOTE: the web UI will not be accessible while the DB is empty, | ||
834 | 51 | # instead run: | ||
835 | 52 | # python web2py.py -S eden -M | ||
836 | 53 | # to create the db structure, then exit and re-import the data. | ||
837 | 54 | deployment_settings.base.prepopulate = True | ||
838 | 55 | |||
839 | 56 | # Email settings | ||
840 | 57 | # Outbound server | ||
841 | 58 | deployment_settings.mail.server = "127.0.0.1:25" | ||
842 | 59 | # Useful for Windows Laptops: | ||
843 | 60 | #deployment_settings.mail.server = "smtp.gmail.com:587" | ||
844 | 61 | #deployment_settings.mail.login = "username:password" | ||
845 | 62 | # From Address | ||
846 | 63 | deployment_settings.mail.sender = "'Sahana' <sahana@your.org>" | ||
847 | 64 | # Address to which mails get sent to approve new users | ||
848 | 65 | deployment_settings.mail.approver = "useradmin@your.org" | ||
849 | 66 | |||
850 | 67 | # L10n settings | ||
851 | 68 | # Uncomment this if the deployment is just in a few countries | ||
852 | 69 | # (used in the GIS Location Selector & maybe in future: Messaging) | ||
853 | 70 | #deployment_settings.L10n.countries = ["PK"] | ||
854 | 71 | # Languages used in the deployment (used for Language Toolbar & GIS Locations) | ||
855 | 72 | # http://www.loc.gov/standards/iso639-2/php/code_list.php | ||
856 | 73 | deployment_settings.L10n.languages = { | ||
857 | 74 | "en":T("English"), | ||
858 | 75 | "es":T("Spanish"), | ||
859 | 76 | "pa":T("Punjabi"), | ||
860 | 77 | "ps":T("Pashto"), | ||
861 | 78 | "sd":T("Sindhi"), | ||
862 | 79 | "ur":T("Urdu"), | ||
863 | 80 | "zh-tw":T("Chinese (Taiwan)"), | ||
864 | 81 | "seraiki":T("Seraiki"), | ||
865 | 82 | "balochi":T("Balochi"), | ||
866 | 83 | } | ||
867 | 84 | # Default language for Language Toolbar (& GIS Locations in future) | ||
868 | 85 | deployment_settings.L10n.default_language = "en" | ||
869 | 86 | # Display the language toolbar | ||
870 | 87 | deployment_settings.L10n.display_toolbar = True | ||
871 | 88 | # Default timezone for users | ||
872 | 89 | deployment_settings.L10n.utc_offset = "UTC +0000" | ||
873 | 90 | |||
874 | 91 | # GIS (Map) settings | ||
875 | 92 | # Provide a tool to select locations via a map on all forms with location_id | ||
876 | 93 | deployment_settings.gis.map_selector = True | ||
877 | 94 | # Display Resources recorded to Admin-Level Locations on the map | ||
878 | 95 | deployment_settings.gis.display_L0 = False | ||
879 | 96 | # Currently unused | ||
880 | 97 | #deployment_settings.gis.display_L1 = True | ||
881 | 98 | # Allow non-MapAdmins to edit Admin locations? | ||
882 | 99 | # (defaults to True, if not set) | ||
883 | 100 | deployment_settings.gis.edit_L0 = False | ||
884 | 101 | deployment_settings.gis.edit_L1 = True | ||
885 | 102 | #deployment_settings.gis.edit_L2 = True | ||
886 | 103 | deployment_settings.gis.locations_hierarchy = { | ||
887 | 104 | "L0":T("Country"), | ||
888 | 105 | "L1":T("Province"), | ||
889 | 106 | "L2":T("District"), | ||
890 | 107 | "L3":T("Town"), | ||
891 | 108 | "L4":T("Village") | ||
892 | 109 | } | ||
893 | 110 | # Do we have a spatial DB available? (currently unused. Will support PostGIS & Spatialite.) | ||
894 | 111 | deployment_settings.gis.spatialdb = False | ||
895 | 112 | # GeoServer (currently unused. Will allow REST control of GeoServer.) | ||
896 | 113 | deployment_settings.gis.geoserver_url = "http://localhost/geoserver" | ||
897 | 114 | deployment_settings.gis.geoserver_username = "admin" | ||
898 | 115 | deployment_settings.gis.geoserver_password = "password" | ||
899 | 116 | |||
900 | 117 | |||
901 | 118 | # Security Policy settings | ||
902 | 119 | # Lock-down access to Map Editing | ||
903 | 120 | #deployment_settings.security.map = True | ||
904 | 121 | # Currently unused | ||
905 | 122 | #deployment_settings.security.policy = 2 # Editor | ||
906 | 123 | |||
907 | 124 | # Comment/uncomment modules here to disable/enable them | ||
908 | 125 | # Modules menu is defined in 01_menu.py | ||
909 | 126 | from gluon.storage import Storage | ||
910 | 127 | deployment_settings.modules = Storage( | ||
911 | 128 | default = Storage( | ||
912 | 129 | name_nice = Tstr("Home"), | ||
913 | 130 | access = None, # All Users (inc Anonymous) can see this module in the default menu & access the controller | ||
914 | 131 | module_type = 0 # This item is always 1st in the menu | ||
915 | 132 | ), | ||
916 | 133 | admin = Storage( | ||
917 | 134 | name_nice = Tstr("Administration"), | ||
918 | 135 | description = Tstr("Site Administration"), | ||
919 | 136 | access = "|1|", # Only Administrators can see this module in the default menu & access the controller | ||
920 | 137 | module_type = 0 # This item is handled separately in the menu | ||
921 | 138 | ), | ||
922 | 139 | gis = Storage( | ||
923 | 140 | name_nice = Tstr("Map"), | ||
924 | 141 | description = Tstr("Situation Awareness & Geospatial Analysis"), | ||
925 | 142 | module_type = 1, # 1st item in the menu | ||
926 | 143 | resources = Storage( | ||
927 | 144 | gis_location = {'importer' : True} | ||
928 | 145 | ) | ||
929 | 146 | ), | ||
930 | 147 | mpr = Storage( | ||
931 | 148 | name_nice = Tstr("Missing Persons"), | ||
932 | 149 | description = Tstr("Helps to report and search for Missing Persons"), | ||
933 | 150 | module_type = 2, | ||
934 | 151 | ), | ||
935 | 152 | rms = Storage( | ||
936 | 153 | name_nice = Tstr("Requests"), | ||
937 | 154 | description = Tstr("Tracks requests for aid and matches them against donors who have pledged aid"), | ||
938 | 155 | module_type = 3, | ||
939 | 156 | resources = Storage( | ||
940 | 157 | rms_req = {'importer' : True}, | ||
941 | 158 | ) | ||
942 | 159 | ), | ||
943 | 160 | hms = Storage( | ||
944 | 161 | name_nice = Tstr("Hospitals"), | ||
945 | 162 | description = Tstr("Helps to monitor status of hospitals"), | ||
946 | 163 | module_type = 4, | ||
947 | 164 | resources = Storage( | ||
948 | 165 | hms_hospital = {'importer' : True} | ||
949 | 166 | ) | ||
950 | 167 | ), | ||
951 | 168 | vol = Storage( | ||
952 | 169 | name_nice = Tstr("Volunteers"), | ||
953 | 170 | description = Tstr("Manage volunteers by capturing their skills, availability and allocation"), | ||
954 | 171 | module_type = 5, | ||
955 | 172 | ), | ||
956 | 173 | logs = Storage( | ||
957 | 174 | name_nice = Tstr("Logistics Management"), | ||
958 | 175 | description = Tstr("Managing, Storing and Distributing Relief Items"), | ||
959 | 176 | module_type = 10 | ||
960 | 177 | ), | ||
961 | 178 | project = Storage( | ||
962 | 179 | name_nice = Tstr("Project Management"), | ||
963 | 180 | description = Tstr("Project Activities"), | ||
964 | 181 | module_type = 10 | ||
965 | 182 | ), | ||
966 | 183 | msg = Storage( | ||
967 | 184 | name_nice = Tstr("Messaging"), | ||
968 | 185 | description = Tstr("Sends & Receives Alerts via Email & SMS"), | ||
969 | 186 | module_type = 10, | ||
970 | 187 | ), | ||
971 | 188 | flood = Storage( | ||
972 | 189 | name_nice = Tstr("Flood Alerts"), | ||
973 | 190 | description = Tstr("Flood Alerts show water levels in various parts of the country"), | ||
974 | 191 | module_type = 10 | ||
975 | 192 | ), | ||
976 | 193 | sitrep = Storage( | ||
977 | 194 | name_nice = Tstr("Assessments"), | ||
978 | 195 | description = Tstr("Assessments are structured reports done by Professional Organisations - data includes WFP Assessments"), | ||
979 | 196 | module_type = 10 | ||
980 | 197 | ), | ||
981 | 198 | rat = Storage( | ||
982 | 199 | name_nice = Tstr("Rapid Assessments"), | ||
983 | 200 | description = Tstr("Assessments are structured reports done by Professional Organisations"), | ||
984 | 201 | module_type = 10 | ||
985 | 202 | ), | ||
986 | 203 | pr = Storage( | ||
987 | 204 | name_nice = Tstr("Person Registry"), | ||
988 | 205 | description = Tstr("Central point to record details on People"), | ||
989 | 206 | module_type = 10, | ||
990 | 207 | resources = Storage( | ||
991 | 208 | pr_address = {'importer' : True}, | ||
992 | 209 | pr_pe_contact = {'importer' : True}, | ||
993 | 210 | pr_presence = {'importer' : True}, | ||
994 | 211 | pr_identity = {'importer' : True}, | ||
995 | 212 | pr_person = {'importer' : True}, | ||
996 | 213 | pr_group = {'importer' : True}, | ||
997 | 214 | pr_group_membership = {'importer' : True}, | ||
998 | 215 | ) | ||
999 | 216 | ), | ||
1000 | 217 | dvi = Storage( | ||
1001 | 218 | name_nice = Tstr("Disaster Victim Identification"), | ||
1002 | 219 | description = Tstr("Disaster Victim Identification"), | ||
1003 | 220 | module_type = 10, | ||
1004 | 221 | resources = Storage( | ||
1005 | 222 | dvi_recreq = {'importer' : True}, | ||
1006 | 223 | ) | ||
1007 | 224 | ), | ||
1008 | 225 | #dvr = Storage( | ||
1009 | 226 | # name_nice = Tstr("Disaster Victim Registry"), | ||
1010 | 227 | # description = Tstr("Traces internally displaced people (IDPs) and their needs"), | ||
1011 | 228 | # module_type = 10 | ||
1012 | 229 | # ), | ||
1013 | 230 | budget = Storage( | ||
1014 | 231 | name_nice = Tstr("Budgeting Module"), | ||
1015 | 232 | description = Tstr("Allows a Budget to be drawn up"), | ||
1016 | 233 | module_type = 10, | ||
1017 | 234 | resources = Storage( | ||
1018 | 235 | budget_item = {'importer' : True}, | ||
1019 | 236 | budget_kit = {'importer' : True}, | ||
1020 | 237 | budget_bundle = {'importer' : True}, | ||
1021 | 238 | ) | ||
1022 | 239 | ), | ||
1023 | 240 | cr = Storage( | ||
1024 | 241 | name_nice = Tstr("Shelter Registry"), | ||
1025 | 242 | description = Tstr("Tracks the location, distibution, capacity and breakdown of victims in Shelters"), | ||
1026 | 243 | module_type = 10, | ||
1027 | 244 | resources = Storage( | ||
1028 | 245 | cr_shelter = {'importer' : True } | ||
1029 | 246 | ) | ||
1030 | 247 | ), | ||
1031 | 248 | delphi = Storage( | ||
1032 | 249 | name_nice = Tstr("Delphi Decision Maker"), | ||
1033 | 250 | description = Tstr("Supports the decision making of large groups of Crisis Management Experts by helping the groups create ranked list."), | ||
1034 | 251 | module_type = 10, | ||
1035 | 252 | ), | ||
1036 | 253 | doc = Storage( | ||
1037 | 254 | name_nice = Tstr("Documents and Photos"), | ||
1038 | 255 | description = Tstr("A library of digital resources, such as photos, documents and reports"), | ||
1039 | 256 | module_type = 10, | ||
1040 | 257 | ), | ||
1041 | 258 | irs = Storage( | ||
1042 | 259 | name_nice = Tstr("Incident Reporting"), | ||
1043 | 260 | description = Tstr("Incident Reporting System"), | ||
1044 | 261 | module_type = 10 | ||
1045 | 262 | ), | ||
1046 | 263 | org = Storage( | ||
1047 | 264 | name_nice = Tstr("Organization Registry"), | ||
1048 | 265 | description = Tstr('Lists "who is doing what & where". Allows relief agencies to coordinate their activities'), | ||
1049 | 266 | module_type = 10, | ||
1050 | 267 | resources = Storage( | ||
1051 | 268 | org_organisation = {'importer' : True}, | ||
1052 | 269 | org_office = {'importer' : True}, | ||
1053 | 270 | org_project = {'importer' : True}, | ||
1054 | 271 | org_staff = {'importer' : True}, | ||
1055 | 272 | org_task = {'importer' : True} | ||
1056 | 273 | ) | ||
1057 | 274 | ), | ||
1058 | 275 | ticket = Storage( | ||
1059 | 276 | name_nice = Tstr("Ticketing Module"), | ||
1060 | 277 | description = Tstr("Master Message Log to process incoming reports & requests"), | ||
1061 | 278 | module_type = 10, | ||
1062 | 279 | ), | ||
1063 | 280 | importer = Storage( | ||
1064 | 281 | name_nice = "Spreadsheet Importer", | ||
1065 | 282 | description = "Used to import data from spreadsheets into the database", | ||
1066 | 283 | module_type = 10, | ||
1067 | 284 | ), | ||
1068 | 285 | survey = Storage( | ||
1069 | 286 | name_nice = "Survey Module", | ||
1070 | 287 | description = "Create, enter, and manage surveys.", | ||
1071 | 288 | module_type = 10, | ||
1072 | 289 | ) | ||
1073 | 290 | |||
1074 | 291 | #lms = Storage( | ||
1075 | 292 | # name_nice = Tstr("Logistics Management System"), | ||
1076 | 293 | # description = Tstr("An intake system, a warehouse management system, commodity tracking, supply chain management, procurement and other asset and resource management capabilities."), | ||
1077 | 294 | # module_type = 10 | ||
1078 | 295 | # ), | ||
1079 | 296 | ) | ||
1080 | 290 | 297 | ||
1081 | === modified file 'models/msg.py' (properties changed: +x to -x) | |||
1082 | === added file 'models/survey.py' | |||
1083 | --- models/survey.py 1970-01-01 00:00:00 +0000 | |||
1084 | +++ models/survey.py 2010-09-02 01:18:42 +0000 | |||
1085 | @@ -0,0 +1,142 @@ | |||
1086 | 1 | # -*- coding: utf-8 -*- | ||
1087 | 2 | |||
1088 | 3 | """ | ||
1089 | 4 | Survey Module | ||
1090 | 5 | |||
1091 | 6 | @author: Robert O'Connor | ||
1092 | 7 | """ | ||
1093 | 8 | |||
1094 | 9 | module = "survey" | ||
1095 | 10 | |||
1096 | 11 | from gluon.sqlhtml import * | ||
1097 | 12 | |||
1098 | 13 | |||
1099 | 14 | ADD_LOCATION = T("Add Location") | ||
1100 | 15 | repr_select = lambda l: len(l.name) > 48 and "%s..." % l.name[:44] or l.name | ||
1101 | 16 | location_id = db.Table(None, "location_id", | ||
1102 | 17 | FieldS3("location_id", db.gis_location, sortby="name", | ||
1103 | 18 | requires = IS_NULL_OR(IS_ONE_OF(db, "gis_location.id", repr_select, sort=True)), | ||
1104 | 19 | represent = lambda id: shn_gis_location_represent(id), | ||
1105 | 20 | label = T("Location"), | ||
1106 | 21 | comment = DIV(SPAN("* ", _class="req"),A(ADD_LOCATION, | ||
1107 | 22 | _class="colorbox", | ||
1108 | 23 | _href=URL(r=request, c="gis", f="location", args="create", vars=dict(format="popup")), | ||
1109 | 24 | _target="top", | ||
1110 | 25 | _title=ADD_LOCATION), | ||
1111 | 26 | DIV( _class="tooltip", | ||
1112 | 27 | _title=Tstr("Location") + "|" + Tstr("The Location of this Site, which can be general (for Reporting) or precise (for displaying on a Map)."))), | ||
1113 | 28 | ondelete = "RESTRICT")) | ||
1114 | 29 | |||
1115 | 30 | s3xrc.model.configure(db.gis_location, | ||
1116 | 31 | onvalidation=lambda form: gis.wkt_centroid(form), | ||
1117 | 32 | onaccept=gis.update_location_tree()) | ||
1118 | 33 | |||
1119 | 34 | |||
1120 | 35 | if deployment_settings.has_module(module): | ||
1121 | 36 | |||
1122 | 37 | #Reusable table | ||
1123 | 38 | name_desc = db.Table(db,timestamp, uuidstamp, deletion_status, authorstamp, | ||
1124 | 39 | Field("name", "string", default="", length=120), | ||
1125 | 40 | Field("description", "text", default="",length=500)) | ||
1126 | 41 | |||
1127 | 42 | #Survey Template | ||
1128 | 43 | resource = "template" | ||
1129 | 44 | tablename = module + "_" + resource | ||
1130 | 45 | template = db.define_table(tablename,name_desc, | ||
1131 | 46 | Field("table_name","string",readable=False,writable=False), | ||
1132 | 47 | Field("locked","boolean",readable=False,writable=False), | ||
1133 | 48 | person_id, | ||
1134 | 49 | organisation_id) | ||
1135 | 50 | |||
1136 | 51 | # Survey Series | ||
1137 | 52 | resource = "series" | ||
1138 | 53 | tablename = module + "_" + resource | ||
1139 | 54 | series = db.define_table(tablename,name_desc, | ||
1140 | 55 | Field("survey_template_id", db.survey_template), | ||
1141 | 56 | Field("from_date", "date", default=None), | ||
1142 | 57 | Field("to_date","date",default=None), | ||
1143 | 58 | location_id) | ||
1144 | 59 | |||
1145 | 60 | # Survey Section | ||
1146 | 61 | resource = "questions" | ||
1147 | 62 | tablename = module +"_" + resource | ||
1148 | 63 | section = db.define_table(tablename,uuidstamp,deletion_status,authorstamp) | ||
1149 | 64 | |||
1150 | 65 | # # Question options e.g., Row choices, Column Choices, Layout Configuration data, etc... | ||
1151 | 66 | # resource = "question_options" | ||
1152 | 67 | # tablename = module +"_" + resource | ||
1153 | 68 | # question_options = db.define_table(tablename,uuidstamp,deletion_status,authorstamp, | ||
1154 | 69 | ## # Field("display_option","integer"), | ||
1155 | 70 | ### Field("answer_choices","text",length=700), | ||
1156 | 71 | ### Field("row_choices","text"), # row choices | ||
1157 | 72 | ### Field("column_choices","text"), # column choices | ||
1158 | 73 | ## Field("tf_choices","text"), # text before the text fields. | ||
1159 | 74 | # Field("tf_ta_columns","integer"), # number of columns for TF/TA | ||
1160 | 75 | # Field("ta_rows","integer"), # number of rows for text areas | ||
1161 | 76 | ### Field("number_of_options","integer"), | ||
1162 | 77 | # Field("allow_comments","boolean"), # whether or not to allow comments | ||
1163 | 78 | # Field("comment_display_label"), # the label for the comment field | ||
1164 | 79 | # Field("required","boolean"), # marks the question as required | ||
1165 | 80 | ## Field("validate","boolean"), # whether or not to enable validation | ||
1166 | 81 | ### Field("validation_options","integer"), # pre-set validation regexps and such. | ||
1167 | 82 | # Field("aggregation_type","string")) | ||
1168 | 83 | |||
1169 | 84 | # Survey Question | ||
1170 | 85 | resource = "question" | ||
1171 | 86 | tablename = module +"_" + resource | ||
1172 | 87 | question = db.define_table(tablename,timestamp, uuidstamp, deletion_status, authorstamp, | ||
1173 | 88 | Field("name", "string", default="", length=120), | ||
1174 | 89 | Field("question_type","integer"), | ||
1175 | 90 | Field("description", "text", default="",length=500)) | ||
1176 | 91 | # Field("options_id",db.survey_question_options), | ||
1177 | 92 | # Field("tf_ta_columns","integer"), # number of columns for TF/TA | ||
1178 | 93 | # Field("ta_rows","integer"), # number of rows for text areas | ||
1179 | 94 | # Field("allow_comments","boolean"), # whether or not to allow comments | ||
1180 | 95 | # Field("comment_display_label"), # the label for the comment field | ||
1181 | 96 | # Field("required","boolean"), # marks the question as required | ||
1182 | 97 | # Field("aggregation_type","string")) | ||
1183 | 98 | |||
1184 | 99 | |||
1185 | 100 | # #Survey Instance | ||
1186 | 101 | # resource = "instance" | ||
1187 | 102 | # tablename = module +"_" + resource | ||
1188 | 103 | # instance = db.define_table(tablename,timestamp, uuidstamp, deletion_status, authorstamp, | ||
1189 | 104 | # Field("survey_series_id",db.survey_series)) | ||
1190 | 105 | |||
1191 | 106 | # # Survey Answer | ||
1192 | 107 | # resource = "answer" | ||
1193 | 108 | # tablename = module +"_" + resource | ||
1194 | 109 | # answer = db.define_table(tablename,timestamp, uuidstamp, deletion_status, authorstamp, | ||
1195 | 110 | # Field("survey_instance_id",db.survey_instance), | ||
1196 | 111 | # Field("question_id",db.survey_question), | ||
1197 | 112 | # Field("answer_value","text",length=600), | ||
1198 | 113 | # Field("answer_image","upload"), # store the image if "Image" is selected. | ||
1199 | 114 | # Field("answer_location",db.gis_location), | ||
1200 | 115 | # Field("answer_person",db.pr_person), | ||
1201 | 116 | # Field("answer_organisation",db.org_organisation)) | ||
1202 | 117 | |||
1203 | 118 | # Link table | ||
1204 | 119 | resource = "template_link" | ||
1205 | 120 | tablename = module +"_" + resource | ||
1206 | 121 | link_table = db.define_table(tablename,timestamp, uuidstamp, deletion_status, authorstamp, | ||
1207 | 122 | Field("survey_question_id",db.survey_question), | ||
1208 | 123 | Field("survey_template_id", db.survey_template), | ||
1209 | 124 | Field("survey_questions_id", db.survey_questions)) | ||
1210 | 125 | link_table.survey_question_id.requires =IS_NULL_OR(IS_ONE_OF(db, "survey_question.id", "%(name)s")) | ||
1211 | 126 | |||
1212 | 127 | |||
1213 | 128 | # def question_options_onaccept(form): | ||
1214 | 129 | # if form.vars.id and session.rcvars.survey_question: | ||
1215 | 130 | # table = db.survey_question_options | ||
1216 | 131 | # opts = db(table.id == form.vars.id).update(question_id=session.rcvars.survey_question) | ||
1217 | 132 | # db.commit() | ||
1218 | 133 | # | ||
1219 | 134 | # s3xrc.model.configure(db.survey_question_options, | ||
1220 | 135 | # onaccept=lambda form: question_options_onaccept(form)) | ||
1221 | 136 | |||
1222 | 137 | # def question_onaccept(form): | ||
1223 | 138 | # if form.vars.id and session.rcvars.survey_section and session.rcvars.survey_template: | ||
1224 | 139 | # db.survey_template_link_table.insert(survey_section_id=session.rcvars.survey_section, survey_template_id=session.rcvars.survey_template) | ||
1225 | 140 | # db.commit() | ||
1226 | 141 | # s3xrc.model.configure(db.survey_question, | ||
1227 | 142 | # onaccept=lambda form: question_onaccept(form)) | ||
1228 | 0 | \ No newline at end of file | 143 | \ No newline at end of file |
1229 | 1 | 144 | ||
1230 | === modified file 'modules/validators.py' | |||
1231 | --- modules/validators.py 2010-08-15 21:47:42 +0000 | |||
1232 | +++ modules/validators.py 2010-09-02 01:18:42 +0000 | |||
1233 | @@ -489,4 +489,4 @@ | |||
1234 | 489 | 489 | ||
1235 | 490 | def formatter(self, value): | 490 | def formatter(self, value): |
1236 | 491 | # Always format with trailing UTC offset | 491 | # Always format with trailing UTC offset |
1238 | 492 | return value.strftime(str(self.format)) + " +0000" | 492 | return value.strftime(str(self.format)) + " +0000" |
1239 | 493 | \ No newline at end of file | 493 | \ No newline at end of file |
1240 | 494 | 494 | ||
1241 | === modified file 'modules/widgets.py' | |||
1242 | --- modules/widgets.py 2010-08-25 11:30:41 +0000 | |||
1243 | +++ modules/widgets.py 2010-09-02 01:18:42 +0000 | |||
1244 | @@ -619,4 +619,4 @@ | |||
1245 | 619 | else: | 619 | else: |
1246 | 620 | return_value = return_value | 620 | return_value = return_value |
1247 | 621 | 621 | ||
1249 | 622 | return return_value | 622 | return return_value |
1250 | 623 | \ No newline at end of file | 623 | \ No newline at end of file |
1251 | 624 | 624 | ||
1252 | === added directory 'static/img/tango' | |||
1253 | === added file 'static/img/tango/down.png' | |||
1254 | 625 | Binary files static/img/tango/down.png 1970-01-01 00:00:00 +0000 and static/img/tango/down.png 2010-09-02 01:18:42 +0000 differ | 625 | Binary files static/img/tango/down.png 1970-01-01 00:00:00 +0000 and static/img/tango/down.png 2010-09-02 01:18:42 +0000 differ |
1255 | === added file 'static/img/tango/minus.png' | |||
1256 | 626 | Binary files static/img/tango/minus.png 1970-01-01 00:00:00 +0000 and static/img/tango/minus.png 2010-09-02 01:18:42 +0000 differ | 626 | Binary files static/img/tango/minus.png 1970-01-01 00:00:00 +0000 and static/img/tango/minus.png 2010-09-02 01:18:42 +0000 differ |
1257 | === added file 'static/img/tango/plus.png' | |||
1258 | 627 | Binary files static/img/tango/plus.png 1970-01-01 00:00:00 +0000 and static/img/tango/plus.png 2010-09-02 01:18:42 +0000 differ | 627 | Binary files static/img/tango/plus.png 1970-01-01 00:00:00 +0000 and static/img/tango/plus.png 2010-09-02 01:18:42 +0000 differ |
1259 | === added file 'static/img/tango/up.png' | |||
1260 | 628 | Binary files static/img/tango/up.png 1970-01-01 00:00:00 +0000 and static/img/tango/up.png 2010-09-02 01:18:42 +0000 differ | 628 | Binary files static/img/tango/up.png 1970-01-01 00:00:00 +0000 and static/img/tango/up.png 2010-09-02 01:18:42 +0000 differ |
1261 | === modified file 'static/scripts/S3/S3.js' (properties changed: +x to -x) | |||
1262 | === added directory 'static/scripts/survey' | |||
1263 | === added file 'static/scripts/survey/jquery-ui-1.8.4.custom.js' | |||
1264 | --- static/scripts/survey/jquery-ui-1.8.4.custom.js 1970-01-01 00:00:00 +0000 | |||
1265 | +++ static/scripts/survey/jquery-ui-1.8.4.custom.js 2010-09-02 01:18:42 +0000 | |||
1266 | @@ -0,0 +1,11241 @@ | |||
1267 | 1 | /*! | ||
1268 | 2 | * jQuery UI 1.8.4 | ||
1269 | 3 | * | ||
1270 | 4 | * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about) | ||
1271 | 5 | * Dual licensed under the MIT or GPL Version 2 licenses. | ||
1272 | 6 | * http://jquery.org/license | ||
1273 | 7 | * | ||
1274 | 8 | * http://docs.jquery.com/UI | ||
1275 | 9 | */ | ||
1276 | 10 | (function( $, undefined ) { | ||
1277 | 11 | |||
1278 | 12 | // prevent duplicate loading | ||
1279 | 13 | // this is only a problem because we proxy existing functions | ||
1280 | 14 | // and we don't want to double proxy them | ||
1281 | 15 | $.ui = $.ui || {}; | ||
1282 | 16 | if ( $.ui.version ) { | ||
1283 | 17 | return; | ||
1284 | 18 | } | ||
1285 | 19 | |||
1286 | 20 | //Helper functions and ui object | ||
1287 | 21 | $.extend( $.ui, { | ||
1288 | 22 | version: "1.8.4", | ||
1289 | 23 | |||
1290 | 24 | // $.ui.plugin is deprecated. Use the proxy pattern instead. | ||
1291 | 25 | plugin: { | ||
1292 | 26 | add: function( module, option, set ) { | ||
1293 | 27 | var proto = $.ui[ module ].prototype; | ||
1294 | 28 | for ( var i in set ) { | ||
1295 | 29 | proto.plugins[ i ] = proto.plugins[ i ] || []; | ||
1296 | 30 | proto.plugins[ i ].push( [ option, set[ i ] ] ); | ||
1297 | 31 | } | ||
1298 | 32 | }, | ||
1299 | 33 | call: function( instance, name, args ) { | ||
1300 | 34 | var set = instance.plugins[ name ]; | ||
1301 | 35 | if ( !set || !instance.element[ 0 ].parentNode ) { | ||
1302 | 36 | return; | ||
1303 | 37 | } | ||
1304 | 38 | |||
1305 | 39 | for ( var i = 0; i < set.length; i++ ) { | ||
1306 | 40 | if ( instance.options[ set[ i ][ 0 ] ] ) { | ||
1307 | 41 | set[ i ][ 1 ].apply( instance.element, args ); | ||
1308 | 42 | } | ||
1309 | 43 | } | ||
1310 | 44 | } | ||
1311 | 45 | }, | ||
1312 | 46 | |||
1313 | 47 | contains: function( a, b ) { | ||
1314 | 48 | return document.compareDocumentPosition ? | ||
1315 | 49 | a.compareDocumentPosition( b ) & 16 : | ||
1316 | 50 | a !== b && a.contains( b ); | ||
1317 | 51 | }, | ||
1318 | 52 | |||
1319 | 53 | hasScroll: function( el, a ) { | ||
1320 | 54 | |||
1321 | 55 | //If overflow is hidden, the element might have extra content, but the user wants to hide it | ||
1322 | 56 | if ( $( el ).css( "overflow" ) === "hidden") { | ||
1323 | 57 | return false; | ||
1324 | 58 | } | ||
1325 | 59 | |||
1326 | 60 | var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop", | ||
1327 | 61 | has = false; | ||
1328 | 62 | |||
1329 | 63 | if ( el[ scroll ] > 0 ) { | ||
1330 | 64 | return true; | ||
1331 | 65 | } | ||
1332 | 66 | |||
1333 | 67 | // TODO: determine which cases actually cause this to happen | ||
1334 | 68 | // if the element doesn't have the scroll set, see if it's possible to | ||
1335 | 69 | // set the scroll | ||
1336 | 70 | el[ scroll ] = 1; | ||
1337 | 71 | has = ( el[ scroll ] > 0 ); | ||
1338 | 72 | el[ scroll ] = 0; | ||
1339 | 73 | return has; | ||
1340 | 74 | }, | ||
1341 | 75 | |||
1342 | 76 | isOverAxis: function( x, reference, size ) { | ||
1343 | 77 | //Determines when x coordinate is over "b" element axis | ||
1344 | 78 | return ( x > reference ) && ( x < ( reference + size ) ); | ||
1345 | 79 | }, | ||
1346 | 80 | |||
1347 | 81 | isOver: function( y, x, top, left, height, width ) { | ||
1348 | 82 | //Determines when x, y coordinates is over "b" element | ||
1349 | 83 | return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width ); | ||
1350 | 84 | }, | ||
1351 | 85 | |||
1352 | 86 | keyCode: { | ||
1353 | 87 | ALT: 18, | ||
1354 | 88 | BACKSPACE: 8, | ||
1355 | 89 | CAPS_LOCK: 20, | ||
1356 | 90 | COMMA: 188, | ||
1357 | 91 | COMMAND: 91, | ||
1358 | 92 | COMMAND_LEFT: 91, // COMMAND | ||
1359 | 93 | COMMAND_RIGHT: 93, | ||
1360 | 94 | CONTROL: 17, | ||
1361 | 95 | DELETE: 46, | ||
1362 | 96 | DOWN: 40, | ||
1363 | 97 | END: 35, | ||
1364 | 98 | ENTER: 13, | ||
1365 | 99 | ESCAPE: 27, | ||
1366 | 100 | HOME: 36, | ||
1367 | 101 | INSERT: 45, | ||
1368 | 102 | LEFT: 37, | ||
1369 | 103 | MENU: 93, // COMMAND_RIGHT | ||
1370 | 104 | NUMPAD_ADD: 107, | ||
1371 | 105 | NUMPAD_DECIMAL: 110, | ||
1372 | 106 | NUMPAD_DIVIDE: 111, | ||
1373 | 107 | NUMPAD_ENTER: 108, | ||
1374 | 108 | NUMPAD_MULTIPLY: 106, | ||
1375 | 109 | NUMPAD_SUBTRACT: 109, | ||
1376 | 110 | PAGE_DOWN: 34, | ||
1377 | 111 | PAGE_UP: 33, | ||
1378 | 112 | PERIOD: 190, | ||
1379 | 113 | RIGHT: 39, | ||
1380 | 114 | SHIFT: 16, | ||
1381 | 115 | SPACE: 32, | ||
1382 | 116 | TAB: 9, | ||
1383 | 117 | UP: 38, | ||
1384 | 118 | WINDOWS: 91 // COMMAND | ||
1385 | 119 | } | ||
1386 | 120 | }); | ||
1387 | 121 | |||
1388 | 122 | //jQuery plugins | ||
1389 | 123 | $.fn.extend({ | ||
1390 | 124 | _focus: $.fn.focus, | ||
1391 | 125 | focus: function( delay, fn ) { | ||
1392 | 126 | return typeof delay === "number" ? | ||
1393 | 127 | this.each(function() { | ||
1394 | 128 | var elem = this; | ||
1395 | 129 | setTimeout(function() { | ||
1396 | 130 | $( elem ).focus(); | ||
1397 | 131 | if ( fn ) { | ||
1398 | 132 | fn.call( elem ); | ||
1399 | 133 | } | ||
1400 | 134 | }, delay ); | ||
1401 | 135 | }) : | ||
1402 | 136 | this._focus.apply( this, arguments ); | ||
1403 | 137 | }, | ||
1404 | 138 | |||
1405 | 139 | enableSelection: function() { | ||
1406 | 140 | return this | ||
1407 | 141 | .attr( "unselectable", "off" ) | ||
1408 | 142 | .css( "MozUserSelect", "" ); | ||
1409 | 143 | }, | ||
1410 | 144 | |||
1411 | 145 | disableSelection: function() { | ||
1412 | 146 | return this | ||
1413 | 147 | .attr( "unselectable", "on" ) | ||
1414 | 148 | .css( "MozUserSelect", "none" ); | ||
1415 | 149 | }, | ||
1416 | 150 | |||
1417 | 151 | scrollParent: function() { | ||
1418 | 152 | var scrollParent; | ||
1419 | 153 | if (($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) { | ||
1420 | 154 | scrollParent = this.parents().filter(function() { | ||
1421 | 155 | return (/(relative|absolute|fixed)/).test($.curCSS(this,'position',1)) && (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1)); | ||
1422 | 156 | }).eq(0); | ||
1423 | 157 | } else { | ||
1424 | 158 | scrollParent = this.parents().filter(function() { | ||
1425 | 159 | return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1)); | ||
1426 | 160 | }).eq(0); | ||
1427 | 161 | } | ||
1428 | 162 | |||
1429 | 163 | return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent; | ||
1430 | 164 | }, | ||
1431 | 165 | |||
1432 | 166 | zIndex: function( zIndex ) { | ||
1433 | 167 | if ( zIndex !== undefined ) { | ||
1434 | 168 | return this.css( "zIndex", zIndex ); | ||
1435 | 169 | } | ||
1436 | 170 | |||
1437 | 171 | if ( this.length ) { | ||
1438 | 172 | var elem = $( this[ 0 ] ), position, value; | ||
1439 | 173 | while ( elem.length && elem[ 0 ] !== document ) { | ||
1440 | 174 | // Ignore z-index if position is set to a value where z-index is ignored by the browser | ||
1441 | 175 | // This makes behavior of this function consistent across browsers | ||
1442 | 176 | // WebKit always returns auto if the element is positioned | ||
1443 | 177 | position = elem.css( "position" ); | ||
1444 | 178 | if ( position === "absolute" || position === "relative" || position === "fixed" ) { | ||
1445 | 179 | // IE returns 0 when zIndex is not specified | ||
1446 | 180 | // other browsers return a string | ||
1447 | 181 | // we ignore the case of nested elements with an explicit value of 0 | ||
1448 | 182 | // <div style="z-index: -10;"><div style="z-index: 0;"></div></div> | ||
1449 | 183 | value = parseInt( elem.css( "zIndex" ) ); | ||
1450 | 184 | if ( !isNaN( value ) && value != 0 ) { | ||
1451 | 185 | return value; | ||
1452 | 186 | } | ||
1453 | 187 | } | ||
1454 | 188 | elem = elem.parent(); | ||
1455 | 189 | } | ||
1456 | 190 | } | ||
1457 | 191 | |||
1458 | 192 | return 0; | ||
1459 | 193 | } | ||
1460 | 194 | }); | ||
1461 | 195 | |||
1462 | 196 | $.each( [ "Width", "Height" ], function( i, name ) { | ||
1463 | 197 | var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ], | ||
1464 | 198 | type = name.toLowerCase(), | ||
1465 | 199 | orig = { | ||
1466 | 200 | innerWidth: $.fn.innerWidth, | ||
1467 | 201 | innerHeight: $.fn.innerHeight, | ||
1468 | 202 | outerWidth: $.fn.outerWidth, | ||
1469 | 203 | outerHeight: $.fn.outerHeight | ||
1470 | 204 | }; | ||
1471 | 205 | |||
1472 | 206 | function reduce( elem, size, border, margin ) { | ||
1473 | 207 | $.each( side, function() { | ||
1474 | 208 | size -= parseFloat( $.curCSS( elem, "padding" + this, true) ) || 0; | ||
1475 | 209 | if ( border ) { | ||
1476 | 210 | size -= parseFloat( $.curCSS( elem, "border" + this + "Width", true) ) || 0; | ||
1477 | 211 | } | ||
1478 | 212 | if ( margin ) { | ||
1479 | 213 | size -= parseFloat( $.curCSS( elem, "margin" + this, true) ) || 0; | ||
1480 | 214 | } | ||
1481 | 215 | }); | ||
1482 | 216 | return size; | ||
1483 | 217 | } | ||
1484 | 218 | |||
1485 | 219 | $.fn[ "inner" + name ] = function( size ) { | ||
1486 | 220 | if ( size === undefined ) { | ||
1487 | 221 | return orig[ "inner" + name ].call( this ); | ||
1488 | 222 | } | ||
1489 | 223 | |||
1490 | 224 | return this.each(function() { | ||
1491 | 225 | $.style( this, type, reduce( this, size ) + "px" ); | ||
1492 | 226 | }); | ||
1493 | 227 | }; | ||
1494 | 228 | |||
1495 | 229 | $.fn[ "outer" + name] = function( size, margin ) { | ||
1496 | 230 | if ( typeof size !== "number" ) { | ||
1497 | 231 | return orig[ "outer" + name ].call( this, size ); | ||
1498 | 232 | } | ||
1499 | 233 | |||
1500 | 234 | return this.each(function() { | ||
1501 | 235 | $.style( this, type, reduce( this, size, true, margin ) + "px" ); | ||
1502 | 236 | }); | ||
1503 | 237 | }; | ||
1504 | 238 | }); | ||
1505 | 239 | |||
1506 | 240 | //Additional selectors | ||
1507 | 241 | function visible( element ) { | ||
1508 | 242 | return !$( element ).parents().andSelf().filter(function() { | ||
1509 | 243 | return $.curCSS( this, "visibility" ) === "hidden" || | ||
1510 | 244 | $.expr.filters.hidden( this ); | ||
1511 | 245 | }).length; | ||
1512 | 246 | } | ||
1513 | 247 | |||
1514 | 248 | $.extend( $.expr[ ":" ], { | ||
1515 | 249 | data: function( elem, i, match ) { | ||
1516 | 250 | return !!$.data( elem, match[ 3 ] ); | ||
1517 | 251 | }, | ||
1518 | 252 | |||
1519 | 253 | focusable: function( element ) { | ||
1520 | 254 | var nodeName = element.nodeName.toLowerCase(), | ||
1521 | 255 | tabIndex = $.attr( element, "tabindex" ); | ||
1522 | 256 | if ( "area" === nodeName ) { | ||
1523 | 257 | var map = element.parentNode, | ||
1524 | 258 | mapName = map.name, | ||
1525 | 259 | img; | ||
1526 | 260 | if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) { | ||
1527 | 261 | return false; | ||
1528 | 262 | } | ||
1529 | 263 | img = $( "img[usemap=#" + mapName + "]" )[0]; | ||
1530 | 264 | return !!img && visible( img ); | ||
1531 | 265 | } | ||
1532 | 266 | return ( /input|select|textarea|button|object/.test( nodeName ) | ||
1533 | 267 | ? !element.disabled | ||
1534 | 268 | : "a" == nodeName | ||
1535 | 269 | ? element.href || !isNaN( tabIndex ) | ||
1536 | 270 | : !isNaN( tabIndex )) | ||
1537 | 271 | // the element and all of its ancestors must be visible | ||
1538 | 272 | && visible( element ); | ||
1539 | 273 | }, | ||
1540 | 274 | |||
1541 | 275 | tabbable: function( element ) { | ||
1542 | 276 | var tabIndex = $.attr( element, "tabindex" ); | ||
1543 | 277 | return ( isNaN( tabIndex ) || tabIndex >= 0 ) && $( element ).is( ":focusable" ); | ||
1544 | 278 | } | ||
1545 | 279 | }); | ||
1546 | 280 | |||
1547 | 281 | })( jQuery ); | ||
1548 | 282 | /*! | ||
1549 | 283 | * jQuery UI Widget 1.8.4 | ||
1550 | 284 | * | ||
1551 | 285 | * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about) | ||
1552 | 286 | * Dual licensed under the MIT or GPL Version 2 licenses. | ||
1553 | 287 | * http://jquery.org/license | ||
1554 | 288 | * | ||
1555 | 289 | * http://docs.jquery.com/UI/Widget | ||
1556 | 290 | */ | ||
1557 | 291 | (function( $, undefined ) { | ||
1558 | 292 | |||
1559 | 293 | var _remove = $.fn.remove; | ||
1560 | 294 | |||
1561 | 295 | $.fn.remove = function( selector, keepData ) { | ||
1562 | 296 | return this.each(function() { | ||
1563 | 297 | if ( !keepData ) { | ||
1564 | 298 | if ( !selector || $.filter( selector, [ this ] ).length ) { | ||
1565 | 299 | $( "*", this ).add( [ this ] ).each(function() { | ||
1566 | 300 | $( this ).triggerHandler( "remove" ); | ||
1567 | 301 | }); | ||
1568 | 302 | } | ||
1569 | 303 | } | ||
1570 | 304 | return _remove.call( $(this), selector, keepData ); | ||
1571 | 305 | }); | ||
1572 | 306 | }; | ||
1573 | 307 | |||
1574 | 308 | $.widget = function( name, base, prototype ) { | ||
1575 | 309 | var namespace = name.split( "." )[ 0 ], | ||
1576 | 310 | fullName; | ||
1577 | 311 | name = name.split( "." )[ 1 ]; | ||
1578 | 312 | fullName = namespace + "-" + name; | ||
1579 | 313 | |||
1580 | 314 | if ( !prototype ) { | ||
1581 | 315 | prototype = base; | ||
1582 | 316 | base = $.Widget; | ||
1583 | 317 | } | ||
1584 | 318 | |||
1585 | 319 | // create selector for plugin | ||
1586 | 320 | $.expr[ ":" ][ fullName ] = function( elem ) { | ||
1587 | 321 | return !!$.data( elem, name ); | ||
1588 | 322 | }; | ||
1589 | 323 | |||
1590 | 324 | $[ namespace ] = $[ namespace ] || {}; | ||
1591 | 325 | $[ namespace ][ name ] = function( options, element ) { | ||
1592 | 326 | // allow instantiation without initializing for simple inheritance | ||
1593 | 327 | if ( arguments.length ) { | ||
1594 | 328 | this._createWidget( options, element ); | ||
1595 | 329 | } | ||
1596 | 330 | }; | ||
1597 | 331 | |||
1598 | 332 | var basePrototype = new base(); | ||
1599 | 333 | // we need to make the options hash a property directly on the new instance | ||
1600 | 334 | // otherwise we'll modify the options hash on the prototype that we're | ||
1601 | 335 | // inheriting from | ||
1602 | 336 | // $.each( basePrototype, function( key, val ) { | ||
1603 | 337 | // if ( $.isPlainObject(val) ) { | ||
1604 | 338 | // basePrototype[ key ] = $.extend( {}, val ); | ||
1605 | 339 | // } | ||
1606 | 340 | // }); | ||
1607 | 341 | basePrototype.options = $.extend( true, {}, basePrototype.options ); | ||
1608 | 342 | $[ namespace ][ name ].prototype = $.extend( true, basePrototype, { | ||
1609 | 343 | namespace: namespace, | ||
1610 | 344 | widgetName: name, | ||
1611 | 345 | widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name, | ||
1612 | 346 | widgetBaseClass: fullName | ||
1613 | 347 | }, prototype ); | ||
1614 | 348 | |||
1615 | 349 | $.widget.bridge( name, $[ namespace ][ name ] ); | ||
1616 | 350 | }; | ||
1617 | 351 | |||
1618 | 352 | $.widget.bridge = function( name, object ) { | ||
1619 | 353 | $.fn[ name ] = function( options ) { | ||
1620 | 354 | var isMethodCall = typeof options === "string", | ||
1621 | 355 | args = Array.prototype.slice.call( arguments, 1 ), | ||
1622 | 356 | returnValue = this; | ||
1623 | 357 | |||
1624 | 358 | // allow multiple hashes to be passed on init | ||
1625 | 359 | options = !isMethodCall && args.length ? | ||
1626 | 360 | $.extend.apply( null, [ true, options ].concat(args) ) : | ||
1627 | 361 | options; | ||
1628 | 362 | |||
1629 | 363 | // prevent calls to internal methods | ||
1630 | 364 | if ( isMethodCall && options.substring( 0, 1 ) === "_" ) { | ||
1631 | 365 | return returnValue; | ||
1632 | 366 | } | ||
1633 | 367 | |||
1634 | 368 | if ( isMethodCall ) { | ||
1635 | 369 | this.each(function() { | ||
1636 | 370 | var instance = $.data( this, name ), | ||
1637 | 371 | methodValue = instance && $.isFunction( instance[options] ) ? | ||
1638 | 372 | instance[ options ].apply( instance, args ) : | ||
1639 | 373 | instance; | ||
1640 | 374 | if ( methodValue !== instance && methodValue !== undefined ) { | ||
1641 | 375 | returnValue = methodValue; | ||
1642 | 376 | return false; | ||
1643 | 377 | } | ||
1644 | 378 | }); | ||
1645 | 379 | } else { | ||
1646 | 380 | this.each(function() { | ||
1647 | 381 | var instance = $.data( this, name ); | ||
1648 | 382 | if ( instance ) { | ||
1649 | 383 | if ( options ) { | ||
1650 | 384 | instance.option( options ); | ||
1651 | 385 | } | ||
1652 | 386 | instance._init(); | ||
1653 | 387 | } else { | ||
1654 | 388 | $.data( this, name, new object( options, this ) ); | ||
1655 | 389 | } | ||
1656 | 390 | }); | ||
1657 | 391 | } | ||
1658 | 392 | |||
1659 | 393 | return returnValue; | ||
1660 | 394 | }; | ||
1661 | 395 | }; | ||
1662 | 396 | |||
1663 | 397 | $.Widget = function( options, element ) { | ||
1664 | 398 | // allow instantiation without initializing for simple inheritance | ||
1665 | 399 | if ( arguments.length ) { | ||
1666 | 400 | this._createWidget( options, element ); | ||
1667 | 401 | } | ||
1668 | 402 | }; | ||
1669 | 403 | |||
1670 | 404 | $.Widget.prototype = { | ||
1671 | 405 | widgetName: "widget", | ||
1672 | 406 | widgetEventPrefix: "", | ||
1673 | 407 | options: { | ||
1674 | 408 | disabled: false | ||
1675 | 409 | }, | ||
1676 | 410 | _createWidget: function( options, element ) { | ||
1677 | 411 | // $.widget.bridge stores the plugin instance, but we do it anyway | ||
1678 | 412 | // so that it's stored even before the _create function runs | ||
1679 | 413 | $.data( element, this.widgetName, this ); | ||
1680 | 414 | this.element = $( element ); | ||
1681 | 415 | this.options = $.extend( true, {}, | ||
1682 | 416 | this.options, | ||
1683 | 417 | $.metadata && $.metadata.get( element )[ this.widgetName ], | ||
1684 | 418 | options ); | ||
1685 | 419 | |||
1686 | 420 | var self = this; | ||
1687 | 421 | this.element.bind( "remove." + this.widgetName, function() { | ||
1688 | 422 | self.destroy(); | ||
1689 | 423 | }); | ||
1690 | 424 | |||
1691 | 425 | this._create(); | ||
1692 | 426 | this._init(); | ||
1693 | 427 | }, | ||
1694 | 428 | _create: function() {}, | ||
1695 | 429 | _init: function() {}, | ||
1696 | 430 | |||
1697 | 431 | destroy: function() { | ||
1698 | 432 | this.element | ||
1699 | 433 | .unbind( "." + this.widgetName ) | ||
1700 | 434 | .removeData( this.widgetName ); | ||
1701 | 435 | this.widget() | ||
1702 | 436 | .unbind( "." + this.widgetName ) | ||
1703 | 437 | .removeAttr( "aria-disabled" ) | ||
1704 | 438 | .removeClass( | ||
1705 | 439 | this.widgetBaseClass + "-disabled " + | ||
1706 | 440 | "ui-state-disabled" ); | ||
1707 | 441 | }, | ||
1708 | 442 | |||
1709 | 443 | widget: function() { | ||
1710 | 444 | return this.element; | ||
1711 | 445 | }, | ||
1712 | 446 | |||
1713 | 447 | option: function( key, value ) { | ||
1714 | 448 | var options = key, | ||
1715 | 449 | self = this; | ||
1716 | 450 | |||
1717 | 451 | if ( arguments.length === 0 ) { | ||
1718 | 452 | // don't return a reference to the internal hash | ||
1719 | 453 | return $.extend( {}, self.options ); | ||
1720 | 454 | } | ||
1721 | 455 | |||
1722 | 456 | if (typeof key === "string" ) { | ||
1723 | 457 | if ( value === undefined ) { | ||
1724 | 458 | return this.options[ key ]; | ||
1725 | 459 | } | ||
1726 | 460 | options = {}; | ||
1727 | 461 | options[ key ] = value; | ||
1728 | 462 | } | ||
1729 | 463 | |||
1730 | 464 | $.each( options, function( key, value ) { | ||
1731 | 465 | self._setOption( key, value ); | ||
1732 | 466 | }); | ||
1733 | 467 | |||
1734 | 468 | return self; | ||
1735 | 469 | }, | ||
1736 | 470 | _setOption: function( key, value ) { | ||
1737 | 471 | this.options[ key ] = value; | ||
1738 | 472 | |||
1739 | 473 | if ( key === "disabled" ) { | ||
1740 | 474 | this.widget() | ||
1741 | 475 | [ value ? "addClass" : "removeClass"]( | ||
1742 | 476 | this.widgetBaseClass + "-disabled" + " " + | ||
1743 | 477 | "ui-state-disabled" ) | ||
1744 | 478 | .attr( "aria-disabled", value ); | ||
1745 | 479 | } | ||
1746 | 480 | |||
1747 | 481 | return this; | ||
1748 | 482 | }, | ||
1749 | 483 | |||
1750 | 484 | enable: function() { | ||
1751 | 485 | return this._setOption( "disabled", false ); | ||
1752 | 486 | }, | ||
1753 | 487 | disable: function() { | ||
1754 | 488 | return this._setOption( "disabled", true ); | ||
1755 | 489 | }, | ||
1756 | 490 | |||
1757 | 491 | _trigger: function( type, event, data ) { | ||
1758 | 492 | var callback = this.options[ type ]; | ||
1759 | 493 | |||
1760 | 494 | event = $.Event( event ); | ||
1761 | 495 | event.type = ( type === this.widgetEventPrefix ? | ||
1762 | 496 | type : | ||
1763 | 497 | this.widgetEventPrefix + type ).toLowerCase(); | ||
1764 | 498 | data = data || {}; | ||
1765 | 499 | |||
1766 | 500 | // copy original event properties over to the new event | ||
1767 | 501 | // this would happen if we could call $.event.fix instead of $.Event | ||
1768 | 502 | // but we don't have a way to force an event to be fixed multiple times | ||
1769 | 503 | if ( event.originalEvent ) { | ||
1770 | 504 | for ( var i = $.event.props.length, prop; i; ) { | ||
1771 | 505 | prop = $.event.props[ --i ]; | ||
1772 | 506 | event[ prop ] = event.originalEvent[ prop ]; | ||
1773 | 507 | } | ||
1774 | 508 | } | ||
1775 | 509 | |||
1776 | 510 | this.element.trigger( event, data ); | ||
1777 | 511 | |||
1778 | 512 | return !( $.isFunction(callback) && | ||
1779 | 513 | callback.call( this.element[0], event, data ) === false || | ||
1780 | 514 | event.isDefaultPrevented() ); | ||
1781 | 515 | } | ||
1782 | 516 | }; | ||
1783 | 517 | |||
1784 | 518 | })( jQuery ); | ||
1785 | 519 | /*! | ||
1786 | 520 | * jQuery UI Mouse 1.8.4 | ||
1787 | 521 | * | ||
1788 | 522 | * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about) | ||
1789 | 523 | * Dual licensed under the MIT or GPL Version 2 licenses. | ||
1790 | 524 | * http://jquery.org/license | ||
1791 | 525 | * | ||
1792 | 526 | * http://docs.jquery.com/UI/Mouse | ||
1793 | 527 | * | ||
1794 | 528 | * Depends: | ||
1795 | 529 | * jquery.ui.widget.js | ||
1796 | 530 | */ | ||
1797 | 531 | (function( $, undefined ) { | ||
1798 | 532 | |||
1799 | 533 | $.widget("ui.mouse", { | ||
1800 | 534 | options: { | ||
1801 | 535 | cancel: ':input,option', | ||
1802 | 536 | distance: 1, | ||
1803 | 537 | delay: 0 | ||
1804 | 538 | }, | ||
1805 | 539 | _mouseInit: function() { | ||
1806 | 540 | var self = this; | ||
1807 | 541 | |||
1808 | 542 | this.element | ||
1809 | 543 | .bind('mousedown.'+this.widgetName, function(event) { | ||
1810 | 544 | return self._mouseDown(event); | ||
1811 | 545 | }) | ||
1812 | 546 | .bind('click.'+this.widgetName, function(event) { | ||
1813 | 547 | if(self._preventClickEvent) { | ||
1814 | 548 | self._preventClickEvent = false; | ||
1815 | 549 | event.stopImmediatePropagation(); | ||
1816 | 550 | return false; | ||
1817 | 551 | } | ||
1818 | 552 | }); | ||
1819 | 553 | |||
1820 | 554 | this.started = false; | ||
1821 | 555 | }, | ||
1822 | 556 | |||
1823 | 557 | // TODO: make sure destroying one instance of mouse doesn't mess with | ||
1824 | 558 | // other instances of mouse | ||
1825 | 559 | _mouseDestroy: function() { | ||
1826 | 560 | this.element.unbind('.'+this.widgetName); | ||
1827 | 561 | }, | ||
1828 | 562 | |||
1829 | 563 | _mouseDown: function(event) { | ||
1830 | 564 | // don't let more than one widget handle mouseStart | ||
1831 | 565 | // TODO: figure out why we have to use originalEvent | ||
1832 | 566 | event.originalEvent = event.originalEvent || {}; | ||
1833 | 567 | if (event.originalEvent.mouseHandled) { return; } | ||
1834 | 568 | |||
1835 | 569 | // we may have missed mouseup (out of window) | ||
1836 | 570 | (this._mouseStarted && this._mouseUp(event)); | ||
1837 | 571 | |||
1838 | 572 | this._mouseDownEvent = event; | ||
1839 | 573 | |||
1840 | 574 | var self = this, | ||
1841 | 575 | btnIsLeft = (event.which == 1), | ||
1842 | 576 | elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false); | ||
1843 | 577 | if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) { | ||
1844 | 578 | return true; | ||
1845 | 579 | } | ||
1846 | 580 | |||
1847 | 581 | this.mouseDelayMet = !this.options.delay; | ||
1848 | 582 | if (!this.mouseDelayMet) { | ||
1849 | 583 | this._mouseDelayTimer = setTimeout(function() { | ||
1850 | 584 | self.mouseDelayMet = true; | ||
1851 | 585 | }, this.options.delay); | ||
1852 | 586 | } | ||
1853 | 587 | |||
1854 | 588 | if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) { | ||
1855 | 589 | this._mouseStarted = (this._mouseStart(event) !== false); | ||
1856 | 590 | if (!this._mouseStarted) { | ||
1857 | 591 | event.preventDefault(); | ||
1858 | 592 | return true; | ||
1859 | 593 | } | ||
1860 | 594 | } | ||
1861 | 595 | |||
1862 | 596 | // these delegates are required to keep context | ||
1863 | 597 | this._mouseMoveDelegate = function(event) { | ||
1864 | 598 | return self._mouseMove(event); | ||
1865 | 599 | }; | ||
1866 | 600 | this._mouseUpDelegate = function(event) { | ||
1867 | 601 | return self._mouseUp(event); | ||
1868 | 602 | }; | ||
1869 | 603 | $(document) | ||
1870 | 604 | .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate) | ||
1871 | 605 | .bind('mouseup.'+this.widgetName, this._mouseUpDelegate); | ||
1872 | 606 | |||
1873 | 607 | // preventDefault() is used to prevent the selection of text here - | ||
1874 | 608 | // however, in Safari, this causes select boxes not to be selectable | ||
1875 | 609 | // anymore, so this fix is needed | ||
1876 | 610 | ($.browser.safari || event.preventDefault()); | ||
1877 | 611 | |||
1878 | 612 | event.originalEvent.mouseHandled = true; | ||
1879 | 613 | return true; | ||
1880 | 614 | }, | ||
1881 | 615 | |||
1882 | 616 | _mouseMove: function(event) { | ||
1883 | 617 | // IE mouseup check - mouseup happened when mouse was out of window | ||
1884 | 618 | if ($.browser.msie && !event.button) { | ||
1885 | 619 | return this._mouseUp(event); | ||
1886 | 620 | } | ||
1887 | 621 | |||
1888 | 622 | if (this._mouseStarted) { | ||
1889 | 623 | this._mouseDrag(event); | ||
1890 | 624 | return event.preventDefault(); | ||
1891 | 625 | } | ||
1892 | 626 | |||
1893 | 627 | if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) { | ||
1894 | 628 | this._mouseStarted = | ||
1895 | 629 | (this._mouseStart(this._mouseDownEvent, event) !== false); | ||
1896 | 630 | (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event)); | ||
1897 | 631 | } | ||
1898 | 632 | |||
1899 | 633 | return !this._mouseStarted; | ||
1900 | 634 | }, | ||
1901 | 635 | |||
1902 | 636 | _mouseUp: function(event) { | ||
1903 | 637 | $(document) | ||
1904 | 638 | .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate) | ||
1905 | 639 | .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate); | ||
1906 | 640 | |||
1907 | 641 | if (this._mouseStarted) { | ||
1908 | 642 | this._mouseStarted = false; | ||
1909 | 643 | this._preventClickEvent = (event.target == this._mouseDownEvent.target); | ||
1910 | 644 | this._mouseStop(event); | ||
1911 | 645 | } | ||
1912 | 646 | |||
1913 | 647 | return false; | ||
1914 | 648 | }, | ||
1915 | 649 | |||
1916 | 650 | _mouseDistanceMet: function(event) { | ||
1917 | 651 | return (Math.max( | ||
1918 | 652 | Math.abs(this._mouseDownEvent.pageX - event.pageX), | ||
1919 | 653 | Math.abs(this._mouseDownEvent.pageY - event.pageY) | ||
1920 | 654 | ) >= this.options.distance | ||
1921 | 655 | ); | ||
1922 | 656 | }, | ||
1923 | 657 | |||
1924 | 658 | _mouseDelayMet: function(event) { | ||
1925 | 659 | return this.mouseDelayMet; | ||
1926 | 660 | }, | ||
1927 | 661 | |||
1928 | 662 | // These are placeholder methods, to be overriden by extending plugin | ||
1929 | 663 | _mouseStart: function(event) {}, | ||
1930 | 664 | _mouseDrag: function(event) {}, | ||
1931 | 665 | _mouseStop: function(event) {}, | ||
1932 | 666 | _mouseCapture: function(event) { return true; } | ||
1933 | 667 | }); | ||
1934 | 668 | |||
1935 | 669 | })(jQuery); | ||
1936 | 670 | /* | ||
1937 | 671 | * jQuery UI Position 1.8.4 | ||
1938 | 672 | * | ||
1939 | 673 | * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about) | ||
1940 | 674 | * Dual licensed under the MIT or GPL Version 2 licenses. | ||
1941 | 675 | * http://jquery.org/license | ||
1942 | 676 | * | ||
1943 | 677 | * http://docs.jquery.com/UI/Position | ||
1944 | 678 | */ | ||
1945 | 679 | (function( $, undefined ) { | ||
1946 | 680 | |||
1947 | 681 | $.ui = $.ui || {}; | ||
1948 | 682 | |||
1949 | 683 | var horizontalPositions = /left|center|right/, | ||
1950 | 684 | horizontalDefault = "center", | ||
1951 | 685 | verticalPositions = /top|center|bottom/, | ||
1952 | 686 | verticalDefault = "center", | ||
1953 | 687 | _position = $.fn.position, | ||
1954 | 688 | _offset = $.fn.offset; | ||
1955 | 689 | |||
1956 | 690 | $.fn.position = function( options ) { | ||
1957 | 691 | if ( !options || !options.of ) { | ||
1958 | 692 | return _position.apply( this, arguments ); | ||
1959 | 693 | } | ||
1960 | 694 | |||
1961 | 695 | // make a copy, we don't want to modify arguments | ||
1962 | 696 | options = $.extend( {}, options ); | ||
1963 | 697 | |||
1964 | 698 | var target = $( options.of ), | ||
1965 | 699 | collision = ( options.collision || "flip" ).split( " " ), | ||
1966 | 700 | offset = options.offset ? options.offset.split( " " ) : [ 0, 0 ], | ||
1967 | 701 | targetWidth, | ||
1968 | 702 | targetHeight, | ||
1969 | 703 | basePosition; | ||
1970 | 704 | |||
1971 | 705 | if ( options.of.nodeType === 9 ) { | ||
1972 | 706 | targetWidth = target.width(); | ||
1973 | 707 | targetHeight = target.height(); | ||
1974 | 708 | basePosition = { top: 0, left: 0 }; | ||
1975 | 709 | } else if ( options.of.scrollTo && options.of.document ) { | ||
1976 | 710 | targetWidth = target.width(); | ||
1977 | 711 | targetHeight = target.height(); | ||
1978 | 712 | basePosition = { top: target.scrollTop(), left: target.scrollLeft() }; | ||
1979 | 713 | } else if ( options.of.preventDefault ) { | ||
1980 | 714 | // force left top to allow flipping | ||
1981 | 715 | options.at = "left top"; | ||
1982 | 716 | targetWidth = targetHeight = 0; | ||
1983 | 717 | basePosition = { top: options.of.pageY, left: options.of.pageX }; | ||
1984 | 718 | } else { | ||
1985 | 719 | targetWidth = target.outerWidth(); | ||
1986 | 720 | targetHeight = target.outerHeight(); | ||
1987 | 721 | basePosition = target.offset(); | ||
1988 | 722 | } | ||
1989 | 723 | |||
1990 | 724 | // force my and at to have valid horizontal and veritcal positions | ||
1991 | 725 | // if a value is missing or invalid, it will be converted to center | ||
1992 | 726 | $.each( [ "my", "at" ], function() { | ||
1993 | 727 | var pos = ( options[this] || "" ).split( " " ); | ||
1994 | 728 | if ( pos.length === 1) { | ||
1995 | 729 | pos = horizontalPositions.test( pos[0] ) ? | ||
1996 | 730 | pos.concat( [verticalDefault] ) : | ||
1997 | 731 | verticalPositions.test( pos[0] ) ? | ||
1998 | 732 | [ horizontalDefault ].concat( pos ) : | ||
1999 | 733 | [ horizontalDefault, verticalDefault ]; | ||
2000 | 734 | } | ||
2001 | 735 | pos[ 0 ] = horizontalPositions.test( pos[0] ) ? pos[ 0 ] : horizontalDefault; | ||
2002 | 736 | pos[ 1 ] = verticalPositions.test( pos[1] ) ? pos[ 1 ] : verticalDefault; | ||
2003 | 737 | options[ this ] = pos; | ||
2004 | 738 | }); | ||
2005 | 739 | |||
2006 | 740 | // normalize collision option | ||
2007 | 741 | if ( collision.length === 1 ) { | ||
2008 | 742 | collision[ 1 ] = collision[ 0 ]; | ||
2009 | 743 | } | ||
2010 | 744 | |||
2011 | 745 | // normalize offset option | ||
2012 | 746 | offset[ 0 ] = parseInt( offset[0], 10 ) || 0; | ||
2013 | 747 | if ( offset.length === 1 ) { | ||
2014 | 748 | offset[ 1 ] = offset[ 0 ]; | ||
2015 | 749 | } | ||
2016 | 750 | offset[ 1 ] = parseInt( offset[1], 10 ) || 0; | ||
2017 | 751 | |||
2018 | 752 | if ( options.at[0] === "right" ) { | ||
2019 | 753 | basePosition.left += targetWidth; | ||
2020 | 754 | } else if (options.at[0] === horizontalDefault ) { | ||
2021 | 755 | basePosition.left += targetWidth / 2; | ||
2022 | 756 | } | ||
2023 | 757 | |||
2024 | 758 | if ( options.at[1] === "bottom" ) { | ||
2025 | 759 | basePosition.top += targetHeight; | ||
2026 | 760 | } else if ( options.at[1] === verticalDefault ) { | ||
2027 | 761 | basePosition.top += targetHeight / 2; | ||
2028 | 762 | } | ||
2029 | 763 | |||
2030 | 764 | basePosition.left += offset[ 0 ]; | ||
2031 | 765 | basePosition.top += offset[ 1 ]; | ||
2032 | 766 | |||
2033 | 767 | return this.each(function() { | ||
2034 | 768 | var elem = $( this ), | ||
2035 | 769 | elemWidth = elem.outerWidth(), | ||
2036 | 770 | elemHeight = elem.outerHeight(), | ||
2037 | 771 | position = $.extend( {}, basePosition ); | ||
2038 | 772 | |||
2039 | 773 | if ( options.my[0] === "right" ) { | ||
2040 | 774 | position.left -= elemWidth; | ||
2041 | 775 | } else if ( options.my[0] === horizontalDefault ) { | ||
2042 | 776 | position.left -= elemWidth / 2; | ||
2043 | 777 | } | ||
2044 | 778 | |||
2045 | 779 | if ( options.my[1] === "bottom" ) { | ||
2046 | 780 | position.top -= elemHeight; | ||
2047 | 781 | } else if ( options.my[1] === verticalDefault ) { | ||
2048 | 782 | position.top -= elemHeight / 2; | ||
2049 | 783 | } | ||
2050 | 784 | |||
2051 | 785 | // prevent fractions (see #5280) | ||
2052 | 786 | position.left = parseInt( position.left ); | ||
2053 | 787 | position.top = parseInt( position.top ); | ||
2054 | 788 | |||
2055 | 789 | $.each( [ "left", "top" ], function( i, dir ) { | ||
2056 | 790 | if ( $.ui.position[ collision[i] ] ) { | ||
2057 | 791 | $.ui.position[ collision[i] ][ dir ]( position, { | ||
2058 | 792 | targetWidth: targetWidth, | ||
2059 | 793 | targetHeight: targetHeight, | ||
2060 | 794 | elemWidth: elemWidth, | ||
2061 | 795 | elemHeight: elemHeight, | ||
2062 | 796 | offset: offset, | ||
2063 | 797 | my: options.my, | ||
2064 | 798 | at: options.at | ||
2065 | 799 | }); | ||
2066 | 800 | } | ||
2067 | 801 | }); | ||
2068 | 802 | |||
2069 | 803 | if ( $.fn.bgiframe ) { | ||
2070 | 804 | elem.bgiframe(); | ||
2071 | 805 | } | ||
2072 | 806 | elem.offset( $.extend( position, { using: options.using } ) ); | ||
2073 | 807 | }); | ||
2074 | 808 | }; | ||
2075 | 809 | |||
2076 | 810 | $.ui.position = { | ||
2077 | 811 | fit: { | ||
2078 | 812 | left: function( position, data ) { | ||
2079 | 813 | var win = $( window ), | ||
2080 | 814 | over = position.left + data.elemWidth - win.width() - win.scrollLeft(); | ||
2081 | 815 | position.left = over > 0 ? position.left - over : Math.max( 0, position.left ); | ||
2082 | 816 | }, | ||
2083 | 817 | top: function( position, data ) { | ||
2084 | 818 | var win = $( window ), | ||
2085 | 819 | over = position.top + data.elemHeight - win.height() - win.scrollTop(); | ||
2086 | 820 | position.top = over > 0 ? position.top - over : Math.max( 0, position.top ); | ||
2087 | 821 | } | ||
2088 | 822 | }, | ||
2089 | 823 | |||
2090 | 824 | flip: { | ||
2091 | 825 | left: function( position, data ) { | ||
2092 | 826 | if ( data.at[0] === "center" ) { | ||
2093 | 827 | return; | ||
2094 | 828 | } | ||
2095 | 829 | var win = $( window ), | ||
2096 | 830 | over = position.left + data.elemWidth - win.width() - win.scrollLeft(), | ||
2097 | 831 | myOffset = data.my[ 0 ] === "left" ? | ||
2098 | 832 | -data.elemWidth : | ||
2099 | 833 | data.my[ 0 ] === "right" ? | ||
2100 | 834 | data.elemWidth : | ||
2101 | 835 | 0, | ||
2102 | 836 | offset = -2 * data.offset[ 0 ]; | ||
2103 | 837 | position.left += position.left < 0 ? | ||
2104 | 838 | myOffset + data.targetWidth + offset : | ||
2105 | 839 | over > 0 ? | ||
2106 | 840 | myOffset - data.targetWidth + offset : | ||
2107 | 841 | 0; | ||
2108 | 842 | }, | ||
2109 | 843 | top: function( position, data ) { | ||
2110 | 844 | if ( data.at[1] === "center" ) { | ||
2111 | 845 | return; | ||
2112 | 846 | } | ||
2113 | 847 | var win = $( window ), | ||
2114 | 848 | over = position.top + data.elemHeight - win.height() - win.scrollTop(), | ||
2115 | 849 | myOffset = data.my[ 1 ] === "top" ? | ||
2116 | 850 | -data.elemHeight : | ||
2117 | 851 | data.my[ 1 ] === "bottom" ? | ||
2118 | 852 | data.elemHeight : | ||
2119 | 853 | 0, | ||
2120 | 854 | atOffset = data.at[ 1 ] === "top" ? | ||
2121 | 855 | data.targetHeight : | ||
2122 | 856 | -data.targetHeight, | ||
2123 | 857 | offset = -2 * data.offset[ 1 ]; | ||
2124 | 858 | position.top += position.top < 0 ? | ||
2125 | 859 | myOffset + data.targetHeight + offset : | ||
2126 | 860 | over > 0 ? | ||
2127 | 861 | myOffset + atOffset + offset : | ||
2128 | 862 | 0; | ||
2129 | 863 | } | ||
2130 | 864 | } | ||
2131 | 865 | }; | ||
2132 | 866 | |||
2133 | 867 | // offset setter from jQuery 1.4 | ||
2134 | 868 | if ( !$.offset.setOffset ) { | ||
2135 | 869 | $.offset.setOffset = function( elem, options ) { | ||
2136 | 870 | // set position first, in-case top/left are set even on static elem | ||
2137 | 871 | if ( /static/.test( $.curCSS( elem, "position" ) ) ) { | ||
2138 | 872 | elem.style.position = "relative"; | ||
2139 | 873 | } | ||
2140 | 874 | var curElem = $( elem ), | ||
2141 | 875 | curOffset = curElem.offset(), | ||
2142 | 876 | curTop = parseInt( $.curCSS( elem, "top", true ), 10 ) || 0, | ||
2143 | 877 | curLeft = parseInt( $.curCSS( elem, "left", true ), 10) || 0, | ||
2144 | 878 | props = { | ||
2145 | 879 | top: (options.top - curOffset.top) + curTop, | ||
2146 | 880 | left: (options.left - curOffset.left) + curLeft | ||
2147 | 881 | }; | ||
2148 | 882 | |||
2149 | 883 | if ( 'using' in options ) { | ||
2150 | 884 | options.using.call( elem, props ); | ||
2151 | 885 | } else { | ||
2152 | 886 | curElem.css( props ); | ||
2153 | 887 | } | ||
2154 | 888 | }; | ||
2155 | 889 | |||
2156 | 890 | $.fn.offset = function( options ) { | ||
2157 | 891 | var elem = this[ 0 ]; | ||
2158 | 892 | if ( !elem || !elem.ownerDocument ) { return null; } | ||
2159 | 893 | if ( options ) { | ||
2160 | 894 | return this.each(function() { | ||
2161 | 895 | $.offset.setOffset( this, options ); | ||
2162 | 896 | }); | ||
2163 | 897 | } | ||
2164 | 898 | return _offset.call( this ); | ||
2165 | 899 | }; | ||
2166 | 900 | } | ||
2167 | 901 | |||
2168 | 902 | }( jQuery )); | ||
2169 | 903 | /* | ||
2170 | 904 | * jQuery UI Draggable 1.8.4 | ||
2171 | 905 | * | ||
2172 | 906 | * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about) | ||
2173 | 907 | * Dual licensed under the MIT or GPL Version 2 licenses. | ||
2174 | 908 | * http://jquery.org/license | ||
2175 | 909 | * | ||
2176 | 910 | * http://docs.jquery.com/UI/Draggables | ||
2177 | 911 | * | ||
2178 | 912 | * Depends: | ||
2179 | 913 | * jquery.ui.core.js | ||
2180 | 914 | * jquery.ui.mouse.js | ||
2181 | 915 | * jquery.ui.widget.js | ||
2182 | 916 | */ | ||
2183 | 917 | (function( $, undefined ) { | ||
2184 | 918 | |||
2185 | 919 | $.widget("ui.draggable", $.ui.mouse, { | ||
2186 | 920 | widgetEventPrefix: "drag", | ||
2187 | 921 | options: { | ||
2188 | 922 | addClasses: true, | ||
2189 | 923 | appendTo: "parent", | ||
2190 | 924 | axis: false, | ||
2191 | 925 | connectToSortable: false, | ||
2192 | 926 | containment: false, | ||
2193 | 927 | cursor: "auto", | ||
2194 | 928 | cursorAt: false, | ||
2195 | 929 | grid: false, | ||
2196 | 930 | handle: false, | ||
2197 | 931 | helper: "original", | ||
2198 | 932 | iframeFix: false, | ||
2199 | 933 | opacity: false, | ||
2200 | 934 | refreshPositions: false, | ||
2201 | 935 | revert: false, | ||
2202 | 936 | revertDuration: 500, | ||
2203 | 937 | scope: "default", | ||
2204 | 938 | scroll: true, | ||
2205 | 939 | scrollSensitivity: 20, | ||
2206 | 940 | scrollSpeed: 20, | ||
2207 | 941 | snap: false, | ||
2208 | 942 | snapMode: "both", | ||
2209 | 943 | snapTolerance: 20, | ||
2210 | 944 | stack: false, | ||
2211 | 945 | zIndex: false | ||
2212 | 946 | }, | ||
2213 | 947 | _create: function() { | ||
2214 | 948 | |||
2215 | 949 | if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position"))) | ||
2216 | 950 | this.element[0].style.position = 'relative'; | ||
2217 | 951 | |||
2218 | 952 | (this.options.addClasses && this.element.addClass("ui-draggable")); | ||
2219 | 953 | (this.options.disabled && this.element.addClass("ui-draggable-disabled")); | ||
2220 | 954 | |||
2221 | 955 | this._mouseInit(); | ||
2222 | 956 | |||
2223 | 957 | }, | ||
2224 | 958 | |||
2225 | 959 | destroy: function() { | ||
2226 | 960 | if(!this.element.data('draggable')) return; | ||
2227 | 961 | this.element | ||
2228 | 962 | .removeData("draggable") | ||
2229 | 963 | .unbind(".draggable") | ||
2230 | 964 | .removeClass("ui-draggable" | ||
2231 | 965 | + " ui-draggable-dragging" | ||
2232 | 966 | + " ui-draggable-disabled"); | ||
2233 | 967 | this._mouseDestroy(); | ||
2234 | 968 | |||
2235 | 969 | return this; | ||
2236 | 970 | }, | ||
2237 | 971 | |||
2238 | 972 | _mouseCapture: function(event) { | ||
2239 | 973 | |||
2240 | 974 | var o = this.options; | ||
2241 | 975 | |||
2242 | 976 | // among others, prevent a drag on a resizable-handle | ||
2243 | 977 | if (this.helper || o.disabled || $(event.target).is('.ui-resizable-handle')) | ||
2244 | 978 | return false; | ||
2245 | 979 | |||
2246 | 980 | //Quit if we're not on a valid handle | ||
2247 | 981 | this.handle = this._getHandle(event); | ||
2248 | 982 | if (!this.handle) | ||
2249 | 983 | return false; | ||
2250 | 984 | |||
2251 | 985 | return true; | ||
2252 | 986 | |||
2253 | 987 | }, | ||
2254 | 988 | |||
2255 | 989 | _mouseStart: function(event) { | ||
2256 | 990 | |||
2257 | 991 | var o = this.options; | ||
2258 | 992 | |||
2259 | 993 | //Create and append the visible helper | ||
2260 | 994 | this.helper = this._createHelper(event); | ||
2261 | 995 | |||
2262 | 996 | //Cache the helper size | ||
2263 | 997 | this._cacheHelperProportions(); | ||
2264 | 998 | |||
2265 | 999 | //If ddmanager is used for droppables, set the global draggable | ||
2266 | 1000 | if($.ui.ddmanager) | ||
2267 | 1001 | $.ui.ddmanager.current = this; | ||
2268 | 1002 | |||
2269 | 1003 | /* | ||
2270 | 1004 | * - Position generation - | ||
2271 | 1005 | * This block generates everything position related - it's the core of draggables. | ||
2272 | 1006 | */ | ||
2273 | 1007 | |||
2274 | 1008 | //Cache the margins of the original element | ||
2275 | 1009 | this._cacheMargins(); | ||
2276 | 1010 | |||
2277 | 1011 | //Store the helper's css position | ||
2278 | 1012 | this.cssPosition = this.helper.css("position"); | ||
2279 | 1013 | this.scrollParent = this.helper.scrollParent(); | ||
2280 | 1014 | |||
2281 | 1015 | //The element's absolute position on the page minus margins | ||
2282 | 1016 | this.offset = this.positionAbs = this.element.offset(); | ||
2283 | 1017 | this.offset = { | ||
2284 | 1018 | top: this.offset.top - this.margins.top, | ||
2285 | 1019 | left: this.offset.left - this.margins.left | ||
2286 | 1020 | }; | ||
2287 | 1021 | |||
2288 | 1022 | $.extend(this.offset, { | ||
2289 | 1023 | click: { //Where the click happened, relative to the element | ||
2290 | 1024 | left: event.pageX - this.offset.left, | ||
2291 | 1025 | top: event.pageY - this.offset.top | ||
2292 | 1026 | }, | ||
2293 | 1027 | parent: this._getParentOffset(), | ||
2294 | 1028 | relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper | ||
2295 | 1029 | }); | ||
2296 | 1030 | |||
2297 | 1031 | //Generate the original position | ||
2298 | 1032 | this.originalPosition = this.position = this._generatePosition(event); | ||
2299 | 1033 | this.originalPageX = event.pageX; | ||
2300 | 1034 | this.originalPageY = event.pageY; | ||
2301 | 1035 | |||
2302 | 1036 | //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied | ||
2303 | 1037 | (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt)); | ||
2304 | 1038 | |||
2305 | 1039 | //Set a containment if given in the options | ||
2306 | 1040 | if(o.containment) | ||
2307 | 1041 | this._setContainment(); | ||
2308 | 1042 | |||
2309 | 1043 | //Trigger event + callbacks | ||
2310 | 1044 | if(this._trigger("start", event) === false) { | ||
2311 | 1045 | this._clear(); | ||
2312 | 1046 | return false; | ||
2313 | 1047 | } | ||
2314 | 1048 | |||
2315 | 1049 | //Recache the helper size | ||
2316 | 1050 | this._cacheHelperProportions(); | ||
2317 | 1051 | |||
2318 | 1052 | //Prepare the droppable offsets | ||
2319 | 1053 | if ($.ui.ddmanager && !o.dropBehaviour) | ||
2320 | 1054 | $.ui.ddmanager.prepareOffsets(this, event); | ||
2321 | 1055 | |||
2322 | 1056 | this.helper.addClass("ui-draggable-dragging"); | ||
2323 | 1057 | this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position | ||
2324 | 1058 | return true; | ||
2325 | 1059 | }, | ||
2326 | 1060 | |||
2327 | 1061 | _mouseDrag: function(event, noPropagation) { | ||
2328 | 1062 | |||
2329 | 1063 | //Compute the helpers position | ||
2330 | 1064 | this.position = this._generatePosition(event); | ||
2331 | 1065 | this.positionAbs = this._convertPositionTo("absolute"); | ||
2332 | 1066 | |||
2333 | 1067 | //Call plugins and callbacks and use the resulting position if something is returned | ||
2334 | 1068 | if (!noPropagation) { | ||
2335 | 1069 | var ui = this._uiHash(); | ||
2336 | 1070 | if(this._trigger('drag', event, ui) === false) { | ||
2337 | 1071 | this._mouseUp({}); | ||
2338 | 1072 | return false; | ||
2339 | 1073 | } | ||
2340 | 1074 | this.position = ui.position; | ||
2341 | 1075 | } | ||
2342 | 1076 | |||
2343 | 1077 | if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px'; | ||
2344 | 1078 | if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px'; | ||
2345 | 1079 | if($.ui.ddmanager) $.ui.ddmanager.drag(this, event); | ||
2346 | 1080 | |||
2347 | 1081 | return false; | ||
2348 | 1082 | }, | ||
2349 | 1083 | |||
2350 | 1084 | _mouseStop: function(event) { | ||
2351 | 1085 | |||
2352 | 1086 | //If we are using droppables, inform the manager about the drop | ||
2353 | 1087 | var dropped = false; | ||
2354 | 1088 | if ($.ui.ddmanager && !this.options.dropBehaviour) | ||
2355 | 1089 | dropped = $.ui.ddmanager.drop(this, event); | ||
2356 | 1090 | |||
2357 | 1091 | //if a drop comes from outside (a sortable) | ||
2358 | 1092 | if(this.dropped) { | ||
2359 | 1093 | dropped = this.dropped; | ||
2360 | 1094 | this.dropped = false; | ||
2361 | 1095 | } | ||
2362 | 1096 | |||
2363 | 1097 | //if the original element is removed, don't bother to continue | ||
2364 | 1098 | if(!this.element[0] || !this.element[0].parentNode) | ||
2365 | 1099 | return false; | ||
2366 | 1100 | |||
2367 | 1101 | if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) { | ||
2368 | 1102 | var self = this; | ||
2369 | 1103 | $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() { | ||
2370 | 1104 | if(self._trigger("stop", event) !== false) { | ||
2371 | 1105 | self._clear(); | ||
2372 | 1106 | } | ||
2373 | 1107 | }); | ||
2374 | 1108 | } else { | ||
2375 | 1109 | if(this._trigger("stop", event) !== false) { | ||
2376 | 1110 | this._clear(); | ||
2377 | 1111 | } | ||
2378 | 1112 | } | ||
2379 | 1113 | |||
2380 | 1114 | return false; | ||
2381 | 1115 | }, | ||
2382 | 1116 | |||
2383 | 1117 | cancel: function() { | ||
2384 | 1118 | |||
2385 | 1119 | if(this.helper.is(".ui-draggable-dragging")) { | ||
2386 | 1120 | this._mouseUp({}); | ||
2387 | 1121 | } else { | ||
2388 | 1122 | this._clear(); | ||
2389 | 1123 | } | ||
2390 | 1124 | |||
2391 | 1125 | return this; | ||
2392 | 1126 | |||
2393 | 1127 | }, | ||
2394 | 1128 | |||
2395 | 1129 | _getHandle: function(event) { | ||
2396 | 1130 | |||
2397 | 1131 | var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false; | ||
2398 | 1132 | $(this.options.handle, this.element) | ||
2399 | 1133 | .find("*") | ||
2400 | 1134 | .andSelf() | ||
2401 | 1135 | .each(function() { | ||
2402 | 1136 | if(this == event.target) handle = true; | ||
2403 | 1137 | }); | ||
2404 | 1138 | |||
2405 | 1139 | return handle; | ||
2406 | 1140 | |||
2407 | 1141 | }, | ||
2408 | 1142 | |||
2409 | 1143 | _createHelper: function(event) { | ||
2410 | 1144 | |||
2411 | 1145 | var o = this.options; | ||
2412 | 1146 | var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper == 'clone' ? this.element.clone() : this.element); | ||
2413 | 1147 | |||
2414 | 1148 | if(!helper.parents('body').length) | ||
2415 | 1149 | helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo)); | ||
2416 | 1150 | |||
2417 | 1151 | if(helper[0] != this.element[0] && !(/(fixed|absolute)/).test(helper.css("position"))) | ||
2418 | 1152 | helper.css("position", "absolute"); | ||
2419 | 1153 | |||
2420 | 1154 | return helper; | ||
2421 | 1155 | |||
2422 | 1156 | }, | ||
2423 | 1157 | |||
2424 | 1158 | _adjustOffsetFromHelper: function(obj) { | ||
2425 | 1159 | if (typeof obj == 'string') { | ||
2426 | 1160 | obj = obj.split(' '); | ||
2427 | 1161 | } | ||
2428 | 1162 | if ($.isArray(obj)) { | ||
2429 | 1163 | obj = {left: +obj[0], top: +obj[1] || 0}; | ||
2430 | 1164 | } | ||
2431 | 1165 | if ('left' in obj) { | ||
2432 | 1166 | this.offset.click.left = obj.left + this.margins.left; | ||
2433 | 1167 | } | ||
2434 | 1168 | if ('right' in obj) { | ||
2435 | 1169 | this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left; | ||
2436 | 1170 | } | ||
2437 | 1171 | if ('top' in obj) { | ||
2438 | 1172 | this.offset.click.top = obj.top + this.margins.top; | ||
2439 | 1173 | } | ||
2440 | 1174 | if ('bottom' in obj) { | ||
2441 | 1175 | this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top; | ||
2442 | 1176 | } | ||
2443 | 1177 | }, | ||
2444 | 1178 | |||
2445 | 1179 | _getParentOffset: function() { | ||
2446 | 1180 | |||
2447 | 1181 | //Get the offsetParent and cache its position | ||
2448 | 1182 | this.offsetParent = this.helper.offsetParent(); | ||
2449 | 1183 | var po = this.offsetParent.offset(); | ||
2450 | 1184 | |||
2451 | 1185 | // This is a special case where we need to modify a offset calculated on start, since the following happened: | ||
2452 | 1186 | // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent | ||
2453 | 1187 | // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that | ||
2454 | 1188 | // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag | ||
2455 | 1189 | if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) { | ||
2456 | 1190 | po.left += this.scrollParent.scrollLeft(); | ||
2457 | 1191 | po.top += this.scrollParent.scrollTop(); | ||
2458 | 1192 | } | ||
2459 | 1193 | |||
2460 | 1194 | if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information | ||
2461 | 1195 | || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.browser.msie)) //Ugly IE fix | ||
2462 | 1196 | po = { top: 0, left: 0 }; | ||
2463 | 1197 | |||
2464 | 1198 | return { | ||
2465 | 1199 | top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0), | ||
2466 | 1200 | left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0) | ||
2467 | 1201 | }; | ||
2468 | 1202 | |||
2469 | 1203 | }, | ||
2470 | 1204 | |||
2471 | 1205 | _getRelativeOffset: function() { | ||
2472 | 1206 | |||
2473 | 1207 | if(this.cssPosition == "relative") { | ||
2474 | 1208 | var p = this.element.position(); | ||
2475 | 1209 | return { | ||
2476 | 1210 | top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(), | ||
2477 | 1211 | left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft() | ||
2478 | 1212 | }; | ||
2479 | 1213 | } else { | ||
2480 | 1214 | return { top: 0, left: 0 }; | ||
2481 | 1215 | } | ||
2482 | 1216 | |||
2483 | 1217 | }, | ||
2484 | 1218 | |||
2485 | 1219 | _cacheMargins: function() { | ||
2486 | 1220 | this.margins = { | ||
2487 | 1221 | left: (parseInt(this.element.css("marginLeft"),10) || 0), | ||
2488 | 1222 | top: (parseInt(this.element.css("marginTop"),10) || 0) | ||
2489 | 1223 | }; | ||
2490 | 1224 | }, | ||
2491 | 1225 | |||
2492 | 1226 | _cacheHelperProportions: function() { | ||
2493 | 1227 | this.helperProportions = { | ||
2494 | 1228 | width: this.helper.outerWidth(), | ||
2495 | 1229 | height: this.helper.outerHeight() | ||
2496 | 1230 | }; | ||
2497 | 1231 | }, | ||
2498 | 1232 | |||
2499 | 1233 | _setContainment: function() { | ||
2500 | 1234 | |||
2501 | 1235 | var o = this.options; | ||
2502 | 1236 | if(o.containment == 'parent') o.containment = this.helper[0].parentNode; | ||
2503 | 1237 | if(o.containment == 'document' || o.containment == 'window') this.containment = [ | ||
2504 | 1238 | 0 - this.offset.relative.left - this.offset.parent.left, | ||
2505 | 1239 | 0 - this.offset.relative.top - this.offset.parent.top, | ||
2506 | 1240 | $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left, | ||
2507 | 1241 | ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top | ||
2508 | 1242 | ]; | ||
2509 | 1243 | |||
2510 | 1244 | if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor != Array) { | ||
2511 | 1245 | var ce = $(o.containment)[0]; if(!ce) return; | ||
2512 | 1246 | var co = $(o.containment).offset(); | ||
2513 | 1247 | var over = ($(ce).css("overflow") != 'hidden'); | ||
2514 | 1248 | |||
2515 | 1249 | this.containment = [ | ||
2516 | 1250 | co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left, | ||
2517 | 1251 | co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0) - this.margins.top, | ||
2518 | 1252 | co.left+(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left, | ||
2519 | 1253 | co.top+(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top | ||
2520 | 1254 | ]; | ||
2521 | 1255 | } else if(o.containment.constructor == Array) { | ||
2522 | 1256 | this.containment = o.containment; | ||
2523 | 1257 | } | ||
2524 | 1258 | |||
2525 | 1259 | }, | ||
2526 | 1260 | |||
2527 | 1261 | _convertPositionTo: function(d, pos) { | ||
2528 | 1262 | |||
2529 | 1263 | if(!pos) pos = this.position; | ||
2530 | 1264 | var mod = d == "absolute" ? 1 : -1; | ||
2531 | 1265 | var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); | ||
2532 | 1266 | |||
2533 | 1267 | return { | ||
2534 | 1268 | top: ( | ||
2535 | 1269 | pos.top // The absolute mouse position | ||
2536 | 1270 | + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent | ||
2537 | 1271 | + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border) | ||
2538 | 1272 | - ($.browser.safari && $.browser.version < 526 && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod) | ||
2539 | 1273 | ), | ||
2540 | 1274 | left: ( | ||
2541 | 1275 | pos.left // The absolute mouse position | ||
2542 | 1276 | + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent | ||
2543 | 1277 | + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border) | ||
2544 | 1278 | - ($.browser.safari && $.browser.version < 526 && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod) | ||
2545 | 1279 | ) | ||
2546 | 1280 | }; | ||
2547 | 1281 | |||
2548 | 1282 | }, | ||
2549 | 1283 | |||
2550 | 1284 | _generatePosition: function(event) { | ||
2551 | 1285 | |||
2552 | 1286 | var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); | ||
2553 | 1287 | var pageX = event.pageX; | ||
2554 | 1288 | var pageY = event.pageY; | ||
2555 | 1289 | |||
2556 | 1290 | /* | ||
2557 | 1291 | * - Position constraining - | ||
2558 | 1292 | * Constrain the position to a mix of grid, containment. | ||
2559 | 1293 | */ | ||
2560 | 1294 | |||
2561 | 1295 | if(this.originalPosition) { //If we are not dragging yet, we won't check for options | ||
2562 | 1296 | |||
2563 | 1297 | if(this.containment) { | ||
2564 | 1298 | if(event.pageX - this.offset.click.left < this.containment[0]) pageX = this.containment[0] + this.offset.click.left; | ||
2565 | 1299 | if(event.pageY - this.offset.click.top < this.containment[1]) pageY = this.containment[1] + this.offset.click.top; | ||
2566 | 1300 | if(event.pageX - this.offset.click.left > this.containment[2]) pageX = this.containment[2] + this.offset.click.left; | ||
2567 | 1301 | if(event.pageY - this.offset.click.top > this.containment[3]) pageY = this.containment[3] + this.offset.click.top; | ||
2568 | 1302 | } | ||
2569 | 1303 | |||
2570 | 1304 | if(o.grid) { | ||
2571 | 1305 | var top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1]; | ||
2572 | 1306 | pageY = this.containment ? (!(top - this.offset.click.top < this.containment[1] || top - this.offset.click.top > this.containment[3]) ? top : (!(top - this.offset.click.top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; | ||
2573 | 1307 | |||
2574 | 1308 | var left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0]; | ||
2575 | 1309 | pageX = this.containment ? (!(left - this.offset.click.left < this.containment[0] || left - this.offset.click.left > this.containment[2]) ? left : (!(left - this.offset.click.left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; | ||
2576 | 1310 | } | ||
2577 | 1311 | |||
2578 | 1312 | } | ||
2579 | 1313 | |||
2580 | 1314 | return { | ||
2581 | 1315 | top: ( | ||
2582 | 1316 | pageY // The absolute mouse position | ||
2583 | 1317 | - this.offset.click.top // Click offset (relative to the element) | ||
2584 | 1318 | - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent | ||
2585 | 1319 | - this.offset.parent.top // The offsetParent's offset without borders (offset + border) | ||
2586 | 1320 | + ($.browser.safari && $.browser.version < 526 && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) )) | ||
2587 | 1321 | ), | ||
2588 | 1322 | left: ( | ||
2589 | 1323 | pageX // The absolute mouse position | ||
2590 | 1324 | - this.offset.click.left // Click offset (relative to the element) | ||
2591 | 1325 | - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent | ||
2592 | 1326 | - this.offset.parent.left // The offsetParent's offset without borders (offset + border) | ||
2593 | 1327 | + ($.browser.safari && $.browser.version < 526 && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() )) | ||
2594 | 1328 | ) | ||
2595 | 1329 | }; | ||
2596 | 1330 | |||
2597 | 1331 | }, | ||
2598 | 1332 | |||
2599 | 1333 | _clear: function() { | ||
2600 | 1334 | this.helper.removeClass("ui-draggable-dragging"); | ||
2601 | 1335 | if(this.helper[0] != this.element[0] && !this.cancelHelperRemoval) this.helper.remove(); | ||
2602 | 1336 | //if($.ui.ddmanager) $.ui.ddmanager.current = null; | ||
2603 | 1337 | this.helper = null; | ||
2604 | 1338 | this.cancelHelperRemoval = false; | ||
2605 | 1339 | }, | ||
2606 | 1340 | |||
2607 | 1341 | // From now on bulk stuff - mainly helpers | ||
2608 | 1342 | |||
2609 | 1343 | _trigger: function(type, event, ui) { | ||
2610 | 1344 | ui = ui || this._uiHash(); | ||
2611 | 1345 | $.ui.plugin.call(this, type, [event, ui]); | ||
2612 | 1346 | if(type == "drag") this.positionAbs = this._convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins | ||
2613 | 1347 | return $.Widget.prototype._trigger.call(this, type, event, ui); | ||
2614 | 1348 | }, | ||
2615 | 1349 | |||
2616 | 1350 | plugins: {}, | ||
2617 | 1351 | |||
2618 | 1352 | _uiHash: function(event) { | ||
2619 | 1353 | return { | ||
2620 | 1354 | helper: this.helper, | ||
2621 | 1355 | position: this.position, | ||
2622 | 1356 | originalPosition: this.originalPosition, | ||
2623 | 1357 | offset: this.positionAbs | ||
2624 | 1358 | }; | ||
2625 | 1359 | } | ||
2626 | 1360 | |||
2627 | 1361 | }); | ||
2628 | 1362 | |||
2629 | 1363 | $.extend($.ui.draggable, { | ||
2630 | 1364 | version: "1.8.4" | ||
2631 | 1365 | }); | ||
2632 | 1366 | |||
2633 | 1367 | $.ui.plugin.add("draggable", "connectToSortable", { | ||
2634 | 1368 | start: function(event, ui) { | ||
2635 | 1369 | |||
2636 | 1370 | var inst = $(this).data("draggable"), o = inst.options, | ||
2637 | 1371 | uiSortable = $.extend({}, ui, { item: inst.element }); | ||
2638 | 1372 | inst.sortables = []; | ||
2639 | 1373 | $(o.connectToSortable).each(function() { | ||
2640 | 1374 | var sortable = $.data(this, 'sortable'); | ||
2641 | 1375 | if (sortable && !sortable.options.disabled) { | ||
2642 | 1376 | inst.sortables.push({ | ||
2643 | 1377 | instance: sortable, | ||
2644 | 1378 | shouldRevert: sortable.options.revert | ||
2645 | 1379 | }); | ||
2646 | 1380 | sortable._refreshItems(); //Do a one-time refresh at start to refresh the containerCache | ||
2647 | 1381 | sortable._trigger("activate", event, uiSortable); | ||
2648 | 1382 | } | ||
2649 | 1383 | }); | ||
2650 | 1384 | |||
2651 | 1385 | }, | ||
2652 | 1386 | stop: function(event, ui) { | ||
2653 | 1387 | |||
2654 | 1388 | //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper | ||
2655 | 1389 | var inst = $(this).data("draggable"), | ||
2656 | 1390 | uiSortable = $.extend({}, ui, { item: inst.element }); | ||
2657 | 1391 | |||
2658 | 1392 | $.each(inst.sortables, function() { | ||
2659 | 1393 | if(this.instance.isOver) { | ||
2660 | 1394 | |||
2661 | 1395 | this.instance.isOver = 0; | ||
2662 | 1396 | |||
2663 | 1397 | inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance | ||
2664 | 1398 | this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work) | ||
2665 | 1399 | |||
2666 | 1400 | //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: 'valid/invalid' | ||
2667 | 1401 | if(this.shouldRevert) this.instance.options.revert = true; | ||
2668 | 1402 | |||
2669 | 1403 | //Trigger the stop of the sortable | ||
2670 | 1404 | this.instance._mouseStop(event); | ||
2671 | 1405 | |||
2672 | 1406 | this.instance.options.helper = this.instance.options._helper; | ||
2673 | 1407 | |||
2674 | 1408 | //If the helper has been the original item, restore properties in the sortable | ||
2675 | 1409 | if(inst.options.helper == 'original') | ||
2676 | 1410 | this.instance.currentItem.css({ top: 'auto', left: 'auto' }); | ||
2677 | 1411 | |||
2678 | 1412 | } else { | ||
2679 | 1413 | this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance | ||
2680 | 1414 | this.instance._trigger("deactivate", event, uiSortable); | ||
2681 | 1415 | } | ||
2682 | 1416 | |||
2683 | 1417 | }); | ||
2684 | 1418 | |||
2685 | 1419 | }, | ||
2686 | 1420 | drag: function(event, ui) { | ||
2687 | 1421 | |||
2688 | 1422 | var inst = $(this).data("draggable"), self = this; | ||
2689 | 1423 | |||
2690 | 1424 | var checkPos = function(o) { | ||
2691 | 1425 | var dyClick = this.offset.click.top, dxClick = this.offset.click.left; | ||
2692 | 1426 | var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left; | ||
2693 | 1427 | var itemHeight = o.height, itemWidth = o.width; | ||
2694 | 1428 | var itemTop = o.top, itemLeft = o.left; | ||
2695 | 1429 | |||
2696 | 1430 | return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth); | ||
2697 | 1431 | }; | ||
2698 | 1432 | |||
2699 | 1433 | $.each(inst.sortables, function(i) { | ||
2700 | 1434 | |||
2701 | 1435 | //Copy over some variables to allow calling the sortable's native _intersectsWith | ||
2702 | 1436 | this.instance.positionAbs = inst.positionAbs; | ||
2703 | 1437 | this.instance.helperProportions = inst.helperProportions; | ||
2704 | 1438 | this.instance.offset.click = inst.offset.click; | ||
2705 | 1439 | |||
2706 | 1440 | if(this.instance._intersectsWith(this.instance.containerCache)) { | ||
2707 | 1441 | |||
2708 | 1442 | //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once | ||
2709 | 1443 | if(!this.instance.isOver) { | ||
2710 | 1444 | |||
2711 | 1445 | this.instance.isOver = 1; | ||
2712 | 1446 | //Now we fake the start of dragging for the sortable instance, | ||
2713 | 1447 | //by cloning the list group item, appending it to the sortable and using it as inst.currentItem | ||
2714 | 1448 | //We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one) | ||
2715 | 1449 | this.instance.currentItem = $(self).clone().appendTo(this.instance.element).data("sortable-item", true); | ||
2716 | 1450 | this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it | ||
2717 | 1451 | this.instance.options.helper = function() { return ui.helper[0]; }; | ||
2718 | 1452 | |||
2719 | 1453 | event.target = this.instance.currentItem[0]; | ||
2720 | 1454 | this.instance._mouseCapture(event, true); | ||
2721 | 1455 | this.instance._mouseStart(event, true, true); | ||
2722 | 1456 | |||
2723 | 1457 | //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes | ||
2724 | 1458 | this.instance.offset.click.top = inst.offset.click.top; | ||
2725 | 1459 | this.instance.offset.click.left = inst.offset.click.left; | ||
2726 | 1460 | this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left; | ||
2727 | 1461 | this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top; | ||
2728 | 1462 | |||
2729 | 1463 | inst._trigger("toSortable", event); | ||
2730 | 1464 | inst.dropped = this.instance.element; //draggable revert needs that | ||
2731 | 1465 | //hack so receive/update callbacks work (mostly) | ||
2732 | 1466 | inst.currentItem = inst.element; | ||
2733 | 1467 | this.instance.fromOutside = inst; | ||
2734 | 1468 | |||
2735 | 1469 | } | ||
2736 | 1470 | |||
2737 | 1471 | //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable | ||
2738 | 1472 | if(this.instance.currentItem) this.instance._mouseDrag(event); | ||
2739 | 1473 | |||
2740 | 1474 | } else { | ||
2741 | 1475 | |||
2742 | 1476 | //If it doesn't intersect with the sortable, and it intersected before, | ||
2743 | 1477 | //we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval | ||
2744 | 1478 | if(this.instance.isOver) { | ||
2745 | 1479 | |||
2746 | 1480 | this.instance.isOver = 0; | ||
2747 | 1481 | this.instance.cancelHelperRemoval = true; | ||
2748 | 1482 | |||
2749 | 1483 | //Prevent reverting on this forced stop | ||
2750 | 1484 | this.instance.options.revert = false; | ||
2751 | 1485 | |||
2752 | 1486 | // The out event needs to be triggered independently | ||
2753 | 1487 | this.instance._trigger('out', event, this.instance._uiHash(this.instance)); | ||
2754 | 1488 | |||
2755 | 1489 | this.instance._mouseStop(event, true); | ||
2756 | 1490 | this.instance.options.helper = this.instance.options._helper; | ||
2757 | 1491 | |||
2758 | 1492 | //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size | ||
2759 | 1493 | this.instance.currentItem.remove(); | ||
2760 | 1494 | if(this.instance.placeholder) this.instance.placeholder.remove(); | ||
2761 | 1495 | |||
2762 | 1496 | inst._trigger("fromSortable", event); | ||
2763 | 1497 | inst.dropped = false; //draggable revert needs that | ||
2764 | 1498 | } | ||
2765 | 1499 | |||
2766 | 1500 | }; | ||
2767 | 1501 | |||
2768 | 1502 | }); | ||
2769 | 1503 | |||
2770 | 1504 | } | ||
2771 | 1505 | }); | ||
2772 | 1506 | |||
2773 | 1507 | $.ui.plugin.add("draggable", "cursor", { | ||
2774 | 1508 | start: function(event, ui) { | ||
2775 | 1509 | var t = $('body'), o = $(this).data('draggable').options; | ||
2776 | 1510 | if (t.css("cursor")) o._cursor = t.css("cursor"); | ||
2777 | 1511 | t.css("cursor", o.cursor); | ||
2778 | 1512 | }, | ||
2779 | 1513 | stop: function(event, ui) { | ||
2780 | 1514 | var o = $(this).data('draggable').options; | ||
2781 | 1515 | if (o._cursor) $('body').css("cursor", o._cursor); | ||
2782 | 1516 | } | ||
2783 | 1517 | }); | ||
2784 | 1518 | |||
2785 | 1519 | $.ui.plugin.add("draggable", "iframeFix", { | ||
2786 | 1520 | start: function(event, ui) { | ||
2787 | 1521 | var o = $(this).data('draggable').options; | ||
2788 | 1522 | $(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() { | ||
2789 | 1523 | $('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>') | ||
2790 | 1524 | .css({ | ||
2791 | 1525 | width: this.offsetWidth+"px", height: this.offsetHeight+"px", | ||
2792 | 1526 | position: "absolute", opacity: "0.001", zIndex: 1000 | ||
2793 | 1527 | }) | ||
2794 | 1528 | .css($(this).offset()) | ||
2795 | 1529 | .appendTo("body"); | ||
2796 | 1530 | }); | ||
2797 | 1531 | }, | ||
2798 | 1532 | stop: function(event, ui) { | ||
2799 | 1533 | $("div.ui-draggable-iframeFix").each(function() { this.parentNode.removeChild(this); }); //Remove frame helpers | ||
2800 | 1534 | } | ||
2801 | 1535 | }); | ||
2802 | 1536 | |||
2803 | 1537 | $.ui.plugin.add("draggable", "opacity", { | ||
2804 | 1538 | start: function(event, ui) { | ||
2805 | 1539 | var t = $(ui.helper), o = $(this).data('draggable').options; | ||
2806 | 1540 | if(t.css("opacity")) o._opacity = t.css("opacity"); | ||
2807 | 1541 | t.css('opacity', o.opacity); | ||
2808 | 1542 | }, | ||
2809 | 1543 | stop: function(event, ui) { | ||
2810 | 1544 | var o = $(this).data('draggable').options; | ||
2811 | 1545 | if(o._opacity) $(ui.helper).css('opacity', o._opacity); | ||
2812 | 1546 | } | ||
2813 | 1547 | }); | ||
2814 | 1548 | |||
2815 | 1549 | $.ui.plugin.add("draggable", "scroll", { | ||
2816 | 1550 | start: function(event, ui) { | ||
2817 | 1551 | var i = $(this).data("draggable"); | ||
2818 | 1552 | if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset(); | ||
2819 | 1553 | }, | ||
2820 | 1554 | drag: function(event, ui) { | ||
2821 | 1555 | |||
2822 | 1556 | var i = $(this).data("draggable"), o = i.options, scrolled = false; | ||
2823 | 1557 | |||
2824 | 1558 | if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') { | ||
2825 | 1559 | |||
2826 | 1560 | if(!o.axis || o.axis != 'x') { | ||
2827 | 1561 | if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) | ||
2828 | 1562 | i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed; | ||
2829 | 1563 | else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity) | ||
2830 | 1564 | i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed; | ||
2831 | 1565 | } | ||
2832 | 1566 | |||
2833 | 1567 | if(!o.axis || o.axis != 'y') { | ||
2834 | 1568 | if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) | ||
2835 | 1569 | i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed; | ||
2836 | 1570 | else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity) | ||
2837 | 1571 | i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed; | ||
2838 | 1572 | } | ||
2839 | 1573 | |||
2840 | 1574 | } else { | ||
2841 | 1575 | |||
2842 | 1576 | if(!o.axis || o.axis != 'x') { | ||
2843 | 1577 | if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) | ||
2844 | 1578 | scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed); | ||
2845 | 1579 | else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) | ||
2846 | 1580 | scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed); | ||
2847 | 1581 | } | ||
2848 | 1582 | |||
2849 | 1583 | if(!o.axis || o.axis != 'y') { | ||
2850 | 1584 | if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) | ||
2851 | 1585 | scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed); | ||
2852 | 1586 | else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) | ||
2853 | 1587 | scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); | ||
2854 | 1588 | } | ||
2855 | 1589 | |||
2856 | 1590 | } | ||
2857 | 1591 | |||
2858 | 1592 | if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) | ||
2859 | 1593 | $.ui.ddmanager.prepareOffsets(i, event); | ||
2860 | 1594 | |||
2861 | 1595 | } | ||
2862 | 1596 | }); | ||
2863 | 1597 | |||
2864 | 1598 | $.ui.plugin.add("draggable", "snap", { | ||
2865 | 1599 | start: function(event, ui) { | ||
2866 | 1600 | |||
2867 | 1601 | var i = $(this).data("draggable"), o = i.options; | ||
2868 | 1602 | i.snapElements = []; | ||
2869 | 1603 | |||
2870 | 1604 | $(o.snap.constructor != String ? ( o.snap.items || ':data(draggable)' ) : o.snap).each(function() { | ||
2871 | 1605 | var $t = $(this); var $o = $t.offset(); | ||
2872 | 1606 | if(this != i.element[0]) i.snapElements.push({ | ||
2873 | 1607 | item: this, | ||
2874 | 1608 | width: $t.outerWidth(), height: $t.outerHeight(), | ||
2875 | 1609 | top: $o.top, left: $o.left | ||
2876 | 1610 | }); | ||
2877 | 1611 | }); | ||
2878 | 1612 | |||
2879 | 1613 | }, | ||
2880 | 1614 | drag: function(event, ui) { | ||
2881 | 1615 | |||
2882 | 1616 | var inst = $(this).data("draggable"), o = inst.options; | ||
2883 | 1617 | var d = o.snapTolerance; | ||
2884 | 1618 | |||
2885 | 1619 | var x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width, | ||
2886 | 1620 | y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height; | ||
2887 | 1621 | |||
2888 | 1622 | for (var i = inst.snapElements.length - 1; i >= 0; i--){ | ||
2889 | 1623 | |||
2890 | 1624 | var l = inst.snapElements[i].left, r = l + inst.snapElements[i].width, | ||
2891 | 1625 | t = inst.snapElements[i].top, b = t + inst.snapElements[i].height; | ||
2892 | 1626 | |||
2893 | 1627 | //Yes, I know, this is insane ;) | ||
2894 | 1628 | if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) { | ||
2895 | 1629 | if(inst.snapElements[i].snapping) (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item }))); | ||
2896 | 1630 | inst.snapElements[i].snapping = false; | ||
2897 | 1631 | continue; | ||
2898 | 1632 | } | ||
2899 | 1633 | |||
2900 | 1634 | if(o.snapMode != 'inner') { | ||
2901 | 1635 | var ts = Math.abs(t - y2) <= d; | ||
2902 | 1636 | var bs = Math.abs(b - y1) <= d; | ||
2903 | 1637 | var ls = Math.abs(l - x2) <= d; | ||
2904 | 1638 | var rs = Math.abs(r - x1) <= d; | ||
2905 | 1639 | if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top - inst.margins.top; | ||
2906 | 1640 | if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top; | ||
2907 | 1641 | if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left; | ||
2908 | 1642 | if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left; | ||
2909 | 1643 | } | ||
2910 | 1644 | |||
2911 | 1645 | var first = (ts || bs || ls || rs); | ||
2912 | 1646 | |||
2913 | 1647 | if(o.snapMode != 'outer') { | ||
2914 | 1648 | var ts = Math.abs(t - y1) <= d; | ||
2915 | 1649 | var bs = Math.abs(b - y2) <= d; | ||
2916 | 1650 | var ls = Math.abs(l - x1) <= d; | ||
2917 | 1651 | var rs = Math.abs(r - x2) <= d; | ||
2918 | 1652 | if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top - inst.margins.top; | ||
2919 | 1653 | if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top; | ||
2920 | 1654 | if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left; | ||
2921 | 1655 | if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left - inst.margins.left; | ||
2922 | 1656 | } | ||
2923 | 1657 | |||
2924 | 1658 | if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first)) | ||
2925 | 1659 | (inst.options.snap.snap && inst.options.snap.snap.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item }))); | ||
2926 | 1660 | inst.snapElements[i].snapping = (ts || bs || ls || rs || first); | ||
2927 | 1661 | |||
2928 | 1662 | }; | ||
2929 | 1663 | |||
2930 | 1664 | } | ||
2931 | 1665 | }); | ||
2932 | 1666 | |||
2933 | 1667 | $.ui.plugin.add("draggable", "stack", { | ||
2934 | 1668 | start: function(event, ui) { | ||
2935 | 1669 | |||
2936 | 1670 | var o = $(this).data("draggable").options; | ||
2937 | 1671 | |||
2938 | 1672 | var group = $.makeArray($(o.stack)).sort(function(a,b) { | ||
2939 | 1673 | return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0); | ||
2940 | 1674 | }); | ||
2941 | 1675 | if (!group.length) { return; } | ||
2942 | 1676 | |||
2943 | 1677 | var min = parseInt(group[0].style.zIndex) || 0; | ||
2944 | 1678 | $(group).each(function(i) { | ||
2945 | 1679 | this.style.zIndex = min + i; | ||
2946 | 1680 | }); | ||
2947 | 1681 | |||
2948 | 1682 | this[0].style.zIndex = min + group.length; | ||
2949 | 1683 | |||
2950 | 1684 | } | ||
2951 | 1685 | }); | ||
2952 | 1686 | |||
2953 | 1687 | $.ui.plugin.add("draggable", "zIndex", { | ||
2954 | 1688 | start: function(event, ui) { | ||
2955 | 1689 | var t = $(ui.helper), o = $(this).data("draggable").options; | ||
2956 | 1690 | if(t.css("zIndex")) o._zIndex = t.css("zIndex"); | ||
2957 | 1691 | t.css('zIndex', o.zIndex); | ||
2958 | 1692 | }, | ||
2959 | 1693 | stop: function(event, ui) { | ||
2960 | 1694 | var o = $(this).data("draggable").options; | ||
2961 | 1695 | if(o._zIndex) $(ui.helper).css('zIndex', o._zIndex); | ||
2962 | 1696 | } | ||
2963 | 1697 | }); | ||
2964 | 1698 | |||
2965 | 1699 | })(jQuery); | ||
2966 | 1700 | /* | ||
2967 | 1701 | * jQuery UI Droppable 1.8.4 | ||
2968 | 1702 | * | ||
2969 | 1703 | * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about) | ||
2970 | 1704 | * Dual licensed under the MIT or GPL Version 2 licenses. | ||
2971 | 1705 | * http://jquery.org/license | ||
2972 | 1706 | * | ||
2973 | 1707 | * http://docs.jquery.com/UI/Droppables | ||
2974 | 1708 | * | ||
2975 | 1709 | * Depends: | ||
2976 | 1710 | * jquery.ui.core.js | ||
2977 | 1711 | * jquery.ui.widget.js | ||
2978 | 1712 | * jquery.ui.mouse.js | ||
2979 | 1713 | * jquery.ui.draggable.js | ||
2980 | 1714 | */ | ||
2981 | 1715 | (function( $, undefined ) { | ||
2982 | 1716 | |||
2983 | 1717 | $.widget("ui.droppable", { | ||
2984 | 1718 | widgetEventPrefix: "drop", | ||
2985 | 1719 | options: { | ||
2986 | 1720 | accept: '*', | ||
2987 | 1721 | activeClass: false, | ||
2988 | 1722 | addClasses: true, | ||
2989 | 1723 | greedy: false, | ||
2990 | 1724 | hoverClass: false, | ||
2991 | 1725 | scope: 'default', | ||
2992 | 1726 | tolerance: 'intersect' | ||
2993 | 1727 | }, | ||
2994 | 1728 | _create: function() { | ||
2995 | 1729 | |||
2996 | 1730 | var o = this.options, accept = o.accept; | ||
2997 | 1731 | this.isover = 0; this.isout = 1; | ||
2998 | 1732 | |||
2999 | 1733 | this.accept = $.isFunction(accept) ? accept : function(d) { | ||
3000 | 1734 | return d.is(accept); | ||
3001 | 1735 | }; | ||
3002 | 1736 | |||
3003 | 1737 | //Store the droppable's proportions | ||
3004 | 1738 | this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight }; | ||
3005 | 1739 | |||
3006 | 1740 | // Add the reference and positions to the manager | ||
3007 | 1741 | $.ui.ddmanager.droppables[o.scope] = $.ui.ddmanager.droppables[o.scope] || []; | ||
3008 | 1742 | $.ui.ddmanager.droppables[o.scope].push(this); | ||
3009 | 1743 | |||
3010 | 1744 | (o.addClasses && this.element.addClass("ui-droppable")); | ||
3011 | 1745 | |||
3012 | 1746 | }, | ||
3013 | 1747 | |||
3014 | 1748 | destroy: function() { | ||
3015 | 1749 | var drop = $.ui.ddmanager.droppables[this.options.scope]; | ||
3016 | 1750 | for ( var i = 0; i < drop.length; i++ ) | ||
3017 | 1751 | if ( drop[i] == this ) | ||
3018 | 1752 | drop.splice(i, 1); | ||
3019 | 1753 | |||
3020 | 1754 | this.element | ||
3021 | 1755 | .removeClass("ui-droppable ui-droppable-disabled") | ||
3022 | 1756 | .removeData("droppable") | ||
3023 | 1757 | .unbind(".droppable"); | ||
3024 | 1758 | |||
3025 | 1759 | return this; | ||
3026 | 1760 | }, | ||
3027 | 1761 | |||
3028 | 1762 | _setOption: function(key, value) { | ||
3029 | 1763 | |||
3030 | 1764 | if(key == 'accept') { | ||
3031 | 1765 | this.accept = $.isFunction(value) ? value : function(d) { | ||
3032 | 1766 | return d.is(value); | ||
3033 | 1767 | }; | ||
3034 | 1768 | } | ||
3035 | 1769 | $.Widget.prototype._setOption.apply(this, arguments); | ||
3036 | 1770 | }, | ||
3037 | 1771 | |||
3038 | 1772 | _activate: function(event) { | ||
3039 | 1773 | var draggable = $.ui.ddmanager.current; | ||
3040 | 1774 | if(this.options.activeClass) this.element.addClass(this.options.activeClass); | ||
3041 | 1775 | (draggable && this._trigger('activate', event, this.ui(draggable))); | ||
3042 | 1776 | }, | ||
3043 | 1777 | |||
3044 | 1778 | _deactivate: function(event) { | ||
3045 | 1779 | var draggable = $.ui.ddmanager.current; | ||
3046 | 1780 | if(this.options.activeClass) this.element.removeClass(this.options.activeClass); | ||
3047 | 1781 | (draggable && this._trigger('deactivate', event, this.ui(draggable))); | ||
3048 | 1782 | }, | ||
3049 | 1783 | |||
3050 | 1784 | _over: function(event) { | ||
3051 | 1785 | |||
3052 | 1786 | var draggable = $.ui.ddmanager.current; | ||
3053 | 1787 | if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element | ||
3054 | 1788 | |||
3055 | 1789 | if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) { | ||
3056 | 1790 | if(this.options.hoverClass) this.element.addClass(this.options.hoverClass); | ||
3057 | 1791 | this._trigger('over', event, this.ui(draggable)); | ||
3058 | 1792 | } | ||
3059 | 1793 | |||
3060 | 1794 | }, | ||
3061 | 1795 | |||
3062 | 1796 | _out: function(event) { | ||
3063 | 1797 | |||
3064 | 1798 | var draggable = $.ui.ddmanager.current; | ||
3065 | 1799 | if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element | ||
3066 | 1800 | |||
3067 | 1801 | if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) { | ||
3068 | 1802 | if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass); | ||
3069 | 1803 | this._trigger('out', event, this.ui(draggable)); | ||
3070 | 1804 | } | ||
3071 | 1805 | |||
3072 | 1806 | }, | ||
3073 | 1807 | |||
3074 | 1808 | _drop: function(event,custom) { | ||
3075 | 1809 | |||
3076 | 1810 | var draggable = custom || $.ui.ddmanager.current; | ||
3077 | 1811 | if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element | ||
3078 | 1812 | |||
3079 | 1813 | var childrenIntersection = false; | ||
3080 | 1814 | this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function() { | ||
3081 | 1815 | var inst = $.data(this, 'droppable'); | ||
3082 | 1816 | if( | ||
3083 | 1817 | inst.options.greedy | ||
3084 | 1818 | && !inst.options.disabled | ||
3085 | 1819 | && inst.options.scope == draggable.options.scope | ||
3086 | 1820 | && inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element)) | ||
3087 | 1821 | && $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance) | ||
3088 | 1822 | ) { childrenIntersection = true; return false; } | ||
3089 | 1823 | }); | ||
3090 | 1824 | if(childrenIntersection) return false; | ||
3091 | 1825 | |||
3092 | 1826 | if(this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) { | ||
3093 | 1827 | if(this.options.activeClass) this.element.removeClass(this.options.activeClass); | ||
3094 | 1828 | if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass); | ||
3095 | 1829 | this._trigger('drop', event, this.ui(draggable)); | ||
3096 | 1830 | return this.element; | ||
3097 | 1831 | } | ||
3098 | 1832 | |||
3099 | 1833 | return false; | ||
3100 | 1834 | |||
3101 | 1835 | }, | ||
3102 | 1836 | |||
3103 | 1837 | ui: function(c) { | ||
3104 | 1838 | return { | ||
3105 | 1839 | draggable: (c.currentItem || c.element), | ||
3106 | 1840 | helper: c.helper, | ||
3107 | 1841 | position: c.position, | ||
3108 | 1842 | offset: c.positionAbs | ||
3109 | 1843 | }; | ||
3110 | 1844 | } | ||
3111 | 1845 | |||
3112 | 1846 | }); | ||
3113 | 1847 | |||
3114 | 1848 | $.extend($.ui.droppable, { | ||
3115 | 1849 | version: "1.8.4" | ||
3116 | 1850 | }); | ||
3117 | 1851 | |||
3118 | 1852 | $.ui.intersect = function(draggable, droppable, toleranceMode) { | ||
3119 | 1853 | |||
3120 | 1854 | if (!droppable.offset) return false; | ||
3121 | 1855 | |||
3122 | 1856 | var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width, | ||
3123 | 1857 | y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height; | ||
3124 | 1858 | var l = droppable.offset.left, r = l + droppable.proportions.width, | ||
3125 | 1859 | t = droppable.offset.top, b = t + droppable.proportions.height; | ||
3126 | 1860 | |||
3127 | 1861 | switch (toleranceMode) { | ||
3128 | 1862 | case 'fit': | ||
3129 | 1863 | return (l <= x1 && x2 <= r | ||
3130 | 1864 | && t <= y1 && y2 <= b); | ||
3131 | 1865 | break; | ||
3132 | 1866 | case 'intersect': | ||
3133 | 1867 | return (l < x1 + (draggable.helperProportions.width / 2) // Right Half | ||
3134 | 1868 | && x2 - (draggable.helperProportions.width / 2) < r // Left Half | ||
3135 | 1869 | && t < y1 + (draggable.helperProportions.height / 2) // Bottom Half | ||
3136 | 1870 | && y2 - (draggable.helperProportions.height / 2) < b ); // Top Half | ||
3137 | 1871 | break; | ||
3138 | 1872 | case 'pointer': | ||
3139 | 1873 | var draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left), | ||
3140 | 1874 | draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top), | ||
3141 | 1875 | isOver = $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width); | ||
3142 | 1876 | return isOver; | ||
3143 | 1877 | break; | ||
3144 | 1878 | case 'touch': | ||
3145 | 1879 | return ( | ||
3146 | 1880 | (y1 >= t && y1 <= b) || // Top edge touching | ||
3147 | 1881 | (y2 >= t && y2 <= b) || // Bottom edge touching | ||
3148 | 1882 | (y1 < t && y2 > b) // Surrounded vertically | ||
3149 | 1883 | ) && ( | ||
3150 | 1884 | (x1 >= l && x1 <= r) || // Left edge touching | ||
3151 | 1885 | (x2 >= l && x2 <= r) || // Right edge touching | ||
3152 | 1886 | (x1 < l && x2 > r) // Surrounded horizontally | ||
3153 | 1887 | ); | ||
3154 | 1888 | break; | ||
3155 | 1889 | default: | ||
3156 | 1890 | return false; | ||
3157 | 1891 | break; | ||
3158 | 1892 | } | ||
3159 | 1893 | |||
3160 | 1894 | }; | ||
3161 | 1895 | |||
3162 | 1896 | /* | ||
3163 | 1897 | This manager tracks offsets of draggables and droppables | ||
3164 | 1898 | */ | ||
3165 | 1899 | $.ui.ddmanager = { | ||
3166 | 1900 | current: null, | ||
3167 | 1901 | droppables: { 'default': [] }, | ||
3168 | 1902 | prepareOffsets: function(t, event) { | ||
3169 | 1903 | |||
3170 | 1904 | var m = $.ui.ddmanager.droppables[t.options.scope] || []; | ||
3171 | 1905 | var type = event ? event.type : null; // workaround for #2317 | ||
3172 | 1906 | var list = (t.currentItem || t.element).find(":data(droppable)").andSelf(); | ||
3173 | 1907 | |||
3174 | 1908 | droppablesLoop: for (var i = 0; i < m.length; i++) { | ||
3175 | 1909 | |||
3176 | 1910 | if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) continue; //No disabled and non-accepted | ||
3177 | 1911 | for (var j=0; j < list.length; j++) { if(list[j] == m[i].element[0]) { m[i].proportions.height = 0; continue droppablesLoop; } }; //Filter out elements in the current dragged item | ||
3178 | 1912 | m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue | ||
3179 | 1913 | |||
3180 | 1914 | m[i].offset = m[i].element.offset(); | ||
3181 | 1915 | m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight }; | ||
3182 | 1916 | |||
3183 | 1917 | if(type == "mousedown") m[i]._activate.call(m[i], event); //Activate the droppable if used directly from draggables | ||
3184 | 1918 | |||
3185 | 1919 | } | ||
3186 | 1920 | |||
3187 | 1921 | }, | ||
3188 | 1922 | drop: function(draggable, event) { | ||
3189 | 1923 | |||
3190 | 1924 | var dropped = false; | ||
3191 | 1925 | $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() { | ||
3192 | 1926 | |||
3193 | 1927 | if(!this.options) return; | ||
3194 | 1928 | if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance)) | ||
3195 | 1929 | dropped = dropped || this._drop.call(this, event); | ||
3196 | 1930 | |||
3197 | 1931 | if (!this.options.disabled && this.visible && this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) { | ||
3198 | 1932 | this.isout = 1; this.isover = 0; | ||
3199 | 1933 | this._deactivate.call(this, event); | ||
3200 | 1934 | } | ||
3201 | 1935 | |||
3202 | 1936 | }); | ||
3203 | 1937 | return dropped; | ||
3204 | 1938 | |||
3205 | 1939 | }, | ||
3206 | 1940 | drag: function(draggable, event) { | ||
3207 | 1941 | |||
3208 | 1942 | //If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse. | ||
3209 | 1943 | if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, event); | ||
3210 | 1944 | |||
3211 | 1945 | //Run through all droppables and check their positions based on specific tolerance options | ||
3212 | 1946 | $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() { | ||
3213 | 1947 | |||
3214 | 1948 | if(this.options.disabled || this.greedyChild || !this.visible) return; | ||
3215 | 1949 | var intersects = $.ui.intersect(draggable, this, this.options.tolerance); | ||
3216 | 1950 | |||
3217 | 1951 | var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover == 0 ? 'isover' : null); | ||
3218 | 1952 | if(!c) return; | ||
3219 | 1953 | |||
3220 | 1954 | var parentInstance; | ||
3221 | 1955 | if (this.options.greedy) { | ||
3222 | 1956 | var parent = this.element.parents(':data(droppable):eq(0)'); | ||
3223 | 1957 | if (parent.length) { | ||
3224 | 1958 | parentInstance = $.data(parent[0], 'droppable'); | ||
3225 | 1959 | parentInstance.greedyChild = (c == 'isover' ? 1 : 0); | ||
3226 | 1960 | } | ||
3227 | 1961 | } | ||
3228 | 1962 | |||
3229 | 1963 | // we just moved into a greedy child | ||
3230 | 1964 | if (parentInstance && c == 'isover') { | ||
3231 | 1965 | parentInstance['isover'] = 0; | ||
3232 | 1966 | parentInstance['isout'] = 1; | ||
3233 | 1967 | parentInstance._out.call(parentInstance, event); | ||
3234 | 1968 | } | ||
3235 | 1969 | |||
3236 | 1970 | this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0; | ||
3237 | 1971 | this[c == "isover" ? "_over" : "_out"].call(this, event); | ||
3238 | 1972 | |||
3239 | 1973 | // we just moved out of a greedy child | ||
3240 | 1974 | if (parentInstance && c == 'isout') { | ||
3241 | 1975 | parentInstance['isout'] = 0; | ||
3242 | 1976 | parentInstance['isover'] = 1; | ||
3243 | 1977 | parentInstance._over.call(parentInstance, event); | ||
3244 | 1978 | } | ||
3245 | 1979 | }); | ||
3246 | 1980 | |||
3247 | 1981 | } | ||
3248 | 1982 | }; | ||
3249 | 1983 | |||
3250 | 1984 | })(jQuery); | ||
3251 | 1985 | /* | ||
3252 | 1986 | * jQuery UI Resizable 1.8.4 | ||
3253 | 1987 | * | ||
3254 | 1988 | * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about) | ||
3255 | 1989 | * Dual licensed under the MIT or GPL Version 2 licenses. | ||
3256 | 1990 | * http://jquery.org/license | ||
3257 | 1991 | * | ||
3258 | 1992 | * http://docs.jquery.com/UI/Resizables | ||
3259 | 1993 | * | ||
3260 | 1994 | * Depends: | ||
3261 | 1995 | * jquery.ui.core.js | ||
3262 | 1996 | * jquery.ui.mouse.js | ||
3263 | 1997 | * jquery.ui.widget.js | ||
3264 | 1998 | */ | ||
3265 | 1999 | (function( $, undefined ) { | ||
3266 | 2000 | |||
3267 | 2001 | $.widget("ui.resizable", $.ui.mouse, { | ||
3268 | 2002 | widgetEventPrefix: "resize", | ||
3269 | 2003 | options: { | ||
3270 | 2004 | alsoResize: false, | ||
3271 | 2005 | animate: false, | ||
3272 | 2006 | animateDuration: "slow", | ||
3273 | 2007 | animateEasing: "swing", | ||
3274 | 2008 | aspectRatio: false, | ||
3275 | 2009 | autoHide: false, | ||
3276 | 2010 | containment: false, | ||
3277 | 2011 | ghost: false, | ||
3278 | 2012 | grid: false, | ||
3279 | 2013 | handles: "e,s,se", | ||
3280 | 2014 | helper: false, | ||
3281 | 2015 | maxHeight: null, | ||
3282 | 2016 | maxWidth: null, | ||
3283 | 2017 | minHeight: 10, | ||
3284 | 2018 | minWidth: 10, | ||
3285 | 2019 | zIndex: 1000 | ||
3286 | 2020 | }, | ||
3287 | 2021 | _create: function() { | ||
3288 | 2022 | |||
3289 | 2023 | var self = this, o = this.options; | ||
3290 | 2024 | this.element.addClass("ui-resizable"); | ||
3291 | 2025 | |||
3292 | 2026 | $.extend(this, { | ||
3293 | 2027 | _aspectRatio: !!(o.aspectRatio), | ||
3294 | 2028 | aspectRatio: o.aspectRatio, | ||
3295 | 2029 | originalElement: this.element, | ||
3296 | 2030 | _proportionallyResizeElements: [], | ||
3297 | 2031 | _helper: o.helper || o.ghost || o.animate ? o.helper || 'ui-resizable-helper' : null | ||
3298 | 2032 | }); | ||
3299 | 2033 | |||
3300 | 2034 | //Wrap the element if it cannot hold child nodes | ||
3301 | 2035 | if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)) { | ||
3302 | 2036 | |||
3303 | 2037 | //Opera fix for relative positioning | ||
3304 | 2038 | if (/relative/.test(this.element.css('position')) && $.browser.opera) | ||
3305 | 2039 | this.element.css({ position: 'relative', top: 'auto', left: 'auto' }); | ||
3306 | 2040 | |||
3307 | 2041 | //Create a wrapper element and set the wrapper to the new current internal element | ||
3308 | 2042 | this.element.wrap( | ||
3309 | 2043 | $('<div class="ui-wrapper" style="overflow: hidden;"></div>').css({ | ||
3310 | 2044 | position: this.element.css('position'), | ||
3311 | 2045 | width: this.element.outerWidth(), | ||
3312 | 2046 | height: this.element.outerHeight(), | ||
3313 | 2047 | top: this.element.css('top'), | ||
3314 | 2048 | left: this.element.css('left') | ||
3315 | 2049 | }) | ||
3316 | 2050 | ); | ||
3317 | 2051 | |||
3318 | 2052 | //Overwrite the original this.element | ||
3319 | 2053 | this.element = this.element.parent().data( | ||
3320 | 2054 | "resizable", this.element.data('resizable') | ||
3321 | 2055 | ); | ||
3322 | 2056 | |||
3323 | 2057 | this.elementIsWrapper = true; | ||
3324 | 2058 | |||
3325 | 2059 | //Move margins to the wrapper | ||
3326 | 2060 | this.element.css({ marginLeft: this.originalElement.css("marginLeft"), marginTop: this.originalElement.css("marginTop"), marginRight: this.originalElement.css("marginRight"), marginBottom: this.originalElement.css("marginBottom") }); | ||
3327 | 2061 | this.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0}); | ||
3328 | 2062 | |||
3329 | 2063 | //Prevent Safari textarea resize | ||
3330 | 2064 | this.originalResizeStyle = this.originalElement.css('resize'); | ||
3331 | 2065 | this.originalElement.css('resize', 'none'); | ||
3332 | 2066 | |||
3333 | 2067 | //Push the actual element to our proportionallyResize internal array | ||
3334 | 2068 | this._proportionallyResizeElements.push(this.originalElement.css({ position: 'static', zoom: 1, display: 'block' })); | ||
3335 | 2069 | |||
3336 | 2070 | // avoid IE jump (hard set the margin) | ||
3337 | 2071 | this.originalElement.css({ margin: this.originalElement.css('margin') }); | ||
3338 | 2072 | |||
3339 | 2073 | // fix handlers offset | ||
3340 | 2074 | this._proportionallyResize(); | ||
3341 | 2075 | |||
3342 | 2076 | } | ||
3343 | 2077 | |||
3344 | 2078 | this.handles = o.handles || (!$('.ui-resizable-handle', this.element).length ? "e,s,se" : { n: '.ui-resizable-n', e: '.ui-resizable-e', s: '.ui-resizable-s', w: '.ui-resizable-w', se: '.ui-resizable-se', sw: '.ui-resizable-sw', ne: '.ui-resizable-ne', nw: '.ui-resizable-nw' }); | ||
3345 | 2079 | if(this.handles.constructor == String) { | ||
3346 | 2080 | |||
3347 | 2081 | if(this.handles == 'all') this.handles = 'n,e,s,w,se,sw,ne,nw'; | ||
3348 | 2082 | var n = this.handles.split(","); this.handles = {}; | ||
3349 | 2083 | |||
3350 | 2084 | for(var i = 0; i < n.length; i++) { | ||
3351 | 2085 | |||
3352 | 2086 | var handle = $.trim(n[i]), hname = 'ui-resizable-'+handle; | ||
3353 | 2087 | var axis = $('<div class="ui-resizable-handle ' + hname + '"></div>'); | ||
3354 | 2088 | |||
3355 | 2089 | // increase zIndex of sw, se, ne, nw axis | ||
3356 | 2090 | //TODO : this modifies original option | ||
3357 | 2091 | if(/sw|se|ne|nw/.test(handle)) axis.css({ zIndex: ++o.zIndex }); | ||
3358 | 2092 | |||
3359 | 2093 | //TODO : What's going on here? | ||
3360 | 2094 | if ('se' == handle) { | ||
3361 | 2095 | axis.addClass('ui-icon ui-icon-gripsmall-diagonal-se'); | ||
3362 | 2096 | }; | ||
3363 | 2097 | |||
3364 | 2098 | //Insert into internal handles object and append to element | ||
3365 | 2099 | this.handles[handle] = '.ui-resizable-'+handle; | ||
3366 | 2100 | this.element.append(axis); | ||
3367 | 2101 | } | ||
3368 | 2102 | |||
3369 | 2103 | } | ||
3370 | 2104 | |||
3371 | 2105 | this._renderAxis = function(target) { | ||
3372 | 2106 | |||
3373 | 2107 | target = target || this.element; | ||
3374 | 2108 | |||
3375 | 2109 | for(var i in this.handles) { | ||
3376 | 2110 | |||
3377 | 2111 | if(this.handles[i].constructor == String) | ||
3378 | 2112 | this.handles[i] = $(this.handles[i], this.element).show(); | ||
3379 | 2113 | |||
3380 | 2114 | //Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls) | ||
3381 | 2115 | if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) { | ||
3382 | 2116 | |||
3383 | 2117 | var axis = $(this.handles[i], this.element), padWrapper = 0; | ||
3384 | 2118 | |||
3385 | 2119 | //Checking the correct pad and border | ||
3386 | 2120 | padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth(); | ||
3387 | 2121 | |||
3388 | 2122 | //The padding type i have to apply... | ||
3389 | 2123 | var padPos = [ 'padding', | ||
3390 | 2124 | /ne|nw|n/.test(i) ? 'Top' : | ||
3391 | 2125 | /se|sw|s/.test(i) ? 'Bottom' : | ||
3392 | 2126 | /^e$/.test(i) ? 'Right' : 'Left' ].join(""); | ||
3393 | 2127 | |||
3394 | 2128 | target.css(padPos, padWrapper); | ||
3395 | 2129 | |||
3396 | 2130 | this._proportionallyResize(); | ||
3397 | 2131 | |||
3398 | 2132 | } | ||
3399 | 2133 | |||
3400 | 2134 | //TODO: What's that good for? There's not anything to be executed left | ||
3401 | 2135 | if(!$(this.handles[i]).length) | ||
3402 | 2136 | continue; | ||
3403 | 2137 | |||
3404 | 2138 | } | ||
3405 | 2139 | }; | ||
3406 | 2140 | |||
3407 | 2141 | //TODO: make renderAxis a prototype function | ||
3408 | 2142 | this._renderAxis(this.element); | ||
3409 | 2143 | |||
3410 | 2144 | this._handles = $('.ui-resizable-handle', this.element) | ||
3411 | 2145 | .disableSelection(); | ||
3412 | 2146 | |||
3413 | 2147 | //Matching axis name | ||
3414 | 2148 | this._handles.mouseover(function() { | ||
3415 | 2149 | if (!self.resizing) { | ||
3416 | 2150 | if (this.className) | ||
3417 | 2151 | var axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i); | ||
3418 | 2152 | //Axis, default = se | ||
3419 | 2153 | self.axis = axis && axis[1] ? axis[1] : 'se'; | ||
3420 | 2154 | } | ||
3421 | 2155 | }); | ||
3422 | 2156 | |||
3423 | 2157 | //If we want to auto hide the elements | ||
3424 | 2158 | if (o.autoHide) { | ||
3425 | 2159 | this._handles.hide(); | ||
3426 | 2160 | $(this.element) | ||
3427 | 2161 | .addClass("ui-resizable-autohide") | ||
3428 | 2162 | .hover(function() { | ||
3429 | 2163 | $(this).removeClass("ui-resizable-autohide"); | ||
3430 | 2164 | self._handles.show(); | ||
3431 | 2165 | }, | ||
3432 | 2166 | function(){ | ||
3433 | 2167 | if (!self.resizing) { | ||
3434 | 2168 | $(this).addClass("ui-resizable-autohide"); | ||
3435 | 2169 | self._handles.hide(); | ||
3436 | 2170 | } | ||
3437 | 2171 | }); | ||
3438 | 2172 | } | ||
3439 | 2173 | |||
3440 | 2174 | //Initialize the mouse interaction | ||
3441 | 2175 | this._mouseInit(); | ||
3442 | 2176 | |||
3443 | 2177 | }, | ||
3444 | 2178 | |||
3445 | 2179 | destroy: function() { | ||
3446 | 2180 | |||
3447 | 2181 | this._mouseDestroy(); | ||
3448 | 2182 | |||
3449 | 2183 | var _destroy = function(exp) { | ||
3450 | 2184 | $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing") | ||
3451 | 2185 | .removeData("resizable").unbind(".resizable").find('.ui-resizable-handle').remove(); | ||
3452 | 2186 | }; | ||
3453 | 2187 | |||
3454 | 2188 | //TODO: Unwrap at same DOM position | ||
3455 | 2189 | if (this.elementIsWrapper) { | ||
3456 | 2190 | _destroy(this.element); | ||
3457 | 2191 | var wrapper = this.element; | ||
3458 | 2192 | wrapper.after( | ||
3459 | 2193 | this.originalElement.css({ | ||
3460 | 2194 | position: wrapper.css('position'), | ||
3461 | 2195 | width: wrapper.outerWidth(), | ||
3462 | 2196 | height: wrapper.outerHeight(), | ||
3463 | 2197 | top: wrapper.css('top'), | ||
3464 | 2198 | left: wrapper.css('left') | ||
3465 | 2199 | }) | ||
3466 | 2200 | ).remove(); | ||
3467 | 2201 | } | ||
3468 | 2202 | |||
3469 | 2203 | this.originalElement.css('resize', this.originalResizeStyle); | ||
3470 | 2204 | _destroy(this.originalElement); | ||
3471 | 2205 | |||
3472 | 2206 | return this; | ||
3473 | 2207 | }, | ||
3474 | 2208 | |||
3475 | 2209 | _mouseCapture: function(event) { | ||
3476 | 2210 | var handle = false; | ||
3477 | 2211 | for (var i in this.handles) { | ||
3478 | 2212 | if ($(this.handles[i])[0] == event.target) { | ||
3479 | 2213 | handle = true; | ||
3480 | 2214 | } | ||
3481 | 2215 | } | ||
3482 | 2216 | |||
3483 | 2217 | return !this.options.disabled && handle; | ||
3484 | 2218 | }, | ||
3485 | 2219 | |||
3486 | 2220 | _mouseStart: function(event) { | ||
3487 | 2221 | |||
3488 | 2222 | var o = this.options, iniPos = this.element.position(), el = this.element; | ||
3489 | 2223 | |||
3490 | 2224 | this.resizing = true; | ||
3491 | 2225 | this.documentScroll = { top: $(document).scrollTop(), left: $(document).scrollLeft() }; | ||
3492 | 2226 | |||
3493 | 2227 | // bugfix for http://dev.jquery.com/ticket/1749 | ||
3494 | 2228 | if (el.is('.ui-draggable') || (/absolute/).test(el.css('position'))) { | ||
3495 | 2229 | el.css({ position: 'absolute', top: iniPos.top, left: iniPos.left }); | ||
3496 | 2230 | } | ||
3497 | 2231 | |||
3498 | 2232 | //Opera fixing relative position | ||
3499 | 2233 | if ($.browser.opera && (/relative/).test(el.css('position'))) | ||
3500 | 2234 | el.css({ position: 'relative', top: 'auto', left: 'auto' }); | ||
3501 | 2235 | |||
3502 | 2236 | this._renderProxy(); | ||
3503 | 2237 | |||
3504 | 2238 | var curleft = num(this.helper.css('left')), curtop = num(this.helper.css('top')); | ||
3505 | 2239 | |||
3506 | 2240 | if (o.containment) { | ||
3507 | 2241 | curleft += $(o.containment).scrollLeft() || 0; | ||
3508 | 2242 | curtop += $(o.containment).scrollTop() || 0; | ||
3509 | 2243 | } | ||
3510 | 2244 | |||
3511 | 2245 | //Store needed variables | ||
3512 | 2246 | this.offset = this.helper.offset(); | ||
3513 | 2247 | this.position = { left: curleft, top: curtop }; | ||
3514 | 2248 | this.size = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() }; | ||
3515 | 2249 | this.originalSize = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() }; | ||
3516 | 2250 | this.originalPosition = { left: curleft, top: curtop }; | ||
3517 | 2251 | this.sizeDiff = { width: el.outerWidth() - el.width(), height: el.outerHeight() - el.height() }; | ||
3518 | 2252 | this.originalMousePosition = { left: event.pageX, top: event.pageY }; | ||
3519 | 2253 | |||
3520 | 2254 | //Aspect Ratio | ||
3521 | 2255 | this.aspectRatio = (typeof o.aspectRatio == 'number') ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height) || 1); | ||
3522 | 2256 | |||
3523 | 2257 | var cursor = $('.ui-resizable-' + this.axis).css('cursor'); | ||
3524 | 2258 | $('body').css('cursor', cursor == 'auto' ? this.axis + '-resize' : cursor); | ||
3525 | 2259 | |||
3526 | 2260 | el.addClass("ui-resizable-resizing"); | ||
3527 | 2261 | this._propagate("start", event); | ||
3528 | 2262 | return true; | ||
3529 | 2263 | }, | ||
3530 | 2264 | |||
3531 | 2265 | _mouseDrag: function(event) { | ||
3532 | 2266 | |||
3533 | 2267 | //Increase performance, avoid regex | ||
3534 | 2268 | var el = this.helper, o = this.options, props = {}, | ||
3535 | 2269 | self = this, smp = this.originalMousePosition, a = this.axis; | ||
3536 | 2270 | |||
3537 | 2271 | var dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0; | ||
3538 | 2272 | var trigger = this._change[a]; | ||
3539 | 2273 | if (!trigger) return false; | ||
3540 | 2274 | |||
3541 | 2275 | // Calculate the attrs that will be change | ||
3542 | 2276 | var data = trigger.apply(this, [event, dx, dy]), ie6 = $.browser.msie && $.browser.version < 7, csdif = this.sizeDiff; | ||
3543 | 2277 | |||
3544 | 2278 | if (this._aspectRatio || event.shiftKey) | ||
3545 | 2279 | data = this._updateRatio(data, event); | ||
3546 | 2280 | |||
3547 | 2281 | data = this._respectSize(data, event); | ||
3548 | 2282 | |||
3549 | 2283 | // plugins callbacks need to be called first | ||
3550 | 2284 | this._propagate("resize", event); | ||
3551 | 2285 | |||
3552 | 2286 | el.css({ | ||
3553 | 2287 | top: this.position.top + "px", left: this.position.left + "px", | ||
3554 | 2288 | width: this.size.width + "px", height: this.size.height + "px" | ||
3555 | 2289 | }); | ||
3556 | 2290 | |||
3557 | 2291 | if (!this._helper && this._proportionallyResizeElements.length) | ||
3558 | 2292 | this._proportionallyResize(); | ||
3559 | 2293 | |||
3560 | 2294 | this._updateCache(data); | ||
3561 | 2295 | |||
3562 | 2296 | // calling the user callback at the end | ||
3563 | 2297 | this._trigger('resize', event, this.ui()); | ||
3564 | 2298 | |||
3565 | 2299 | return false; | ||
3566 | 2300 | }, | ||
3567 | 2301 | |||
3568 | 2302 | _mouseStop: function(event) { | ||
3569 | 2303 | |||
3570 | 2304 | this.resizing = false; | ||
3571 | 2305 | var o = this.options, self = this; | ||
3572 | 2306 | |||
3573 | 2307 | if(this._helper) { | ||
3574 | 2308 | var pr = this._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName), | ||
3575 | 2309 | soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : self.sizeDiff.height, | ||
3576 | 2310 | soffsetw = ista ? 0 : self.sizeDiff.width; | ||
3577 | 2311 | |||
3578 | 2312 | var s = { width: (self.size.width - soffsetw), height: (self.size.height - soffseth) }, | ||
3579 | 2313 | left = (parseInt(self.element.css('left'), 10) + (self.position.left - self.originalPosition.left)) || null, | ||
3580 | 2314 | top = (parseInt(self.element.css('top'), 10) + (self.position.top - self.originalPosition.top)) || null; | ||
3581 | 2315 | |||
3582 | 2316 | if (!o.animate) | ||
3583 | 2317 | this.element.css($.extend(s, { top: top, left: left })); | ||
3584 | 2318 | |||
3585 | 2319 | self.helper.height(self.size.height); | ||
3586 | 2320 | self.helper.width(self.size.width); | ||
3587 | 2321 | |||
3588 | 2322 | if (this._helper && !o.animate) this._proportionallyResize(); | ||
3589 | 2323 | } | ||
3590 | 2324 | |||
3591 | 2325 | $('body').css('cursor', 'auto'); | ||
3592 | 2326 | |||
3593 | 2327 | this.element.removeClass("ui-resizable-resizing"); | ||
3594 | 2328 | |||
3595 | 2329 | this._propagate("stop", event); | ||
3596 | 2330 | |||
3597 | 2331 | if (this._helper) this.helper.remove(); | ||
3598 | 2332 | return false; | ||
3599 | 2333 | |||
3600 | 2334 | }, | ||
3601 | 2335 | |||
3602 | 2336 | _updateCache: function(data) { | ||
3603 | 2337 | var o = this.options; | ||
3604 | 2338 | this.offset = this.helper.offset(); | ||
3605 | 2339 | if (isNumber(data.left)) this.position.left = data.left; | ||
3606 | 2340 | if (isNumber(data.top)) this.position.top = data.top; | ||
3607 | 2341 | if (isNumber(data.height)) this.size.height = data.height; | ||
3608 | 2342 | if (isNumber(data.width)) this.size.width = data.width; | ||
3609 | 2343 | }, | ||
3610 | 2344 | |||
3611 | 2345 | _updateRatio: function(data, event) { | ||
3612 | 2346 | |||
3613 | 2347 | var o = this.options, cpos = this.position, csize = this.size, a = this.axis; | ||
3614 | 2348 | |||
3615 | 2349 | if (data.height) data.width = (csize.height * this.aspectRatio); | ||
3616 | 2350 | else if (data.width) data.height = (csize.width / this.aspectRatio); | ||
3617 | 2351 | |||
3618 | 2352 | if (a == 'sw') { | ||
3619 | 2353 | data.left = cpos.left + (csize.width - data.width); | ||
3620 | 2354 | data.top = null; | ||
3621 | 2355 | } | ||
3622 | 2356 | if (a == 'nw') { | ||
3623 | 2357 | data.top = cpos.top + (csize.height - data.height); | ||
3624 | 2358 | data.left = cpos.left + (csize.width - data.width); | ||
3625 | 2359 | } | ||
3626 | 2360 | |||
3627 | 2361 | return data; | ||
3628 | 2362 | }, | ||
3629 | 2363 | |||
3630 | 2364 | _respectSize: function(data, event) { | ||
3631 | 2365 | |||
3632 | 2366 | var el = this.helper, o = this.options, pRatio = this._aspectRatio || event.shiftKey, a = this.axis, | ||
3633 | 2367 | ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height), | ||
3634 | 2368 | isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height); | ||
3635 | 2369 | |||
3636 | 2370 | if (isminw) data.width = o.minWidth; | ||
3637 | 2371 | if (isminh) data.height = o.minHeight; | ||
3638 | 2372 | if (ismaxw) data.width = o.maxWidth; | ||
3639 | 2373 | if (ismaxh) data.height = o.maxHeight; | ||
3640 | 2374 | |||
3641 | 2375 | var dw = this.originalPosition.left + this.originalSize.width, dh = this.position.top + this.size.height; | ||
3642 | 2376 | var cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a); | ||
3643 | 2377 | |||
3644 | 2378 | if (isminw && cw) data.left = dw - o.minWidth; | ||
3645 | 2379 | if (ismaxw && cw) data.left = dw - o.maxWidth; | ||
3646 | 2380 | if (isminh && ch) data.top = dh - o.minHeight; | ||
3647 | 2381 | if (ismaxh && ch) data.top = dh - o.maxHeight; | ||
3648 | 2382 | |||
3649 | 2383 | // fixing jump error on top/left - bug #2330 | ||
3650 | 2384 | var isNotwh = !data.width && !data.height; | ||
3651 | 2385 | if (isNotwh && !data.left && data.top) data.top = null; | ||
3652 | 2386 | else if (isNotwh && !data.top && data.left) data.left = null; | ||
3653 | 2387 | |||
3654 | 2388 | return data; | ||
3655 | 2389 | }, | ||
3656 | 2390 | |||
3657 | 2391 | _proportionallyResize: function() { | ||
3658 | 2392 | |||
3659 | 2393 | var o = this.options; | ||
3660 | 2394 | if (!this._proportionallyResizeElements.length) return; | ||
3661 | 2395 | var element = this.helper || this.element; | ||
3662 | 2396 | |||
3663 | 2397 | for (var i=0; i < this._proportionallyResizeElements.length; i++) { | ||
3664 | 2398 | |||
3665 | 2399 | var prel = this._proportionallyResizeElements[i]; | ||
3666 | 2400 | |||
3667 | 2401 | if (!this.borderDif) { | ||
3668 | 2402 | var b = [prel.css('borderTopWidth'), prel.css('borderRightWidth'), prel.css('borderBottomWidth'), prel.css('borderLeftWidth')], | ||
3669 | 2403 | p = [prel.css('paddingTop'), prel.css('paddingRight'), prel.css('paddingBottom'), prel.css('paddingLeft')]; | ||
3670 | 2404 | |||
3671 | 2405 | this.borderDif = $.map(b, function(v, i) { | ||
3672 | 2406 | var border = parseInt(v,10)||0, padding = parseInt(p[i],10)||0; | ||
3673 | 2407 | return border + padding; | ||
3674 | 2408 | }); | ||
3675 | 2409 | } | ||
3676 | 2410 | |||
3677 | 2411 | if ($.browser.msie && !(!($(element).is(':hidden') || $(element).parents(':hidden').length))) | ||
3678 | 2412 | continue; | ||
3679 | 2413 | |||
3680 | 2414 | prel.css({ | ||
3681 | 2415 | height: (element.height() - this.borderDif[0] - this.borderDif[2]) || 0, | ||
3682 | 2416 | width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0 | ||
3683 | 2417 | }); | ||
3684 | 2418 | |||
3685 | 2419 | }; | ||
3686 | 2420 | |||
3687 | 2421 | }, | ||
3688 | 2422 | |||
3689 | 2423 | _renderProxy: function() { | ||
3690 | 2424 | |||
3691 | 2425 | var el = this.element, o = this.options; | ||
3692 | 2426 | this.elementOffset = el.offset(); | ||
3693 | 2427 | |||
3694 | 2428 | if(this._helper) { | ||
3695 | 2429 | |||
3696 | 2430 | this.helper = this.helper || $('<div style="overflow:hidden;"></div>'); | ||
3697 | 2431 | |||
3698 | 2432 | // fix ie6 offset TODO: This seems broken | ||
3699 | 2433 | var ie6 = $.browser.msie && $.browser.version < 7, ie6offset = (ie6 ? 1 : 0), | ||
3700 | 2434 | pxyoffset = ( ie6 ? 2 : -1 ); | ||
3701 | 2435 | |||
3702 | 2436 | this.helper.addClass(this._helper).css({ | ||
3703 | 2437 | width: this.element.outerWidth() + pxyoffset, | ||
3704 | 2438 | height: this.element.outerHeight() + pxyoffset, | ||
3705 | 2439 | position: 'absolute', | ||
3706 | 2440 | left: this.elementOffset.left - ie6offset +'px', | ||
3707 | 2441 | top: this.elementOffset.top - ie6offset +'px', | ||
3708 | 2442 | zIndex: ++o.zIndex //TODO: Don't modify option | ||
3709 | 2443 | }); | ||
3710 | 2444 | |||
3711 | 2445 | this.helper | ||
3712 | 2446 | .appendTo("body") | ||
3713 | 2447 | .disableSelection(); | ||
3714 | 2448 | |||
3715 | 2449 | } else { | ||
3716 | 2450 | this.helper = this.element; | ||
3717 | 2451 | } | ||
3718 | 2452 | |||
3719 | 2453 | }, | ||
3720 | 2454 | |||
3721 | 2455 | _change: { | ||
3722 | 2456 | e: function(event, dx, dy) { | ||
3723 | 2457 | return { width: this.originalSize.width + dx }; | ||
3724 | 2458 | }, | ||
3725 | 2459 | w: function(event, dx, dy) { | ||
3726 | 2460 | var o = this.options, cs = this.originalSize, sp = this.originalPosition; | ||
3727 | 2461 | return { left: sp.left + dx, width: cs.width - dx }; | ||
3728 | 2462 | }, | ||
3729 | 2463 | n: function(event, dx, dy) { | ||
3730 | 2464 | var o = this.options, cs = this.originalSize, sp = this.originalPosition; | ||
3731 | 2465 | return { top: sp.top + dy, height: cs.height - dy }; | ||
3732 | 2466 | }, | ||
3733 | 2467 | s: function(event, dx, dy) { | ||
3734 | 2468 | return { height: this.originalSize.height + dy }; | ||
3735 | 2469 | }, | ||
3736 | 2470 | se: function(event, dx, dy) { | ||
3737 | 2471 | return $.extend(this._change.s.apply(this, arguments), this._change.e.apply(this, [event, dx, dy])); | ||
3738 | 2472 | }, | ||
3739 | 2473 | sw: function(event, dx, dy) { | ||
3740 | 2474 | return $.extend(this._change.s.apply(this, arguments), this._change.w.apply(this, [event, dx, dy])); | ||
3741 | 2475 | }, | ||
3742 | 2476 | ne: function(event, dx, dy) { | ||
3743 | 2477 | return $.extend(this._change.n.apply(this, arguments), this._change.e.apply(this, [event, dx, dy])); | ||
3744 | 2478 | }, | ||
3745 | 2479 | nw: function(event, dx, dy) { | ||
3746 | 2480 | return $.extend(this._change.n.apply(this, arguments), this._change.w.apply(this, [event, dx, dy])); | ||
3747 | 2481 | } | ||
3748 | 2482 | }, | ||
3749 | 2483 | |||
3750 | 2484 | _propagate: function(n, event) { | ||
3751 | 2485 | $.ui.plugin.call(this, n, [event, this.ui()]); | ||
3752 | 2486 | (n != "resize" && this._trigger(n, event, this.ui())); | ||
3753 | 2487 | }, | ||
3754 | 2488 | |||
3755 | 2489 | plugins: {}, | ||
3756 | 2490 | |||
3757 | 2491 | ui: function() { | ||
3758 | 2492 | return { | ||
3759 | 2493 | originalElement: this.originalElement, | ||
3760 | 2494 | element: this.element, | ||
3761 | 2495 | helper: this.helper, | ||
3762 | 2496 | position: this.position, | ||
3763 | 2497 | size: this.size, | ||
3764 | 2498 | originalSize: this.originalSize, | ||
3765 | 2499 | originalPosition: this.originalPosition | ||
3766 | 2500 | }; | ||
3767 | 2501 | } | ||
3768 | 2502 | |||
3769 | 2503 | }); | ||
3770 | 2504 | |||
3771 | 2505 | $.extend($.ui.resizable, { | ||
3772 | 2506 | version: "1.8.4" | ||
3773 | 2507 | }); | ||
3774 | 2508 | |||
3775 | 2509 | /* | ||
3776 | 2510 | * Resizable Extensions | ||
3777 | 2511 | */ | ||
3778 | 2512 | |||
3779 | 2513 | $.ui.plugin.add("resizable", "alsoResize", { | ||
3780 | 2514 | |||
3781 | 2515 | start: function (event, ui) { | ||
3782 | 2516 | var self = $(this).data("resizable"), o = self.options; | ||
3783 | 2517 | |||
3784 | 2518 | var _store = function (exp) { | ||
3785 | 2519 | $(exp).each(function() { | ||
3786 | 2520 | var el = $(this); | ||
3787 | 2521 | el.data("resizable-alsoresize", { | ||
3788 | 2522 | width: parseInt(el.width(), 10), height: parseInt(el.height(), 10), | ||
3789 | 2523 | left: parseInt(el.css('left'), 10), top: parseInt(el.css('top'), 10), | ||
3790 | 2524 | position: el.css('position') // to reset Opera on stop() | ||
3791 | 2525 | }); | ||
3792 | 2526 | }); | ||
3793 | 2527 | }; | ||
3794 | 2528 | |||
3795 | 2529 | if (typeof(o.alsoResize) == 'object' && !o.alsoResize.parentNode) { | ||
3796 | 2530 | if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); } | ||
3797 | 2531 | else { $.each(o.alsoResize, function (exp) { _store(exp); }); } | ||
3798 | 2532 | }else{ | ||
3799 | 2533 | _store(o.alsoResize); | ||
3800 | 2534 | } | ||
3801 | 2535 | }, | ||
3802 | 2536 | |||
3803 | 2537 | resize: function (event, ui) { | ||
3804 | 2538 | var self = $(this).data("resizable"), o = self.options, os = self.originalSize, op = self.originalPosition; | ||
3805 | 2539 | |||
3806 | 2540 | var delta = { | ||
3807 | 2541 | height: (self.size.height - os.height) || 0, width: (self.size.width - os.width) || 0, | ||
3808 | 2542 | top: (self.position.top - op.top) || 0, left: (self.position.left - op.left) || 0 | ||
3809 | 2543 | }, | ||
3810 | 2544 | |||
3811 | 2545 | _alsoResize = function (exp, c) { | ||
3812 | 2546 | $(exp).each(function() { | ||
3813 | 2547 | var el = $(this), start = $(this).data("resizable-alsoresize"), style = {}, | ||
3814 | 2548 | css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ['width', 'height'] : ['width', 'height', 'top', 'left']; | ||
3815 | 2549 | |||
3816 | 2550 | $.each(css, function (i, prop) { | ||
3817 | 2551 | var sum = (start[prop]||0) + (delta[prop]||0); | ||
3818 | 2552 | if (sum && sum >= 0) | ||
3819 | 2553 | style[prop] = sum || null; | ||
3820 | 2554 | }); | ||
3821 | 2555 | |||
3822 | 2556 | // Opera fixing relative position | ||
3823 | 2557 | if ($.browser.opera && /relative/.test(el.css('position'))) { | ||
3824 | 2558 | self._revertToRelativePosition = true; | ||
3825 | 2559 | el.css({ position: 'absolute', top: 'auto', left: 'auto' }); | ||
3826 | 2560 | } | ||
3827 | 2561 | |||
3828 | 2562 | el.css(style); | ||
3829 | 2563 | }); | ||
3830 | 2564 | }; | ||
3831 | 2565 | |||
3832 | 2566 | if (typeof(o.alsoResize) == 'object' && !o.alsoResize.nodeType) { | ||
3833 | 2567 | $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); }); | ||
3834 | 2568 | }else{ | ||
3835 | 2569 | _alsoResize(o.alsoResize); | ||
3836 | 2570 | } | ||
3837 | 2571 | }, | ||
3838 | 2572 | |||
3839 | 2573 | stop: function (event, ui) { | ||
3840 | 2574 | var self = $(this).data("resizable"), o = self.options; | ||
3841 | 2575 | |||
3842 | 2576 | var _reset = function (exp) { | ||
3843 | 2577 | $(exp).each(function() { | ||
3844 | 2578 | var el = $(this); | ||
3845 | 2579 | // reset position for Opera - no need to verify it was changed | ||
3846 | 2580 | el.css({ position: el.data("resizable-alsoresize").position }); | ||
3847 | 2581 | }); | ||
3848 | 2582 | } | ||
3849 | 2583 | |||
3850 | 2584 | if (self._revertToRelativePosition) { | ||
3851 | 2585 | self._revertToRelativePosition = false; | ||
3852 | 2586 | if (typeof(o.alsoResize) == 'object' && !o.alsoResize.nodeType) { | ||
3853 | 2587 | $.each(o.alsoResize, function (exp) { _reset(exp); }); | ||
3854 | 2588 | }else{ | ||
3855 | 2589 | _reset(o.alsoResize); | ||
3856 | 2590 | } | ||
3857 | 2591 | } | ||
3858 | 2592 | |||
3859 | 2593 | $(this).removeData("resizable-alsoresize"); | ||
3860 | 2594 | } | ||
3861 | 2595 | }); | ||
3862 | 2596 | |||
3863 | 2597 | $.ui.plugin.add("resizable", "animate", { | ||
3864 | 2598 | |||
3865 | 2599 | stop: function(event, ui) { | ||
3866 | 2600 | var self = $(this).data("resizable"), o = self.options; | ||
3867 | 2601 | |||
3868 | 2602 | var pr = self._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName), | ||
3869 | 2603 | soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : self.sizeDiff.height, | ||
3870 | 2604 | soffsetw = ista ? 0 : self.sizeDiff.width; | ||
3871 | 2605 | |||
3872 | 2606 | var style = { width: (self.size.width - soffsetw), height: (self.size.height - soffseth) }, | ||
3873 | 2607 | left = (parseInt(self.element.css('left'), 10) + (self.position.left - self.originalPosition.left)) || null, | ||
3874 | 2608 | top = (parseInt(self.element.css('top'), 10) + (self.position.top - self.originalPosition.top)) || null; | ||
3875 | 2609 | |||
3876 | 2610 | self.element.animate( | ||
3877 | 2611 | $.extend(style, top && left ? { top: top, left: left } : {}), { | ||
3878 | 2612 | duration: o.animateDuration, | ||
3879 | 2613 | easing: o.animateEasing, | ||
3880 | 2614 | step: function() { | ||
3881 | 2615 | |||
3882 | 2616 | var data = { | ||
3883 | 2617 | width: parseInt(self.element.css('width'), 10), | ||
3884 | 2618 | height: parseInt(self.element.css('height'), 10), | ||
3885 | 2619 | top: parseInt(self.element.css('top'), 10), | ||
3886 | 2620 | left: parseInt(self.element.css('left'), 10) | ||
3887 | 2621 | }; | ||
3888 | 2622 | |||
3889 | 2623 | if (pr && pr.length) $(pr[0]).css({ width: data.width, height: data.height }); | ||
3890 | 2624 | |||
3891 | 2625 | // propagating resize, and updating values for each animation step | ||
3892 | 2626 | self._updateCache(data); | ||
3893 | 2627 | self._propagate("resize", event); | ||
3894 | 2628 | |||
3895 | 2629 | } | ||
3896 | 2630 | } | ||
3897 | 2631 | ); | ||
3898 | 2632 | } | ||
3899 | 2633 | |||
3900 | 2634 | }); | ||
3901 | 2635 | |||
3902 | 2636 | $.ui.plugin.add("resizable", "containment", { | ||
3903 | 2637 | |||
3904 | 2638 | start: function(event, ui) { | ||
3905 | 2639 | var self = $(this).data("resizable"), o = self.options, el = self.element; | ||
3906 | 2640 | var oc = o.containment, ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc; | ||
3907 | 2641 | if (!ce) return; | ||
3908 | 2642 | |||
3909 | 2643 | self.containerElement = $(ce); | ||
3910 | 2644 | |||
3911 | 2645 | if (/document/.test(oc) || oc == document) { | ||
3912 | 2646 | self.containerOffset = { left: 0, top: 0 }; | ||
3913 | 2647 | self.containerPosition = { left: 0, top: 0 }; | ||
3914 | 2648 | |||
3915 | 2649 | self.parentData = { | ||
3916 | 2650 | element: $(document), left: 0, top: 0, | ||
3917 | 2651 | width: $(document).width(), height: $(document).height() || document.body.parentNode.scrollHeight | ||
3918 | 2652 | }; | ||
3919 | 2653 | } | ||
3920 | 2654 | |||
3921 | 2655 | // i'm a node, so compute top, left, right, bottom | ||
3922 | 2656 | else { | ||
3923 | 2657 | var element = $(ce), p = []; | ||
3924 | 2658 | $([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = num(element.css("padding" + name)); }); | ||
3925 | 2659 | |||
3926 | 2660 | self.containerOffset = element.offset(); | ||
3927 | 2661 | self.containerPosition = element.position(); | ||
3928 | 2662 | self.containerSize = { height: (element.innerHeight() - p[3]), width: (element.innerWidth() - p[1]) }; | ||
3929 | 2663 | |||
3930 | 2664 | var co = self.containerOffset, ch = self.containerSize.height, cw = self.containerSize.width, | ||
3931 | 2665 | width = ($.ui.hasScroll(ce, "left") ? ce.scrollWidth : cw ), height = ($.ui.hasScroll(ce) ? ce.scrollHeight : ch); | ||
3932 | 2666 | |||
3933 | 2667 | self.parentData = { | ||
3934 | 2668 | element: ce, left: co.left, top: co.top, width: width, height: height | ||
3935 | 2669 | }; | ||
3936 | 2670 | } | ||
3937 | 2671 | }, | ||
3938 | 2672 | |||
3939 | 2673 | resize: function(event, ui) { | ||
3940 | 2674 | var self = $(this).data("resizable"), o = self.options, | ||
3941 | 2675 | ps = self.containerSize, co = self.containerOffset, cs = self.size, cp = self.position, | ||
3942 | 2676 | pRatio = self._aspectRatio || event.shiftKey, cop = { top:0, left:0 }, ce = self.containerElement; | ||
3943 | 2677 | |||
3944 | 2678 | if (ce[0] != document && (/static/).test(ce.css('position'))) cop = co; | ||
3945 | 2679 | |||
3946 | 2680 | if (cp.left < (self._helper ? co.left : 0)) { | ||
3947 | 2681 | self.size.width = self.size.width + (self._helper ? (self.position.left - co.left) : (self.position.left - cop.left)); | ||
3948 | 2682 | if (pRatio) self.size.height = self.size.width / o.aspectRatio; | ||
3949 | 2683 | self.position.left = o.helper ? co.left : 0; | ||
3950 | 2684 | } | ||
3951 | 2685 | |||
3952 | 2686 | if (cp.top < (self._helper ? co.top : 0)) { | ||
3953 | 2687 | self.size.height = self.size.height + (self._helper ? (self.position.top - co.top) : self.position.top); | ||
3954 | 2688 | if (pRatio) self.size.width = self.size.height * o.aspectRatio; | ||
3955 | 2689 | self.position.top = self._helper ? co.top : 0; | ||
3956 | 2690 | } | ||
3957 | 2691 | |||
3958 | 2692 | self.offset.left = self.parentData.left+self.position.left; | ||
3959 | 2693 | self.offset.top = self.parentData.top+self.position.top; | ||
3960 | 2694 | |||
3961 | 2695 | var woset = Math.abs( (self._helper ? self.offset.left - cop.left : (self.offset.left - cop.left)) + self.sizeDiff.width ), | ||
3962 | 2696 | hoset = Math.abs( (self._helper ? self.offset.top - cop.top : (self.offset.top - co.top)) + self.sizeDiff.height ); | ||
3963 | 2697 | |||
3964 | 2698 | var isParent = self.containerElement.get(0) == self.element.parent().get(0), | ||
3965 | 2699 | isOffsetRelative = /relative|absolute/.test(self.containerElement.css('position')); | ||
3966 | 2700 | |||
3967 | 2701 | if(isParent && isOffsetRelative) woset -= self.parentData.left; | ||
3968 | 2702 | |||
3969 | 2703 | if (woset + self.size.width >= self.parentData.width) { | ||
3970 | 2704 | self.size.width = self.parentData.width - woset; | ||
3971 | 2705 | if (pRatio) self.size.height = self.size.width / self.aspectRatio; | ||
3972 | 2706 | } | ||
3973 | 2707 | |||
3974 | 2708 | if (hoset + self.size.height >= self.parentData.height) { | ||
3975 | 2709 | self.size.height = self.parentData.height - hoset; | ||
3976 | 2710 | if (pRatio) self.size.width = self.size.height * self.aspectRatio; | ||
3977 | 2711 | } | ||
3978 | 2712 | }, | ||
3979 | 2713 | |||
3980 | 2714 | stop: function(event, ui){ | ||
3981 | 2715 | var self = $(this).data("resizable"), o = self.options, cp = self.position, | ||
3982 | 2716 | co = self.containerOffset, cop = self.containerPosition, ce = self.containerElement; | ||
3983 | 2717 | |||
3984 | 2718 | var helper = $(self.helper), ho = helper.offset(), w = helper.outerWidth() - self.sizeDiff.width, h = helper.outerHeight() - self.sizeDiff.height; | ||
3985 | 2719 | |||
3986 | 2720 | if (self._helper && !o.animate && (/relative/).test(ce.css('position'))) | ||
3987 | 2721 | $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h }); | ||
3988 | 2722 | |||
3989 | 2723 | if (self._helper && !o.animate && (/static/).test(ce.css('position'))) | ||
3990 | 2724 | $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h }); | ||
3991 | 2725 | |||
3992 | 2726 | } | ||
3993 | 2727 | }); | ||
3994 | 2728 | |||
3995 | 2729 | $.ui.plugin.add("resizable", "ghost", { | ||
3996 | 2730 | |||
3997 | 2731 | start: function(event, ui) { | ||
3998 | 2732 | |||
3999 | 2733 | var self = $(this).data("resizable"), o = self.options, cs = self.size; | ||
4000 | 2734 | |||
4001 | 2735 | self.ghost = self.originalElement.clone(); | ||
4002 | 2736 | self.ghost | ||
4003 | 2737 | .css({ opacity: .25, display: 'block', position: 'relative', height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 }) | ||
4004 | 2738 | .addClass('ui-resizable-ghost') | ||
4005 | 2739 | .addClass(typeof o.ghost == 'string' ? o.ghost : ''); | ||
4006 | 2740 | |||
4007 | 2741 | self.ghost.appendTo(self.helper); | ||
4008 | 2742 | |||
4009 | 2743 | }, | ||
4010 | 2744 | |||
4011 | 2745 | resize: function(event, ui){ | ||
4012 | 2746 | var self = $(this).data("resizable"), o = self.options; | ||
4013 | 2747 | if (self.ghost) self.ghost.css({ position: 'relative', height: self.size.height, width: self.size.width }); | ||
4014 | 2748 | }, | ||
4015 | 2749 | |||
4016 | 2750 | stop: function(event, ui){ | ||
4017 | 2751 | var self = $(this).data("resizable"), o = self.options; | ||
4018 | 2752 | if (self.ghost && self.helper) self.helper.get(0).removeChild(self.ghost.get(0)); | ||
4019 | 2753 | } | ||
4020 | 2754 | |||
4021 | 2755 | }); | ||
4022 | 2756 | |||
4023 | 2757 | $.ui.plugin.add("resizable", "grid", { | ||
4024 | 2758 | |||
4025 | 2759 | resize: function(event, ui) { | ||
4026 | 2760 | var self = $(this).data("resizable"), o = self.options, cs = self.size, os = self.originalSize, op = self.originalPosition, a = self.axis, ratio = o._aspectRatio || event.shiftKey; | ||
4027 | 2761 | o.grid = typeof o.grid == "number" ? [o.grid, o.grid] : o.grid; | ||
4028 | 2762 | var ox = Math.round((cs.width - os.width) / (o.grid[0]||1)) * (o.grid[0]||1), oy = Math.round((cs.height - os.height) / (o.grid[1]||1)) * (o.grid[1]||1); | ||
4029 | 2763 | |||
4030 | 2764 | if (/^(se|s|e)$/.test(a)) { | ||
4031 | 2765 | self.size.width = os.width + ox; | ||
4032 | 2766 | self.size.height = os.height + oy; | ||
4033 | 2767 | } | ||
4034 | 2768 | else if (/^(ne)$/.test(a)) { | ||
4035 | 2769 | self.size.width = os.width + ox; | ||
4036 | 2770 | self.size.height = os.height + oy; | ||
4037 | 2771 | self.position.top = op.top - oy; | ||
4038 | 2772 | } | ||
4039 | 2773 | else if (/^(sw)$/.test(a)) { | ||
4040 | 2774 | self.size.width = os.width + ox; | ||
4041 | 2775 | self.size.height = os.height + oy; | ||
4042 | 2776 | self.position.left = op.left - ox; | ||
4043 | 2777 | } | ||
4044 | 2778 | else { | ||
4045 | 2779 | self.size.width = os.width + ox; | ||
4046 | 2780 | self.size.height = os.height + oy; | ||
4047 | 2781 | self.position.top = op.top - oy; | ||
4048 | 2782 | self.position.left = op.left - ox; | ||
4049 | 2783 | } | ||
4050 | 2784 | } | ||
4051 | 2785 | |||
4052 | 2786 | }); | ||
4053 | 2787 | |||
4054 | 2788 | var num = function(v) { | ||
4055 | 2789 | return parseInt(v, 10) || 0; | ||
4056 | 2790 | }; | ||
4057 | 2791 | |||
4058 | 2792 | var isNumber = function(value) { | ||
4059 | 2793 | return !isNaN(parseInt(value, 10)); | ||
4060 | 2794 | }; | ||
4061 | 2795 | |||
4062 | 2796 | })(jQuery); | ||
4063 | 2797 | /* | ||
4064 | 2798 | * jQuery UI Selectable 1.8.4 | ||
4065 | 2799 | * | ||
4066 | 2800 | * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about) | ||
4067 | 2801 | * Dual licensed under the MIT or GPL Version 2 licenses. | ||
4068 | 2802 | * http://jquery.org/license | ||
4069 | 2803 | * | ||
4070 | 2804 | * http://docs.jquery.com/UI/Selectables | ||
4071 | 2805 | * | ||
4072 | 2806 | * Depends: | ||
4073 | 2807 | * jquery.ui.core.js | ||
4074 | 2808 | * jquery.ui.mouse.js | ||
4075 | 2809 | * jquery.ui.widget.js | ||
4076 | 2810 | */ | ||
4077 | 2811 | (function( $, undefined ) { | ||
4078 | 2812 | |||
4079 | 2813 | $.widget("ui.selectable", $.ui.mouse, { | ||
4080 | 2814 | options: { | ||
4081 | 2815 | appendTo: 'body', | ||
4082 | 2816 | autoRefresh: true, | ||
4083 | 2817 | distance: 0, | ||
4084 | 2818 | filter: '*', | ||
4085 | 2819 | tolerance: 'touch' | ||
4086 | 2820 | }, | ||
4087 | 2821 | _create: function() { | ||
4088 | 2822 | var self = this; | ||
4089 | 2823 | |||
4090 | 2824 | this.element.addClass("ui-selectable"); | ||
4091 | 2825 | |||
4092 | 2826 | this.dragged = false; | ||
4093 | 2827 | |||
4094 | 2828 | // cache selectee children based on filter | ||
4095 | 2829 | var selectees; | ||
4096 | 2830 | this.refresh = function() { | ||
4097 | 2831 | selectees = $(self.options.filter, self.element[0]); | ||
4098 | 2832 | selectees.each(function() { | ||
4099 | 2833 | var $this = $(this); | ||
4100 | 2834 | var pos = $this.offset(); | ||
4101 | 2835 | $.data(this, "selectable-item", { | ||
4102 | 2836 | element: this, | ||
4103 | 2837 | $element: $this, | ||
4104 | 2838 | left: pos.left, | ||
4105 | 2839 | top: pos.top, | ||
4106 | 2840 | right: pos.left + $this.outerWidth(), | ||
4107 | 2841 | bottom: pos.top + $this.outerHeight(), | ||
4108 | 2842 | startselected: false, | ||
4109 | 2843 | selected: $this.hasClass('ui-selected'), | ||
4110 | 2844 | selecting: $this.hasClass('ui-selecting'), | ||
4111 | 2845 | unselecting: $this.hasClass('ui-unselecting') | ||
4112 | 2846 | }); | ||
4113 | 2847 | }); | ||
4114 | 2848 | }; | ||
4115 | 2849 | this.refresh(); | ||
4116 | 2850 | |||
4117 | 2851 | this.selectees = selectees.addClass("ui-selectee"); | ||
4118 | 2852 | |||
4119 | 2853 | this._mouseInit(); | ||
4120 | 2854 | |||
4121 | 2855 | this.helper = $("<div class='ui-selectable-helper'></div>"); | ||
4122 | 2856 | }, | ||
4123 | 2857 | |||
4124 | 2858 | destroy: function() { | ||
4125 | 2859 | this.selectees | ||
4126 | 2860 | .removeClass("ui-selectee") | ||
4127 | 2861 | .removeData("selectable-item"); | ||
4128 | 2862 | this.element | ||
4129 | 2863 | .removeClass("ui-selectable ui-selectable-disabled") | ||
4130 | 2864 | .removeData("selectable") | ||
4131 | 2865 | .unbind(".selectable"); | ||
4132 | 2866 | this._mouseDestroy(); | ||
4133 | 2867 | |||
4134 | 2868 | return this; | ||
4135 | 2869 | }, | ||
4136 | 2870 | |||
4137 | 2871 | _mouseStart: function(event) { | ||
4138 | 2872 | var self = this; | ||
4139 | 2873 | |||
4140 | 2874 | this.opos = [event.pageX, event.pageY]; | ||
4141 | 2875 | |||
4142 | 2876 | if (this.options.disabled) | ||
4143 | 2877 | return; | ||
4144 | 2878 | |||
4145 | 2879 | var options = this.options; | ||
4146 | 2880 | |||
4147 | 2881 | this.selectees = $(options.filter, this.element[0]); | ||
4148 | 2882 | |||
4149 | 2883 | this._trigger("start", event); | ||
4150 | 2884 | |||
4151 | 2885 | $(options.appendTo).append(this.helper); | ||
4152 | 2886 | // position helper (lasso) | ||
4153 | 2887 | this.helper.css({ | ||
4154 | 2888 | "left": event.clientX, | ||
4155 | 2889 | "top": event.clientY, | ||
4156 | 2890 | "width": 0, | ||
4157 | 2891 | "height": 0 | ||
4158 | 2892 | }); | ||
4159 | 2893 | |||
4160 | 2894 | if (options.autoRefresh) { | ||
4161 | 2895 | this.refresh(); | ||
4162 | 2896 | } | ||
4163 | 2897 | |||
4164 | 2898 | this.selectees.filter('.ui-selected').each(function() { | ||
4165 | 2899 | var selectee = $.data(this, "selectable-item"); | ||
4166 | 2900 | selectee.startselected = true; | ||
4167 | 2901 | if (!event.metaKey) { | ||
4168 | 2902 | selectee.$element.removeClass('ui-selected'); | ||
4169 | 2903 | selectee.selected = false; | ||
4170 | 2904 | selectee.$element.addClass('ui-unselecting'); | ||
4171 | 2905 | selectee.unselecting = true; | ||
4172 | 2906 | // selectable UNSELECTING callback | ||
4173 | 2907 | self._trigger("unselecting", event, { | ||
4174 | 2908 | unselecting: selectee.element | ||
4175 | 2909 | }); | ||
4176 | 2910 | } | ||
4177 | 2911 | }); | ||
4178 | 2912 | |||
4179 | 2913 | $(event.target).parents().andSelf().each(function() { | ||
4180 | 2914 | var selectee = $.data(this, "selectable-item"); | ||
4181 | 2915 | if (selectee) { | ||
4182 | 2916 | var doSelect = !event.metaKey || !selectee.$element.hasClass('ui-selected'); | ||
4183 | 2917 | selectee.$element | ||
4184 | 2918 | .removeClass(doSelect ? "ui-unselecting" : "ui-selected") | ||
4185 | 2919 | .addClass(doSelect ? "ui-selecting" : "ui-unselecting"); | ||
4186 | 2920 | selectee.unselecting = !doSelect; | ||
4187 | 2921 | selectee.selecting = doSelect; | ||
4188 | 2922 | selectee.selected = doSelect; | ||
4189 | 2923 | // selectable (UN)SELECTING callback | ||
4190 | 2924 | if (doSelect) { | ||
4191 | 2925 | self._trigger("selecting", event, { | ||
4192 | 2926 | selecting: selectee.element | ||
4193 | 2927 | }); | ||
4194 | 2928 | } else { | ||
4195 | 2929 | self._trigger("unselecting", event, { | ||
4196 | 2930 | unselecting: selectee.element | ||
4197 | 2931 | }); | ||
4198 | 2932 | } | ||
4199 | 2933 | return false; | ||
4200 | 2934 | } | ||
4201 | 2935 | }); | ||
4202 | 2936 | |||
4203 | 2937 | }, | ||
4204 | 2938 | |||
4205 | 2939 | _mouseDrag: function(event) { | ||
4206 | 2940 | var self = this; | ||
4207 | 2941 | this.dragged = true; | ||
4208 | 2942 | |||
4209 | 2943 | if (this.options.disabled) | ||
4210 | 2944 | return; | ||
4211 | 2945 | |||
4212 | 2946 | var options = this.options; | ||
4213 | 2947 | |||
4214 | 2948 | var x1 = this.opos[0], y1 = this.opos[1], x2 = event.pageX, y2 = event.pageY; | ||
4215 | 2949 | if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; } | ||
4216 | 2950 | if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; } | ||
4217 | 2951 | this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1}); | ||
4218 | 2952 | |||
4219 | 2953 | this.selectees.each(function() { | ||
4220 | 2954 | var selectee = $.data(this, "selectable-item"); | ||
4221 | 2955 | //prevent helper from being selected if appendTo: selectable | ||
4222 | 2956 | if (!selectee || selectee.element == self.element[0]) | ||
4223 | 2957 | return; | ||
4224 | 2958 | var hit = false; | ||
4225 | 2959 | if (options.tolerance == 'touch') { | ||
4226 | 2960 | hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) ); | ||
4227 | 2961 | } else if (options.tolerance == 'fit') { | ||
4228 | 2962 | hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2); | ||
4229 | 2963 | } | ||
4230 | 2964 | |||
4231 | 2965 | if (hit) { | ||
4232 | 2966 | // SELECT | ||
4233 | 2967 | if (selectee.selected) { | ||
4234 | 2968 | selectee.$element.removeClass('ui-selected'); | ||
4235 | 2969 | selectee.selected = false; | ||
4236 | 2970 | } | ||
4237 | 2971 | if (selectee.unselecting) { | ||
4238 | 2972 | selectee.$element.removeClass('ui-unselecting'); | ||
4239 | 2973 | selectee.unselecting = false; | ||
4240 | 2974 | } | ||
4241 | 2975 | if (!selectee.selecting) { | ||
4242 | 2976 | selectee.$element.addClass('ui-selecting'); | ||
4243 | 2977 | selectee.selecting = true; | ||
4244 | 2978 | // selectable SELECTING callback | ||
4245 | 2979 | self._trigger("selecting", event, { | ||
4246 | 2980 | selecting: selectee.element | ||
4247 | 2981 | }); | ||
4248 | 2982 | } | ||
4249 | 2983 | } else { | ||
4250 | 2984 | // UNSELECT | ||
4251 | 2985 | if (selectee.selecting) { | ||
4252 | 2986 | if (event.metaKey && selectee.startselected) { | ||
4253 | 2987 | selectee.$element.removeClass('ui-selecting'); | ||
4254 | 2988 | selectee.selecting = false; | ||
4255 | 2989 | selectee.$element.addClass('ui-selected'); | ||
4256 | 2990 | selectee.selected = true; | ||
4257 | 2991 | } else { | ||
4258 | 2992 | selectee.$element.removeClass('ui-selecting'); | ||
4259 | 2993 | selectee.selecting = false; | ||
4260 | 2994 | if (selectee.startselected) { | ||
4261 | 2995 | selectee.$element.addClass('ui-unselecting'); | ||
4262 | 2996 | selectee.unselecting = true; | ||
4263 | 2997 | } | ||
4264 | 2998 | // selectable UNSELECTING callback | ||
4265 | 2999 | self._trigger("unselecting", event, { | ||
4266 | 3000 | unselecting: selectee.element | ||
4267 | 3001 | }); | ||
4268 | 3002 | } | ||
4269 | 3003 | } | ||
4270 | 3004 | if (selectee.selected) { | ||
4271 | 3005 | if (!event.metaKey && !selectee.startselected) { | ||
4272 | 3006 | selectee.$element.removeClass('ui-selected'); | ||
4273 | 3007 | selectee.selected = false; | ||
4274 | 3008 | |||
4275 | 3009 | selectee.$element.addClass('ui-unselecting'); | ||
4276 | 3010 | selectee.unselecting = true; | ||
4277 | 3011 | // selectable UNSELECTING callback | ||
4278 | 3012 | self._trigger("unselecting", event, { | ||
4279 | 3013 | unselecting: selectee.element | ||
4280 | 3014 | }); | ||
4281 | 3015 | } | ||
4282 | 3016 | } | ||
4283 | 3017 | } | ||
4284 | 3018 | }); | ||
4285 | 3019 | |||
4286 | 3020 | return false; | ||
4287 | 3021 | }, | ||
4288 | 3022 | |||
4289 | 3023 | _mouseStop: function(event) { | ||
4290 | 3024 | var self = this; | ||
4291 | 3025 | |||
4292 | 3026 | this.dragged = false; | ||
4293 | 3027 | |||
4294 | 3028 | var options = this.options; | ||
4295 | 3029 | |||
4296 | 3030 | $('.ui-unselecting', this.element[0]).each(function() { | ||
4297 | 3031 | var selectee = $.data(this, "selectable-item"); | ||
4298 | 3032 | selectee.$element.removeClass('ui-unselecting'); | ||
4299 | 3033 | selectee.unselecting = false; | ||
4300 | 3034 | selectee.startselected = false; | ||
4301 | 3035 | self._trigger("unselected", event, { | ||
4302 | 3036 | unselected: selectee.element | ||
4303 | 3037 | }); | ||
4304 | 3038 | }); | ||
4305 | 3039 | $('.ui-selecting', this.element[0]).each(function() { | ||
4306 | 3040 | var selectee = $.data(this, "selectable-item"); | ||
4307 | 3041 | selectee.$element.removeClass('ui-selecting').addClass('ui-selected'); | ||
4308 | 3042 | selectee.selecting = false; | ||
4309 | 3043 | selectee.selected = true; | ||
4310 | 3044 | selectee.startselected = true; | ||
4311 | 3045 | self._trigger("selected", event, { | ||
4312 | 3046 | selected: selectee.element | ||
4313 | 3047 | }); | ||
4314 | 3048 | }); | ||
4315 | 3049 | this._trigger("stop", event); | ||
4316 | 3050 | |||
4317 | 3051 | this.helper.remove(); | ||
4318 | 3052 | |||
4319 | 3053 | return false; | ||
4320 | 3054 | } | ||
4321 | 3055 | |||
4322 | 3056 | }); | ||
4323 | 3057 | |||
4324 | 3058 | $.extend($.ui.selectable, { | ||
4325 | 3059 | version: "1.8.4" | ||
4326 | 3060 | }); | ||
4327 | 3061 | |||
4328 | 3062 | })(jQuery); | ||
4329 | 3063 | /* | ||
4330 | 3064 | * jQuery UI Sortable 1.8.4 | ||
4331 | 3065 | * | ||
4332 | 3066 | * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about) | ||
4333 | 3067 | * Dual licensed under the MIT or GPL Version 2 licenses. | ||
4334 | 3068 | * http://jquery.org/license | ||
4335 | 3069 | * | ||
4336 | 3070 | * http://docs.jquery.com/UI/Sortables | ||
4337 | 3071 | * | ||
4338 | 3072 | * Depends: | ||
4339 | 3073 | * jquery.ui.core.js | ||
4340 | 3074 | * jquery.ui.mouse.js | ||
4341 | 3075 | * jquery.ui.widget.js | ||
4342 | 3076 | */ | ||
4343 | 3077 | (function( $, undefined ) { | ||
4344 | 3078 | |||
4345 | 3079 | $.widget("ui.sortable", $.ui.mouse, { | ||
4346 | 3080 | widgetEventPrefix: "sort", | ||
4347 | 3081 | options: { | ||
4348 | 3082 | appendTo: "parent", | ||
4349 | 3083 | axis: false, | ||
4350 | 3084 | connectWith: false, | ||
4351 | 3085 | containment: false, | ||
4352 | 3086 | cursor: 'auto', | ||
4353 | 3087 | cursorAt: false, | ||
4354 | 3088 | dropOnEmpty: true, | ||
4355 | 3089 | forcePlaceholderSize: false, | ||
4356 | 3090 | forceHelperSize: false, | ||
4357 | 3091 | grid: false, | ||
4358 | 3092 | handle: false, | ||
4359 | 3093 | helper: "original", | ||
4360 | 3094 | items: '> *', | ||
4361 | 3095 | opacity: false, | ||
4362 | 3096 | placeholder: false, | ||
4363 | 3097 | revert: false, | ||
4364 | 3098 | scroll: true, | ||
4365 | 3099 | scrollSensitivity: 20, | ||
4366 | 3100 | scrollSpeed: 20, | ||
4367 | 3101 | scope: "default", | ||
4368 | 3102 | tolerance: "intersect", | ||
4369 | 3103 | zIndex: 1000 | ||
4370 | 3104 | }, | ||
4371 | 3105 | _create: function() { | ||
4372 | 3106 | |||
4373 | 3107 | var o = this.options; | ||
4374 | 3108 | this.containerCache = {}; | ||
4375 | 3109 | this.element.addClass("ui-sortable"); | ||
4376 | 3110 | |||
4377 | 3111 | //Get the items | ||
4378 | 3112 | this.refresh(); | ||
4379 | 3113 | |||
4380 | 3114 | //Let's determine if the items are floating | ||
4381 | 3115 | this.floating = this.items.length ? (/left|right/).test(this.items[0].item.css('float')) : false; | ||
4382 | 3116 | |||
4383 | 3117 | //Let's determine the parent's offset | ||
4384 | 3118 | this.offset = this.element.offset(); | ||
4385 | 3119 | |||
4386 | 3120 | //Initialize mouse events for interaction | ||
4387 | 3121 | this._mouseInit(); | ||
4388 | 3122 | |||
4389 | 3123 | }, | ||
4390 | 3124 | |||
4391 | 3125 | destroy: function() { | ||
4392 | 3126 | this.element | ||
4393 | 3127 | .removeClass("ui-sortable ui-sortable-disabled") | ||
4394 | 3128 | .removeData("sortable") | ||
4395 | 3129 | .unbind(".sortable"); | ||
4396 | 3130 | this._mouseDestroy(); | ||
4397 | 3131 | |||
4398 | 3132 | for ( var i = this.items.length - 1; i >= 0; i-- ) | ||
4399 | 3133 | this.items[i].item.removeData("sortable-item"); | ||
4400 | 3134 | |||
4401 | 3135 | return this; | ||
4402 | 3136 | }, | ||
4403 | 3137 | |||
4404 | 3138 | _setOption: function(key, value){ | ||
4405 | 3139 | if ( key === "disabled" ) { | ||
4406 | 3140 | this.options[ key ] = value; | ||
4407 | 3141 | |||
4408 | 3142 | this.widget() | ||
4409 | 3143 | [ value ? "addClass" : "removeClass"]( "ui-sortable-disabled" ); | ||
4410 | 3144 | } else { | ||
4411 | 3145 | // Don't call widget base _setOption for disable as it adds ui-state-disabled class | ||
4412 | 3146 | $.Widget.prototype._setOption.apply(this, arguments); | ||
4413 | 3147 | } | ||
4414 | 3148 | }, | ||
4415 | 3149 | |||
4416 | 3150 | _mouseCapture: function(event, overrideHandle) { | ||
4417 | 3151 | |||
4418 | 3152 | if (this.reverting) { | ||
4419 | 3153 | return false; | ||
4420 | 3154 | } | ||
4421 | 3155 | |||
4422 | 3156 | if(this.options.disabled || this.options.type == 'static') return false; | ||
4423 | 3157 | |||
4424 | 3158 | //We have to refresh the items data once first | ||
4425 | 3159 | this._refreshItems(event); | ||
4426 | 3160 | |||
4427 | 3161 | //Find out if the clicked node (or one of its parents) is a actual item in this.items | ||
4428 | 3162 | var currentItem = null, self = this, nodes = $(event.target).parents().each(function() { | ||
4429 | 3163 | if($.data(this, 'sortable-item') == self) { | ||
4430 | 3164 | currentItem = $(this); | ||
4431 | 3165 | return false; | ||
4432 | 3166 | } | ||
4433 | 3167 | }); | ||
4434 | 3168 | if($.data(event.target, 'sortable-item') == self) currentItem = $(event.target); | ||
4435 | 3169 | |||
4436 | 3170 | if(!currentItem) return false; | ||
4437 | 3171 | if(this.options.handle && !overrideHandle) { | ||
4438 | 3172 | var validHandle = false; | ||
4439 | 3173 | |||
4440 | 3174 | $(this.options.handle, currentItem).find("*").andSelf().each(function() { if(this == event.target) validHandle = true; }); | ||
4441 | 3175 | if(!validHandle) return false; | ||
4442 | 3176 | } | ||
4443 | 3177 | |||
4444 | 3178 | this.currentItem = currentItem; | ||
4445 | 3179 | this._removeCurrentsFromItems(); | ||
4446 | 3180 | return true; | ||
4447 | 3181 | |||
4448 | 3182 | }, | ||
4449 | 3183 | |||
4450 | 3184 | _mouseStart: function(event, overrideHandle, noActivation) { | ||
4451 | 3185 | |||
4452 | 3186 | var o = this.options, self = this; | ||
4453 | 3187 | this.currentContainer = this; | ||
4454 | 3188 | |||
4455 | 3189 | //We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture | ||
4456 | 3190 | this.refreshPositions(); | ||
4457 | 3191 | |||
4458 | 3192 | //Create and append the visible helper | ||
4459 | 3193 | this.helper = this._createHelper(event); | ||
4460 | 3194 | |||
4461 | 3195 | //Cache the helper size | ||
4462 | 3196 | this._cacheHelperProportions(); | ||
4463 | 3197 | |||
4464 | 3198 | /* | ||
4465 | 3199 | * - Position generation - | ||
4466 | 3200 | * This block generates everything position related - it's the core of draggables. | ||
4467 | 3201 | */ | ||
4468 | 3202 | |||
4469 | 3203 | //Cache the margins of the original element | ||
4470 | 3204 | this._cacheMargins(); | ||
4471 | 3205 | |||
4472 | 3206 | //Get the next scrolling parent | ||
4473 | 3207 | this.scrollParent = this.helper.scrollParent(); | ||
4474 | 3208 | |||
4475 | 3209 | //The element's absolute position on the page minus margins | ||
4476 | 3210 | this.offset = this.currentItem.offset(); | ||
4477 | 3211 | this.offset = { | ||
4478 | 3212 | top: this.offset.top - this.margins.top, | ||
4479 | 3213 | left: this.offset.left - this.margins.left | ||
4480 | 3214 | }; | ||
4481 | 3215 | |||
4482 | 3216 | // Only after we got the offset, we can change the helper's position to absolute | ||
4483 | 3217 | // TODO: Still need to figure out a way to make relative sorting possible | ||
4484 | 3218 | this.helper.css("position", "absolute"); | ||
4485 | 3219 | this.cssPosition = this.helper.css("position"); | ||
4486 | 3220 | |||
4487 | 3221 | $.extend(this.offset, { | ||
4488 | 3222 | click: { //Where the click happened, relative to the element | ||
4489 | 3223 | left: event.pageX - this.offset.left, | ||
4490 | 3224 | top: event.pageY - this.offset.top | ||
4491 | 3225 | }, | ||
4492 | 3226 | parent: this._getParentOffset(), | ||
4493 | 3227 | relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper | ||
4494 | 3228 | }); | ||
4495 | 3229 | |||
4496 | 3230 | //Generate the original position | ||
4497 | 3231 | this.originalPosition = this._generatePosition(event); | ||
4498 | 3232 | this.originalPageX = event.pageX; | ||
4499 | 3233 | this.originalPageY = event.pageY; | ||
4500 | 3234 | |||
4501 | 3235 | //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied | ||
4502 | 3236 | (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt)); | ||
4503 | 3237 | |||
4504 | 3238 | //Cache the former DOM position | ||
4505 | 3239 | this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] }; | ||
4506 | 3240 | |||
4507 | 3241 | //If the helper is not the original, hide the original so it's not playing any role during the drag, won't cause anything bad this way | ||
4508 | 3242 | if(this.helper[0] != this.currentItem[0]) { | ||
4509 | 3243 | this.currentItem.hide(); | ||
4510 | 3244 | } | ||
4511 | 3245 | |||
4512 | 3246 | //Create the placeholder | ||
4513 | 3247 | this._createPlaceholder(); | ||
4514 | 3248 | |||
4515 | 3249 | //Set a containment if given in the options | ||
4516 | 3250 | if(o.containment) | ||
4517 | 3251 | this._setContainment(); | ||
4518 | 3252 | |||
4519 | 3253 | if(o.cursor) { // cursor option | ||
4520 | 3254 | if ($('body').css("cursor")) this._storedCursor = $('body').css("cursor"); | ||
4521 | 3255 | $('body').css("cursor", o.cursor); | ||
4522 | 3256 | } | ||
4523 | 3257 | |||
4524 | 3258 | if(o.opacity) { // opacity option | ||
4525 | 3259 | if (this.helper.css("opacity")) this._storedOpacity = this.helper.css("opacity"); | ||
4526 | 3260 | this.helper.css("opacity", o.opacity); | ||
4527 | 3261 | } | ||
4528 | 3262 | |||
4529 | 3263 | if(o.zIndex) { // zIndex option | ||
4530 | 3264 | if (this.helper.css("zIndex")) this._storedZIndex = this.helper.css("zIndex"); | ||
4531 | 3265 | this.helper.css("zIndex", o.zIndex); | ||
4532 | 3266 | } | ||
4533 | 3267 | |||
4534 | 3268 | //Prepare scrolling | ||
4535 | 3269 | if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') | ||
4536 | 3270 | this.overflowOffset = this.scrollParent.offset(); | ||
4537 | 3271 | |||
4538 | 3272 | //Call callbacks | ||
4539 | 3273 | this._trigger("start", event, this._uiHash()); | ||
4540 | 3274 | |||
4541 | 3275 | //Recache the helper size | ||
4542 | 3276 | if(!this._preserveHelperProportions) | ||
4543 | 3277 | this._cacheHelperProportions(); | ||
4544 | 3278 | |||
4545 | 3279 | |||
4546 | 3280 | //Post 'activate' events to possible containers | ||
4547 | 3281 | if(!noActivation) { | ||
4548 | 3282 | for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, self._uiHash(this)); } | ||
4549 | 3283 | } | ||
4550 | 3284 | |||
4551 | 3285 | //Prepare possible droppables | ||
4552 | 3286 | if($.ui.ddmanager) | ||
4553 | 3287 | $.ui.ddmanager.current = this; | ||
4554 | 3288 | |||
4555 | 3289 | if ($.ui.ddmanager && !o.dropBehaviour) | ||
4556 | 3290 | $.ui.ddmanager.prepareOffsets(this, event); | ||
4557 | 3291 | |||
4558 | 3292 | this.dragging = true; | ||
4559 | 3293 | |||
4560 | 3294 | this.helper.addClass("ui-sortable-helper"); | ||
4561 | 3295 | this._mouseDrag(event); //Execute the drag once - this causes the helper not to be visible before getting its correct position | ||
4562 | 3296 | return true; | ||
4563 | 3297 | |||
4564 | 3298 | }, | ||
4565 | 3299 | |||
4566 | 3300 | _mouseDrag: function(event) { | ||
4567 | 3301 | |||
4568 | 3302 | //Compute the helpers position | ||
4569 | 3303 | this.position = this._generatePosition(event); | ||
4570 | 3304 | this.positionAbs = this._convertPositionTo("absolute"); | ||
4571 | 3305 | |||
4572 | 3306 | if (!this.lastPositionAbs) { | ||
4573 | 3307 | this.lastPositionAbs = this.positionAbs; | ||
4574 | 3308 | } | ||
4575 | 3309 | |||
4576 | 3310 | //Do scrolling | ||
4577 | 3311 | if(this.options.scroll) { | ||
4578 | 3312 | var o = this.options, scrolled = false; | ||
4579 | 3313 | if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') { | ||
4580 | 3314 | |||
4581 | 3315 | if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) | ||
4582 | 3316 | this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed; | ||
4583 | 3317 | else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity) | ||
4584 | 3318 | this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed; | ||
4585 | 3319 | |||
4586 | 3320 | if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) | ||
4587 | 3321 | this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed; | ||
4588 | 3322 | else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity) | ||
4589 | 3323 | this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed; | ||
4590 | 3324 | |||
4591 | 3325 | } else { | ||
4592 | 3326 | |||
4593 | 3327 | if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) | ||
4594 | 3328 | scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed); | ||
4595 | 3329 | else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) | ||
4596 | 3330 | scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed); | ||
4597 | 3331 | |||
4598 | 3332 | if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) | ||
4599 | 3333 | scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed); | ||
4600 | 3334 | else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) | ||
4601 | 3335 | scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); | ||
4602 | 3336 | |||
4603 | 3337 | } | ||
4604 | 3338 | |||
4605 | 3339 | if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) | ||
4606 | 3340 | $.ui.ddmanager.prepareOffsets(this, event); | ||
4607 | 3341 | } | ||
4608 | 3342 | |||
4609 | 3343 | //Regenerate the absolute position used for position checks | ||
4610 | 3344 | this.positionAbs = this._convertPositionTo("absolute"); | ||
4611 | 3345 | |||
4612 | 3346 | //Set the helper position | ||
4613 | 3347 | if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px'; | ||
4614 | 3348 | if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px'; | ||
4615 | 3349 | |||
4616 | 3350 | //Rearrange | ||
4617 | 3351 | for (var i = this.items.length - 1; i >= 0; i--) { | ||
4618 | 3352 | |||
4619 | 3353 | //Cache variables and intersection, continue if no intersection | ||
4620 | 3354 | var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item); | ||
4621 | 3355 | if (!intersection) continue; | ||
4622 | 3356 | |||
4623 | 3357 | if(itemElement != this.currentItem[0] //cannot intersect with itself | ||
4624 | 3358 | && this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before | ||
4625 | 3359 | && !$.ui.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked | ||
4626 | 3360 | && (this.options.type == 'semi-dynamic' ? !$.ui.contains(this.element[0], itemElement) : true) | ||
4627 | 3361 | //&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container | ||
4628 | 3362 | ) { | ||
4629 | 3363 | |||
4630 | 3364 | this.direction = intersection == 1 ? "down" : "up"; | ||
4631 | 3365 | |||
4632 | 3366 | if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) { | ||
4633 | 3367 | this._rearrange(event, item); | ||
4634 | 3368 | } else { | ||
4635 | 3369 | break; | ||
4636 | 3370 | } | ||
4637 | 3371 | |||
4638 | 3372 | this._trigger("change", event, this._uiHash()); | ||
4639 | 3373 | break; | ||
4640 | 3374 | } | ||
4641 | 3375 | } | ||
4642 | 3376 | |||
4643 | 3377 | //Post events to containers | ||
4644 | 3378 | this._contactContainers(event); | ||
4645 | 3379 | |||
4646 | 3380 | //Interconnect with droppables | ||
4647 | 3381 | if($.ui.ddmanager) $.ui.ddmanager.drag(this, event); | ||
4648 | 3382 | |||
4649 | 3383 | //Call callbacks | ||
4650 | 3384 | this._trigger('sort', event, this._uiHash()); | ||
4651 | 3385 | |||
4652 | 3386 | this.lastPositionAbs = this.positionAbs; | ||
4653 | 3387 | return false; | ||
4654 | 3388 | |||
4655 | 3389 | }, | ||
4656 | 3390 | |||
4657 | 3391 | _mouseStop: function(event, noPropagation) { | ||
4658 | 3392 | |||
4659 | 3393 | if(!event) return; | ||
4660 | 3394 | |||
4661 | 3395 | //If we are using droppables, inform the manager about the drop | ||
4662 | 3396 | if ($.ui.ddmanager && !this.options.dropBehaviour) | ||
4663 | 3397 | $.ui.ddmanager.drop(this, event); | ||
4664 | 3398 | |||
4665 | 3399 | if(this.options.revert) { | ||
4666 | 3400 | var self = this; | ||
4667 | 3401 | var cur = self.placeholder.offset(); | ||
4668 | 3402 | |||
4669 | 3403 | self.reverting = true; | ||
4670 | 3404 | |||
4671 | 3405 | $(this.helper).animate({ | ||
4672 | 3406 | left: cur.left - this.offset.parent.left - self.margins.left + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft), | ||
4673 | 3407 | top: cur.top - this.offset.parent.top - self.margins.top + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop) | ||
4674 | 3408 | }, parseInt(this.options.revert, 10) || 500, function() { | ||
4675 | 3409 | self._clear(event); | ||
4676 | 3410 | }); | ||
4677 | 3411 | } else { | ||
4678 | 3412 | this._clear(event, noPropagation); | ||
4679 | 3413 | } | ||
4680 | 3414 | |||
4681 | 3415 | return false; | ||
4682 | 3416 | |||
4683 | 3417 | }, | ||
4684 | 3418 | |||
4685 | 3419 | cancel: function() { | ||
4686 | 3420 | |||
4687 | 3421 | var self = this; | ||
4688 | 3422 | |||
4689 | 3423 | if(this.dragging) { | ||
4690 | 3424 | |||
4691 | 3425 | this._mouseUp(); | ||
4692 | 3426 | |||
4693 | 3427 | if(this.options.helper == "original") | ||
4694 | 3428 | this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper"); | ||
4695 | 3429 | else | ||
4696 | 3430 | this.currentItem.show(); | ||
4697 | 3431 | |||
4698 | 3432 | //Post deactivating events to containers | ||
4699 | 3433 | for (var i = this.containers.length - 1; i >= 0; i--){ | ||
4700 | 3434 | this.containers[i]._trigger("deactivate", null, self._uiHash(this)); | ||
4701 | 3435 | if(this.containers[i].containerCache.over) { | ||
4702 | 3436 | this.containers[i]._trigger("out", null, self._uiHash(this)); | ||
4703 | 3437 | this.containers[i].containerCache.over = 0; | ||
4704 | 3438 | } | ||
4705 | 3439 | } | ||
4706 | 3440 | |||
4707 | 3441 | } | ||
4708 | 3442 | |||
4709 | 3443 | //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node! | ||
4710 | 3444 | if(this.placeholder[0].parentNode) this.placeholder[0].parentNode.removeChild(this.placeholder[0]); | ||
4711 | 3445 | if(this.options.helper != "original" && this.helper && this.helper[0].parentNode) this.helper.remove(); | ||
4712 | 3446 | |||
4713 | 3447 | $.extend(this, { | ||
4714 | 3448 | helper: null, | ||
4715 | 3449 | dragging: false, | ||
4716 | 3450 | reverting: false, | ||
4717 | 3451 | _noFinalSort: null | ||
4718 | 3452 | }); | ||
4719 | 3453 | |||
4720 | 3454 | if(this.domPosition.prev) { | ||
4721 | 3455 | $(this.domPosition.prev).after(this.currentItem); | ||
4722 | 3456 | } else { | ||
4723 | 3457 | $(this.domPosition.parent).prepend(this.currentItem); | ||
4724 | 3458 | } | ||
4725 | 3459 | |||
4726 | 3460 | return this; | ||
4727 | 3461 | |||
4728 | 3462 | }, | ||
4729 | 3463 | |||
4730 | 3464 | serialize: function(o) { | ||
4731 | 3465 | |||
4732 | 3466 | var items = this._getItemsAsjQuery(o && o.connected); | ||
4733 | 3467 | var str = []; o = o || {}; | ||
4734 | 3468 | |||
4735 | 3469 | $(items).each(function() { | ||
4736 | 3470 | var res = ($(o.item || this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/)); | ||
4737 | 3471 | if(res) str.push((o.key || res[1]+'[]')+'='+(o.key && o.expression ? res[1] : res[2])); | ||
4738 | 3472 | }); | ||
4739 | 3473 | |||
4740 | 3474 | if(!str.length && o.key) { | ||
4741 | 3475 | str.push(o.key + '='); | ||
4742 | 3476 | } | ||
4743 | 3477 | |||
4744 | 3478 | return str.join('&'); | ||
4745 | 3479 | |||
4746 | 3480 | }, | ||
4747 | 3481 | |||
4748 | 3482 | toArray: function(o) { | ||
4749 | 3483 | |||
4750 | 3484 | var items = this._getItemsAsjQuery(o && o.connected); | ||
4751 | 3485 | var ret = []; o = o || {}; | ||
4752 | 3486 | |||
4753 | 3487 | items.each(function() { ret.push($(o.item || this).attr(o.attribute || 'id') || ''); }); | ||
4754 | 3488 | return ret; | ||
4755 | 3489 | |||
4756 | 3490 | }, | ||
4757 | 3491 | |||
4758 | 3492 | /* Be careful with the following core functions */ | ||
4759 | 3493 | _intersectsWith: function(item) { | ||
4760 | 3494 | |||
4761 | 3495 | var x1 = this.positionAbs.left, | ||
4762 | 3496 | x2 = x1 + this.helperProportions.width, | ||
4763 | 3497 | y1 = this.positionAbs.top, | ||
4764 | 3498 | y2 = y1 + this.helperProportions.height; | ||
4765 | 3499 | |||
4766 | 3500 | var l = item.left, | ||
4767 | 3501 | r = l + item.width, | ||
4768 | 3502 | t = item.top, | ||
4769 | 3503 | b = t + item.height; | ||
4770 | 3504 | |||
4771 | 3505 | var dyClick = this.offset.click.top, | ||
4772 | 3506 | dxClick = this.offset.click.left; | ||
4773 | 3507 | |||
4774 | 3508 | var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r; | ||
4775 | 3509 | |||
4776 | 3510 | if( this.options.tolerance == "pointer" | ||
4777 | 3511 | || this.options.forcePointerForContainers | ||
4778 | 3512 | || (this.options.tolerance != "pointer" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height']) | ||
4779 | 3513 | ) { | ||
4780 | 3514 | return isOverElement; | ||
4781 | 3515 | } else { | ||
4782 | 3516 | |||
4783 | 3517 | return (l < x1 + (this.helperProportions.width / 2) // Right Half | ||
4784 | 3518 | && x2 - (this.helperProportions.width / 2) < r // Left Half | ||
4785 | 3519 | && t < y1 + (this.helperProportions.height / 2) // Bottom Half | ||
4786 | 3520 | && y2 - (this.helperProportions.height / 2) < b ); // Top Half | ||
4787 | 3521 | |||
4788 | 3522 | } | ||
4789 | 3523 | }, | ||
4790 | 3524 | |||
4791 | 3525 | _intersectsWithPointer: function(item) { | ||
4792 | 3526 | |||
4793 | 3527 | var isOverElementHeight = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height), | ||
4794 | 3528 | isOverElementWidth = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width), | ||
4795 | 3529 | isOverElement = isOverElementHeight && isOverElementWidth, | ||
4796 | 3530 | verticalDirection = this._getDragVerticalDirection(), | ||
4797 | 3531 | horizontalDirection = this._getDragHorizontalDirection(); | ||
4798 | 3532 | |||
4799 | 3533 | if (!isOverElement) | ||
4800 | 3534 | return false; | ||
4801 | 3535 | |||
4802 | 3536 | return this.floating ? | ||
4803 | 3537 | ( ((horizontalDirection && horizontalDirection == "right") || verticalDirection == "down") ? 2 : 1 ) | ||
4804 | 3538 | : ( verticalDirection && (verticalDirection == "down" ? 2 : 1) ); | ||
4805 | 3539 | |||
4806 | 3540 | }, | ||
4807 | 3541 | |||
4808 | 3542 | _intersectsWithSides: function(item) { | ||
4809 | 3543 | |||
4810 | 3544 | var isOverBottomHalf = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height), | ||
4811 | 3545 | isOverRightHalf = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width), | ||
4812 | 3546 | verticalDirection = this._getDragVerticalDirection(), | ||
4813 | 3547 | horizontalDirection = this._getDragHorizontalDirection(); | ||
4814 | 3548 | |||
4815 | 3549 | if (this.floating && horizontalDirection) { | ||
4816 | 3550 | return ((horizontalDirection == "right" && isOverRightHalf) || (horizontalDirection == "left" && !isOverRightHalf)); | ||
4817 | 3551 | } else { | ||
4818 | 3552 | return verticalDirection && ((verticalDirection == "down" && isOverBottomHalf) || (verticalDirection == "up" && !isOverBottomHalf)); | ||
4819 | 3553 | } | ||
4820 | 3554 | |||
4821 | 3555 | }, | ||
4822 | 3556 | |||
4823 | 3557 | _getDragVerticalDirection: function() { | ||
4824 | 3558 | var delta = this.positionAbs.top - this.lastPositionAbs.top; | ||
4825 | 3559 | return delta != 0 && (delta > 0 ? "down" : "up"); | ||
4826 | 3560 | }, | ||
4827 | 3561 | |||
4828 | 3562 | _getDragHorizontalDirection: function() { | ||
4829 | 3563 | var delta = this.positionAbs.left - this.lastPositionAbs.left; | ||
4830 | 3564 | return delta != 0 && (delta > 0 ? "right" : "left"); | ||
4831 | 3565 | }, | ||
4832 | 3566 | |||
4833 | 3567 | refresh: function(event) { | ||
4834 | 3568 | this._refreshItems(event); | ||
4835 | 3569 | this.refreshPositions(); | ||
4836 | 3570 | return this; | ||
4837 | 3571 | }, | ||
4838 | 3572 | |||
4839 | 3573 | _connectWith: function() { | ||
4840 | 3574 | var options = this.options; | ||
4841 | 3575 | return options.connectWith.constructor == String | ||
4842 | 3576 | ? [options.connectWith] | ||
4843 | 3577 | : options.connectWith; | ||
4844 | 3578 | }, | ||
4845 | 3579 | |||
4846 | 3580 | _getItemsAsjQuery: function(connected) { | ||
4847 | 3581 | |||
4848 | 3582 | var self = this; | ||
4849 | 3583 | var items = []; | ||
4850 | 3584 | var queries = []; | ||
4851 | 3585 | var connectWith = this._connectWith(); | ||
4852 | 3586 | |||
4853 | 3587 | if(connectWith && connected) { | ||
4854 | 3588 | for (var i = connectWith.length - 1; i >= 0; i--){ | ||
4855 | 3589 | var cur = $(connectWith[i]); | ||
4856 | 3590 | for (var j = cur.length - 1; j >= 0; j--){ | ||
4857 | 3591 | var inst = $.data(cur[j], 'sortable'); | ||
4858 | 3592 | if(inst && inst != this && !inst.options.disabled) { | ||
4859 | 3593 | queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), inst]); | ||
4860 | 3594 | } | ||
4861 | 3595 | }; | ||
4862 | 3596 | }; | ||
4863 | 3597 | } | ||
4864 | 3598 | |||
4865 | 3599 | queries.push([$.isFunction(this.options.items) ? this.options.items.call(this.element, null, { options: this.options, item: this.currentItem }) : $(this.options.items, this.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), this]); | ||
4866 | 3600 | |||
4867 | 3601 | for (var i = queries.length - 1; i >= 0; i--){ | ||
4868 | 3602 | queries[i][0].each(function() { | ||
4869 | 3603 | items.push(this); | ||
4870 | 3604 | }); | ||
4871 | 3605 | }; | ||
4872 | 3606 | |||
4873 | 3607 | return $(items); | ||
4874 | 3608 | |||
4875 | 3609 | }, | ||
4876 | 3610 | |||
4877 | 3611 | _removeCurrentsFromItems: function() { | ||
4878 | 3612 | |||
4879 | 3613 | var list = this.currentItem.find(":data(sortable-item)"); | ||
4880 | 3614 | |||
4881 | 3615 | for (var i=0; i < this.items.length; i++) { | ||
4882 | 3616 | |||
4883 | 3617 | for (var j=0; j < list.length; j++) { | ||
4884 | 3618 | if(list[j] == this.items[i].item[0]) | ||
4885 | 3619 | this.items.splice(i,1); | ||
4886 | 3620 | }; | ||
4887 | 3621 | |||
4888 | 3622 | }; | ||
4889 | 3623 | |||
4890 | 3624 | }, | ||
4891 | 3625 | |||
4892 | 3626 | _refreshItems: function(event) { | ||
4893 | 3627 | |||
4894 | 3628 | this.items = []; | ||
4895 | 3629 | this.containers = [this]; | ||
4896 | 3630 | var items = this.items; | ||
4897 | 3631 | var self = this; | ||
4898 | 3632 | var queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]]; | ||
4899 | 3633 | var connectWith = this._connectWith(); | ||
4900 | 3634 | |||
4901 | 3635 | if(connectWith) { | ||
4902 | 3636 | for (var i = connectWith.length - 1; i >= 0; i--){ | ||
4903 | 3637 | var cur = $(connectWith[i]); | ||
4904 | 3638 | for (var j = cur.length - 1; j >= 0; j--){ | ||
4905 | 3639 | var inst = $.data(cur[j], 'sortable'); | ||
4906 | 3640 | if(inst && inst != this && !inst.options.disabled) { | ||
4907 | 3641 | queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]); | ||
4908 | 3642 | this.containers.push(inst); | ||
4909 | 3643 | } | ||
4910 | 3644 | }; | ||
4911 | 3645 | }; | ||
4912 | 3646 | } | ||
4913 | 3647 | |||
4914 | 3648 | for (var i = queries.length - 1; i >= 0; i--) { | ||
4915 | 3649 | var targetData = queries[i][1]; | ||
4916 | 3650 | var _queries = queries[i][0]; | ||
4917 | 3651 | |||
4918 | 3652 | for (var j=0, queriesLength = _queries.length; j < queriesLength; j++) { | ||
4919 | 3653 | var item = $(_queries[j]); | ||
4920 | 3654 | |||
4921 | 3655 | item.data('sortable-item', targetData); // Data for target checking (mouse manager) | ||
4922 | 3656 | |||
4923 | 3657 | items.push({ | ||
4924 | 3658 | item: item, | ||
4925 | 3659 | instance: targetData, | ||
4926 | 3660 | width: 0, height: 0, | ||
4927 | 3661 | left: 0, top: 0 | ||
4928 | 3662 | }); | ||
4929 | 3663 | }; | ||
4930 | 3664 | }; | ||
4931 | 3665 | |||
4932 | 3666 | }, | ||
4933 | 3667 | |||
4934 | 3668 | refreshPositions: function(fast) { | ||
4935 | 3669 | |||
4936 | 3670 | //This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change | ||
4937 | 3671 | if(this.offsetParent && this.helper) { | ||
4938 | 3672 | this.offset.parent = this._getParentOffset(); | ||
4939 | 3673 | } | ||
4940 | 3674 | |||
4941 | 3675 | for (var i = this.items.length - 1; i >= 0; i--){ | ||
4942 | 3676 | var item = this.items[i]; | ||
4943 | 3677 | |||
4944 | 3678 | var t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item; | ||
4945 | 3679 | |||
4946 | 3680 | if (!fast) { | ||
4947 | 3681 | item.width = t.outerWidth(); | ||
4948 | 3682 | item.height = t.outerHeight(); | ||
4949 | 3683 | } | ||
4950 | 3684 | |||
4951 | 3685 | var p = t.offset(); | ||
4952 | 3686 | item.left = p.left; | ||
4953 | 3687 | item.top = p.top; | ||
4954 | 3688 | }; | ||
4955 | 3689 | |||
4956 | 3690 | if(this.options.custom && this.options.custom.refreshContainers) { | ||
4957 | 3691 | this.options.custom.refreshContainers.call(this); | ||
4958 | 3692 | } else { | ||
4959 | 3693 | for (var i = this.containers.length - 1; i >= 0; i--){ | ||
4960 | 3694 | var p = this.containers[i].element.offset(); | ||
4961 | 3695 | this.containers[i].containerCache.left = p.left; | ||
4962 | 3696 | this.containers[i].containerCache.top = p.top; | ||
4963 | 3697 | this.containers[i].containerCache.width = this.containers[i].element.outerWidth(); | ||
4964 | 3698 | this.containers[i].containerCache.height = this.containers[i].element.outerHeight(); | ||
4965 | 3699 | }; | ||
4966 | 3700 | } | ||
4967 | 3701 | |||
4968 | 3702 | return this; | ||
4969 | 3703 | }, | ||
4970 | 3704 | |||
4971 | 3705 | _createPlaceholder: function(that) { | ||
4972 | 3706 | |||
4973 | 3707 | var self = that || this, o = self.options; | ||
4974 | 3708 | |||
4975 | 3709 | if(!o.placeholder || o.placeholder.constructor == String) { | ||
4976 | 3710 | var className = o.placeholder; | ||
4977 | 3711 | o.placeholder = { | ||
4978 | 3712 | element: function() { | ||
4979 | 3713 | |||
4980 | 3714 | var el = $(document.createElement(self.currentItem[0].nodeName)) | ||
4981 | 3715 | .addClass(className || self.currentItem[0].className+" ui-sortable-placeholder") | ||
4982 | 3716 | .removeClass("ui-sortable-helper")[0]; | ||
4983 | 3717 | |||
4984 | 3718 | if(!className) | ||
4985 | 3719 | el.style.visibility = "hidden"; | ||
4986 | 3720 | |||
4987 | 3721 | return el; | ||
4988 | 3722 | }, | ||
4989 | 3723 | update: function(container, p) { | ||
4990 | 3724 | |||
4991 | 3725 | // 1. If a className is set as 'placeholder option, we don't force sizes - the class is responsible for that | ||
4992 | 3726 | // 2. The option 'forcePlaceholderSize can be enabled to force it even if a class name is specified | ||
4993 | 3727 | if(className && !o.forcePlaceholderSize) return; | ||
4994 | 3728 | |||
4995 | 3729 | //If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item | ||
4996 | 3730 | if(!p.height()) { p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10)); }; | ||
4997 | 3731 | if(!p.width()) { p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10)); }; | ||
4998 | 3732 | } | ||
4999 | 3733 | }; | ||
5000 | 3734 | } |