티스토리 뷰
기존의 스크립트를 prototype 1.6.3 의 Class 생성에 맞게 직접 패치했다.
스크립트
스타일쉬트
스크립트
// Copyright (c) 2006 Gabriel Lanzani (http://www.glanzani.com.ar) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // SEE CHANGELOG FOR A COMPLETE CHANGES OVERVIEW // VERSION 0.3.1 /* USAGE: 1 - include prototype.js 2 - include scriptaculous.js 3 - include select.js 4 - include autocomplete styles 5 - write a selec control with a valid id and name and its options 6 - just add this script in page */ Autocompleter.SelectBox = Class.create(Autocompleter.Base, { initialize: function(select, options) { this.element = "" $(select).insert({ before:this.element }); var inputClasses = $(select).classNames(); inputClasses.each(function(inputClass) { $($(select).id + "_combo").addClassName(inputClass); }); this.update = "" $(select).insert({ before:this.update }); this.baseInitialize($(select).id + "_combo", $(select).id + "_options", options); this.select = select; this.selectOptions = []; $(this.element.id).addClassName(this.options.initClass); $(this.element.id).setAttribute('readonly','readonly'); this.element.readOnly = true; if(this.options.debug) alert('input ' + this.element.id + ' and div '+ this.update.id + ' created, Autocompleter.Base() initialized'); if(!this.options.debug) $(select).hide(); var optionList = $(this.select).getElementsByTagName('option'); var nodes = $A(optionList); for(i=0; i" + nodes[i].innerHTML + ''); if (nodes[i].getAttribute("selected")) this.element.value = nodes[i].innerHTML; if(this.options.debug) alert('option ' + nodes[i].innerHTML + ' added to '+ this.update.id); } $(this.element).observe("click", this.activate.bindAsEventListener(this)); if ($(select).selectedIndex >= 0) this.element.value = $(select).options[$(select).selectedIndex].innerHTML; var self = this; this.options.afterUpdateElement = function(text, li) { var optionList = $(select).getElementsByTagName('option'); var nodes = $A(optionList); var opt = nodes.find( function(node) { return (node.value == li.id); }); $(select).selectedIndex = opt.index; if(self.options.redirect) document.location.href = opt.value; if(self.options.autoSubmit) $(self.options.autoSubmit).submit; } }, getUpdatedChoices: function() { this.updateChoices(this.setValues()); }, setValues : function() { return (" " + this.selectOptions.join('') + "
"); }, setOptions: function(options) { this.options = Object.extend({ //MORE OPTIONS TO EXTEND THIS CLASS redirect : false, // redirects to option value debug : false, // show alerts with information autoSubmit : '', // form Id to submit after change initClass : 'combo' // set css class }, options || {}); } });
스타일쉬트
div.autocomplete { position:absolute; width:200px; background-color:white; border:1px solid #ccc; margin:0px; padding:0px; font-size: 9pt; text-align:left; max-height:200px; overflow:auto; } div.autocomplete ul { list-style-type:none; margin:0px; padding:0px; } div.autocomplete ul li.selected { background-color: #EAF2FB; } div.autocomplete ul li { list-style-type:none; display:block; margin:0; padding:2px; cursor:pointer; } input.combo /* look&fell of scriptaculous select box */ { background: url('/images/bg_select.jpg') right; width: 10em; height: 20px; cursor: pointer; border: 1px solid #ccc; text-align:left; font: normal 9pt sans-serif; }
'웹프로그래밍 > js' 카테고리의 다른 글
Stereotabs: Prototype 과 Scriptaculous 로 구현한 탭 (0) | 2009.11.05 |
---|---|
Prototype JS로 Checkbox들 모두 선택 구현 (1) | 2009.11.05 |
마우스 오버 스크롤 메뉴 (2) | 2009.07.07 |
모든 자바스크립트 오류를 디버그 콘솔에 던지기 (0) | 2009.06.01 |
Shadowbox.js (0) | 2009.05.07 |
댓글
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- Wordpress
- CSS
- macos
- 워드프레스
- 안드로이드
- git
- IE
- centos
- PHP
- iphone
- IOS
- mssql
- laravel
- Docker
- 한글
- JQuery
- javascript
- sencha touch
- nodejs
- JSON
- Linux
- classic asp
- Debug
- nginx
- Android
- ASP
- Prototype
- API
- Mac
- iis
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함