| | 169 | /** Return a DOM fragment which has all the fields needed to set the |
| | 170 | * attributes for a link given a structure of initial values. |
| | 171 | * |
| | 172 | * OR return a structure of values taken from the currently table. |
| | 173 | */ |
| | 174 | |
| | 175 | MootoolsFileManager.prototype.FileManagerAttributes = function (details) |
| | 176 | { |
| | 177 | |
| | 178 | var self = this; |
| | 179 | self._LastFileDetails = details; |
| | 180 | |
| | 181 | function f(name) |
| | 182 | { |
| | 183 | var e = self._FileManagerAttributesTable.getElementsByTagName('input'); |
| | 184 | for(var i = 0; i < e.length; i++) |
| | 185 | { |
| | 186 | if(e[i].name == name) return e[i]; |
| | 187 | } |
| | 188 | |
| | 189 | var e = self._FileManagerAttributesTable.getElementsByTagName('select'); |
| | 190 | for(var i = 0; i < e.length; i++) |
| | 191 | { |
| | 192 | if(e[i].name == name) return e[i]; |
| | 193 | } |
| | 194 | |
| | 195 | return null; |
| | 196 | } |
| | 197 | |
| | 198 | function s(name, value) |
| | 199 | { |
| | 200 | for(var i = 0; i < f(name).options.length; i++) |
| | 201 | { |
| | 202 | if(f(name).options[i].value == value) |
| | 203 | { |
| | 204 | // f(name).options[i].selected = true; |
| | 205 | f(name).selectedIndex = i; |
| | 206 | return true; |
| | 207 | } |
| | 208 | } |
| | 209 | return false; |
| | 210 | } |
| | 211 | |
| | 212 | if(!this._FileManagerAttributesTable) |
| | 213 | { |
| | 214 | this._FileManagerAttributesTable = (function() { |
| | 215 | var div = document.createElement('div'); |
| | 216 | |
| | 217 | var h2 = document.createElement('h2'); |
| | 218 | h2.appendChild(document.createTextNode('Link Attributes')); |
| | 219 | div.appendChild(h2); |
| | 220 | |
| | 221 | var table = document.createElement('table'); |
| | 222 | div.appendChild(table); |
| | 223 | |
| | 224 | table.className = 'filemanager-extended-options'; |
| | 225 | var tbody = table.appendChild(document.createElement('tbody')); |
| | 226 | |
| | 227 | { // Title |
| | 228 | var tr = tbody.appendChild(document.createElement('tr')); |
| | 229 | var th = tr.appendChild(document.createElement('th')); |
| | 230 | var label = th.appendChild(document.createTextNode('Title:')); |
| | 231 | |
| | 232 | var td = tr.appendChild(document.createElement('td')); |
| | 233 | var input = td.appendChild(document.createElement('input')); |
| | 234 | |
| | 235 | td.colSpan = 6; |
| | 236 | input.name = 'f_title'; |
| | 237 | input.type = 'text'; |
| | 238 | th.className = td.className = 'filemanager-f_title'; |
| | 239 | } |
| | 240 | |
| | 241 | { // Content Type |
| | 242 | var tr = tbody.appendChild(document.createElement('tr')); |
| | 243 | var th = tr.appendChild(document.createElement('th')); |
| | 244 | var label = th.appendChild(document.createTextNode('Type:')); |
| | 245 | |
| | 246 | var td = tr.appendChild(document.createElement('td')); |
| | 247 | var input = td.appendChild(document.createElement('input')); |
| | 248 | |
| | 249 | td.colSpan = 6; |
| | 250 | input.name = 'f_type'; |
| | 251 | input.type = 'text'; |
| | 252 | th.className = td.className = 'filemanager-f_type'; |
| | 253 | } |
| | 254 | |
| | 255 | { // Target |
| | 256 | var tr = tbody.appendChild(document.createElement('tr')); |
| | 257 | |
| | 258 | { // Target |
| | 259 | var th = tr.appendChild(document.createElement('th')); |
| | 260 | var label = th.appendChild(document.createTextNode('Open In:')); |
| | 261 | |
| | 262 | var td = tr.appendChild(document.createElement('td')); |
| | 263 | td.colSpan = 2; |
| | 264 | var input = td.appendChild(document.createElement('select')); |
| | 265 | |
| | 266 | input.name = 'f_target'; |
| | 267 | input.options[0] = new Option(''); |
| | 268 | input.options[1] = new Option('New Window', '_blank'); |
| | 269 | input.options[2] = new Option('Top Frame', '_top'); |
| | 270 | input.options[3] = new Option('Other Frame:', ''); |
| | 271 | |
| | 272 | Xinha._addEvent(input, 'change', function() |
| | 273 | { |
| | 274 | if(f('f_target').selectedIndex == 3) |
| | 275 | { |
| | 276 | f('f_otherTarget').style.visibility = 'visible'; |
| | 277 | } |
| | 278 | else |
| | 279 | { |
| | 280 | f('f_otherTarget').style.visibility = 'hidden'; |
| | 281 | } |
| | 282 | }); |
| | 283 | |
| | 284 | var input = td.appendChild(document.createElement('input')); |
| | 285 | input.name = 'f_otherTarget'; |
| | 286 | input.size = 7; |
| | 287 | input.type = 'text'; |
| | 288 | input.style.visibility = 'hidden'; |
| | 289 | |
| | 290 | th.className = td.className = 'filemanager-f_target'; |
| | 291 | } |
| | 292 | } |
| | 293 | |
| | 294 | return div; |
| | 295 | })(); |
| | 296 | } |
| | 297 | |
| | 298 | if(this.current_attributes) |
| | 299 | { |
| | 300 | f('f_title').value = this.current_attributes.f_title; |
| | 301 | f('f_type').value = this.current_attributes.f_type; |
| | 302 | |
| | 303 | if(this.current_attributes.f_target) |
| | 304 | { |
| | 305 | if(!s('f_target', this.current_attributes.f_target)) |
| | 306 | { |
| | 307 | f('f_target').selectedIndex = 3; |
| | 308 | f('f_otherTarget').value = this.current_attributes.f_target; |
| | 309 | } |
| | 310 | else |
| | 311 | { |
| | 312 | f('f_otherTarget').value = ''; |
| | 313 | } |
| | 314 | } |
| | 315 | |
| | 316 | this.current_attributes = null; |
| | 317 | } |
| | 318 | |
| | 319 | // If no details were supplied, we return the current ones |
| | 320 | if(!details) |
| | 321 | { |
| | 322 | var details = { |
| | 323 | f_title: f('f_title').value, |
| | 324 | f_type: f('f_type').value, |
| | 325 | f_target: f('f_target').selectedIndex < 3 ? f('f_target').options[f('f_target').selectedIndex].value : f('f_otherTarget').value, |
| | 326 | |
| | 327 | table: this._FileManagerAttributesTable |
| | 328 | } |
| | 329 | |
| | 330 | return details; |
| | 331 | } |
| | 332 | |
| | 333 | // If details were supplied, we set the appropriate ones. |
| | 334 | if(details.mime) f('f_type').value = details.mime; |
| | 335 | |
| | 336 | f('f_target').style.visibility = ''; // Ensure that the select hasn't been hidden by an overlay and not put back |
| | 337 | |
| | 338 | if(f('f_target').selectedIndex == 3) |
| | 339 | { |
| | 340 | f('f_otherTarget').style.visibility = 'visible'; |
| | 341 | } |
| | 342 | else |
| | 343 | { |
| | 344 | f('f_otherTarget').style.visibility = 'hidden'; |
| | 345 | } |
| | 346 | |
| | 347 | return this._FileManagerAttributesTable; |
| | 348 | }; |