Changeset 570
add window iframeShim, add autocomplete unique option
Apr 14 2008 * 17:27 (7 months ago)
Committed by seb
Affected files:
trunk/src/auto_complete/auto_complete.js
(Unified diff)
| r569 | r570 | |
| 17 | 17 | delay: 0.2, // Delay before running ajax request |
| 18 | 18 | shadow: false, // Shadow theme name (false = no shadow) |
| 19 | 19 | highlight: false, // Highlight search string in list |
| 20 | | tokens: false // Tokens used to automatically adds a new entry (ex tokens:[',', ' '] for coma and spaces) |
| 20 | tokens: false, // Tokens used to automatically adds a new entry (ex tokens:[',', ' '] for coma and spaces) |
| 21 | unique: true // Do not display in suggestion a selected value |
| 21 | 22 | }, |
| 22 | 23 | |
| 23 | 24 | initialize: function(element, options) { |
| --- | --- | |
| 82 | 83 | else |
| 83 | 84 | this.hideAutocomplete().fire("input:empty"); |
| 84 | 85 | |
| 85 | | return this.fire("element:added", {element: li}); |
| 86 | return this.fire("element:added", {element: li, text: text, value: value}); |
| 86 | 87 | }, |
| 87 | 88 | |
| 88 | 89 | remove: function(element) { |
| --- | --- | |
| 298 | 299 | this.autocompletionContainer.hide(); |
| 299 | 300 | this.fire("request:started"); |
| 300 | 301 | |
| 301 | | new Ajax.Request(this.options.url, {parameters: {search: search, max: this.options.max.selection}, onComplete: function(transport) { |
| 302 | new Ajax.Request(this.options.url, {parameters: {search: search, max: this.options.max.selection, "selected[]": this.selectedValues()}, onComplete: function(transport) {
|
| 302 | 303 | this.setAutocompleteList(transport.responseText.evalJSON()); |
| 303 | 304 | this.timer = null; |
| 304 | 305 | this.fire("request:completed"); |
| --- | --- | |
| 418 | 419 | this.message.hide(); |
| 419 | 420 | if (this.options.url) |
| 420 | 421 | this.selectedList = this.list; |
| 421 | | else |
| 422 | else { |
| 422 | 423 | this.selectedList = this.list.findAll(function(entry) {return entry.text.match(value)}).slice(0, this.options.max.selection); |
| 424 | if (this.options.unique) { |
| 425 | var selected= this.selectedValues(); |
| 426 | if (! selected.empty()) |
| 427 | this.selectedList = this.selectedList.findAll(function(entry) {return !selected.include(entry.value)}); |
| 428 | } |
| 429 | } |
| 423 | 430 | this.autocompletionContainer.update(""); |
| 424 | 431 | if (this.selectedList.empty()) { |
| 425 | 432 | this.hideAutocomplete().fire('selection:empty'); |
| --- | --- | |
| 514 | 521 | updateHiddenField: function() { |
| 515 | 522 | var separator = this.options.tokens ? this.options.tokens.first() : " "; |
| 516 | 523 | this.hidden.value = this.selectedText ? $A([this.selectedText, this.input.value]).join(separator) : this.input.value; |
| 524 | }, |
| 525 | |
| 526 | selectedValues: function() { |
| 527 | var selected = this.container.select("li." + this.getClassName("box")); |
| 528 | return selected.collect(function(element) {return element.readAttribute("pui-autocomplete:value")}); |
| 517 | 529 | } |
| 518 | 530 | }); |
| 519 | 531 | |
trunk/src/shadow/shadow.js
(Unified diff)
| r533 | r570 | |
| 15 | 15 | options: { |
| 16 | 16 | theme: "mac_shadow", |
| 17 | 17 | focus: false, |
| 18 | | zIndex: 100 |
| 18 | zIndex: 100, |
| 19 | withIFrameShim: true |
| 19 | 20 | }, |
| 20 | 21 | |
| 21 | 22 | /* |
| --- | --- | |
| 38 | 39 | |
| 39 | 40 | this.element = $(element); |
| 40 | 41 | this.create(); |
| 41 | | this.iframe = Prototype.Browser.IE ? new UI.IframeShim() : null; |
| 42 | this.iframe = Prototype.Browser.IE && this.options.withIFrameShim ? new UI.IframeShim() : null; |
| 42 | 43 | |
| 43 | 44 | if (Object.isElement(this.element.parentNode)) |
| 44 | 45 | this.render(); |
| --- | --- | |
| 101 | 102 | this.shadowContents.each(function(item){ item.style.width = w}); |
| 102 | 103 | if (this.iframe) |
| 103 | 104 | this.iframe.setSize(width + this.shadowSize.width - this.shadowShift.width, height + this.shadowSize.height - this.shadowShift.height); |
| 104 | | |
| 105 | 105 | } |
| 106 | 106 | catch(e) { |
| 107 | 107 | // IE could throw an exception if called to early |
trunk/src/util/iframe_shim.js
(Unified diff)
| r533 | r570 | |
| 39 | 39 | */ |
| 40 | 40 | initialize: function() { |
| 41 | 41 | this.element = new Element('iframe', { |
| 42 | | style: 'position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);display:none', |
| 42 | style: 'position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=1);', |
| 43 | 43 | src: 'javascript:false;', |
| 44 | 44 | frameborder: 0 |
| 45 | 45 | }); |
trunk/src/window/shadow.js
(Unified diff)
| r498 | r570 | |
| 9 | 9 | if (this.shadow) { |
| 10 | 10 | this.shadow.hide(); |
| 11 | 11 | this.effect('show', this.shadow.shadow); |
| 12 | | } |
| 12 | } |
| 13 | if (this.iframe) |
| 14 | this.iframe.show(); |
| 13 | 15 | }, |
| 14 | 16 | |
| 15 | 17 | hideShadow: function() { |
| 16 | 18 | if (this.shadow) |
| 17 | 19 | this.effect('hide', this.shadow.shadow); |
| 20 | if (this.iframe) |
| 21 | this.iframe.hide(); |
| 18 | 22 | }, |
| 19 | 23 | |
| 20 | 24 | removeShadow: function() { |
| --- | --- | |
| 43 | 47 | .observe('blurred', this.blurShadow); |
| 44 | 48 | |
| 45 | 49 | if (this.options.shadow) |
| 46 | | this.shadow = new UI.Shadow(this.element, {theme: this.getShadowTheme()}); |
| 50 | this.shadow = new UI.Shadow(this.element, {theme: this.getShadowTheme(), withIFrameShim: false}); |
| 51 | this.iframe = Prototype.Browser.IE ? new UI.IframeShim() : null; |
| 47 | 52 | }, |
| 48 | 53 | |
| 49 | 54 | addElementsWithShadow: function() { |
| --- | --- | |
| 69 | 74 | var pos = this.getPosition(); |
| 70 | 75 | this.shadow.setPosition(pos.top, pos.left); |
| 71 | 76 | } |
| 77 | if (this.iframe) { |
| 78 | var pos = this.getPosition(); |
| 79 | this.iframe.setPosition(pos.top, pos.left); |
| 80 | } |
| 72 | 81 | return this; |
| 73 | 82 | }, |
| 74 | 83 | |
| --- | --- | |
| 78 | 87 | var size = this.getSize(); |
| 79 | 88 | this.shadow.setSize(size.width, size.height); |
| 80 | 89 | } |
| 90 | if (this.iframe) { |
| 91 | var size = this.getSize(); |
| 92 | this.iframe.setSize(size.width, size.height); |
| 93 | } |
| 81 | 94 | return this; |
| 82 | 95 | }, |
| 83 | 96 | |
| --- | --- | |
| 85 | 98 | this.setBoundsWithoutShadow(bounds, innerSize); |
| 86 | 99 | if (this.shadow) |
| 87 | 100 | this.shadow.setBounds(this.getBounds()); |
| 101 | if (this.iframe) |
| 102 | this.iframe.setBounds(this.getBounds()); |
| 88 | 103 | } |
| 89 | 104 | }); |
trunk/test/functional/auto_complete/test_auto_complete.html
(Unified diff)
| r568 | r570 | |
| 7 | 7 | |
| 8 | 8 | <script src="../../../lib/prototype.js" type="text/javascript"></script> |
| 9 | 9 | <script src="../../../lib/effects.js" type="text/javascript"></script> |
| 10 | | <script src="../../../test/lib/unittest.js" type="text/javascript"></script> |
| 11 | 10 | <script src="../../../dist/prototype-ui.js" type="text/javascript"></script> |
| 12 | 11 | <link href="../../../themes/auto_complete/mac_os_x.css" rel="stylesheet" type="text/css" /> |
| 13 | 12 | <link href="../../../themes/shadow/auto_complete.css" rel="stylesheet" type="text/css"> |
| --- | --- | |
| 44 | 43 | <script type="text/javascript"> |
| 45 | 44 | document.whenReady(function() { |
| 46 | 45 | ac = new UI.AutoComplete('pui-demo', { shadow: "auto_complete"}); |
| 47 | | ac.observe('input:empty', function() {ac.showMessage("Type a user name")}) |
| 48 | | .observe('selection:empty', function() {ac.showMessage("Nothing found")}); |
| 46 | ac.observe('input:empty', function(event) {event.memo.autocomplete.showMessage("Type a user name")}) |
| 47 | .observe('selection:empty', function(event) {event.memo.autocomplete.showMessage("Nothing found")}); |
| 49 | 48 | |
| 50 | 49 | ac.setAutocompleteList([{text:"Sébastien", value:1}, |
| 51 | 50 | {text:"Samuel", value:2}, |
trunk/test/functional/auto_complete/test_auto_complete_ajax.html
(Unified diff)
| r569 | r570 | |
| 19 | 19 | |
| 20 | 20 | <body id="test"> |
| 21 | 21 | <h1>Prototype UI autocomplete Demo (Ajax)</h1> |
| 22 | Ajax requests are simulated by stubbing Ajax.Request#onComplete and may not work on some browser (like IE)<br> |
| 23 | One second delay is set to simulate also internet traffic<br><br> |
| 22 | 24 | Type "e" for example to see autocompletion.<br/><br/> |
| 23 | 25 | <form action="test_submit" method="get" accept-charset="utf-8"> |
| 24 | 26 | <div id="input-text"> |
| --- | --- | |
| 36 | 38 | <button onclick="return false;">Submit</button> |
| 37 | 39 | <script type="text/javascript"> |
| 38 | 40 | |
| 39 | | |
| 41 | // Simulate AJAX response from server. It filters response values with input search string and handles unique options |
| 40 | 42 | Ajax.Request.prototype.originalInitialize = Ajax.Request.prototype.initialize; |
| 41 | 43 | Ajax.Request.prototype.initialize = function(url, options) { |
| 44 | var unique = ac.options.unique; |
| 45 | |
| 42 | 46 | options.onComplete = options.onComplete.wrap(function(proceed, request, json) { |
| 43 | | //console.log(request.responseText) |
| 44 | 47 | var list = request.responseText.evalJSON(); |
| 45 | | var value = $("pui-demo").value; |
| 46 | | list = list.findAll(function(entry) {return entry.text.match(value)}); |
| 47 | | proceed.curry(request, json).delay(0.1); |
| 48 | | }); |
| 48 | // Simulate a search on server |
| 49 | list = list.findAll(function(entry) {return entry.text.match(this.search)}.bind(this)); |
| 50 | if (unique && !this.selected.empty()) |
| 51 | list = list.findAll(function(entry) {return !this.selected.include(entry.value)}.bind(this)); |
| 52 | request.responseText = list.toJSON() |
| 53 | proceed.curry(request, json).delay(1); |
| 54 | }.bind(this)); |
| 55 | this.search = options.parameters.search; |
| 56 | this.selected = options.parameters.selected; |
| 49 | 57 | this.originalInitialize(url, options); |
| 50 | 58 | } |
| 51 | 59 | |
| --- | --- | |
| 54 | 62 | Event.observe(window, "load", function() { |
| 55 | 63 | ac = new UI.AutoComplete('pui-demo', { url: "../../fixtures/auto_complete.json", |
| 56 | 64 | shadow: "drop_shadow" |
| 65 | |
| 57 | 66 | }); |
| 58 | | ac.observe('input:empty', function() {ac.showMessage("Type a user name")}) |
| 59 | | .observe('request:started', function() {ac.showMessage("Please wait...")}) |
| 60 | | .observe('selection:empty', function() {ac.showMessage("Nothing found")}); |
| 67 | ac.observe('input:empty', function(event) {event.memo.autocomplete.showMessage("Type a user name")}) |
| 68 | .observe('request:started', function(event) {event.memo.autocomplete.showMessage("Please wait...")}) |
| 69 | .observe('selection:empty', function(event) {event.memo.autocomplete.showMessage("Nothing found")}); |
| 61 | 70 | }); |
| 62 | 71 | </script> |
| 63 | 72 | </body> |
trunk/test/functional/auto_complete/test_auto_complete_in_window.html
(Unified diff)
| r568 | r570 | |
| 56 | 56 | win.content.insert($('autocomplete')); |
| 57 | 57 | win.observe("shown", function() { |
| 58 | 58 | ac = new UI.AutoComplete('pui-demo', { shadow: "auto_complete" }); |
| 59 | | ac.observe('input:empty', function() {ac.showMessage("Type a user name")}) |
| 60 | | .observe('selection:empty', function() {ac.showMessage("Nothing found")}); |
| 59 | ac.observe('input:empty', function(event) {event.memo.autocomplete.showMessage("Type a user name")}) |
| 60 | .observe('selection:empty', function(event) {event.memo.autocompleteac.showMessage("Nothing found")}); |
| 61 | |
| 61 | 62 | ac.setAutocompleteList([{text:"Sébastien", value:1}, |
| 62 | 63 | {text:"Samuel", value:2}, |
| 63 | 64 | {text:"Vincent", value:3}, |
trunk/test/functional/auto_complete/test_auto_complete_token.html
(Unified diff)
| r569 | r570 | |
| 23 | 23 | Type "e" for example to see autocompletion.<br/><br/> |
| 24 | 24 | <form action="test_submit" accept-charset="utf-8" id="test-form"> |
| 25 | 25 | Tags: <div id="input-text"> |
| 26 | | <input type="text" value="Ruby, Apple" id="pui-demo" name="taglist" /> |
| 26 | <input type="text" value="" id="pui-demo" name="taglist" /> |
| 27 | 27 | </div> |
| 28 | 28 | <br/> |
| 29 | 29 | <input type=submit onclick="console.log($('test-form').serialize());return false;" value="Submit"/> |
trunk/test/functional/window/test.html
(Unified diff)
| r567 | r570 | |
| 5 | 5 | <title>Test PWC</title> |
| 6 | 6 | <script src="../../../lib/prototype.js" type="text/javascript"></script> |
| 7 | 7 | <script src="../../../lib/effects.js" type="text/javascript"></script> |
| 8 | | <script src="../../../dist/prototype-ui.packed.js" type="text/javascript"></script> |
| 8 | <script src="../../../dist/prototype-ui.js" type="text/javascript"></script> |
| 9 | 9 | |
| 10 | 10 | <link href="../../../themes/window/window.css" rel="stylesheet" type="text/css"> |
| 11 | 11 | <link href="../../../themes/window/mac_os_x.css" rel="stylesheet" type="text/css"> |
| --- | --- | |
| 20 | 20 | </head> |
| 21 | 21 | <body> |
| 22 | 22 | <a href="#" onclick="openWindow(); return false;">Open window</a> |
| 23 | <br/> |
| 24 | Add Select box for testing iFrameShim on IE<br/> |
| 25 | <select> |
| 26 | <option>option 1</option> |
| 27 | <option>option 2</option> |
| 28 | <option>option 3</option> |
| 29 | </select> |
| 30 | <br/> |
| 31 | <select> |
| 32 | <option>option 1</option> |
| 33 | <option>option 2</option> |
| 34 | <option>option 3</option> |
| 35 | </select> |
| 23 | 36 | |
| 24 | 37 | <script type="text/javascript"> |
| 25 | 38 | function runTest() { |