From 89c6be32eef4c78fa2ea619b4db6f7f608de3aad Mon Sep 17 00:00:00 2001 From: Coleman Date: Wed, 23 Jul 2008 05:53:11 -0500 Subject: [PATCH] remove control suite that is unused --- public/javascripts/control.modal.js | 463 --------------------- public/javascripts/control.progress_bar.js | 99 ----- public/javascripts/control.tabs.js | 159 ------- public/javascripts/control.textarea.js | 118 ------ 4 files changed, 839 deletions(-) delete mode 100644 public/javascripts/control.modal.js delete mode 100644 public/javascripts/control.progress_bar.js delete mode 100644 public/javascripts/control.tabs.js delete mode 100644 public/javascripts/control.textarea.js diff --git a/public/javascripts/control.modal.js b/public/javascripts/control.modal.js deleted file mode 100644 index 00daa69..0000000 --- a/public/javascripts/control.modal.js +++ /dev/null @@ -1,463 +0,0 @@ -/** - * @author Ryan Johnson - * @copyright 2007 LivePipe LLC - * @package Control.Modal - * @license MIT - * @url http://livepipe.net/projects/control_modal/ - * @version 2.2.3 - */ - -if(typeof(Control) == "undefined") - Control = {}; -Control.Modal = Class.create(); -Object.extend(Control.Modal,{ - loaded: false, - loading: false, - loadingTimeout: false, - overlay: false, - container: false, - current: false, - ie: false, - effects: { - containerFade: false, - containerAppear: false, - overlayFade: false, - overlayAppear: false - }, - targetRegexp: /#(.+)$/, - imgRegexp: /\.(jpe?g|gif|png|tiff?)$/i, - overlayStyles: { - position: 'fixed', - top: 0, - left: 0, - width: '100%', - height: '100%', - zIndex: 9998 - }, - overlayIEStyles: { - position: 'absolute', - top: 0, - left: 0, - zIndex: 9998 - }, - disableHoverClose: false, - load: function(){ - if(!Control.Modal.loaded){ - Control.Modal.loaded = true; - Control.Modal.ie = !(typeof document.body.style.maxHeight != 'undefined'); - Control.Modal.overlay = $(document.createElement('div')); - Control.Modal.overlay.id = 'modal_overlay'; - Object.extend(Control.Modal.overlay.style,Control.Modal['overlay' + (Control.Modal.ie ? 'IE' : '') + 'Styles']); - Control.Modal.overlay.hide(); - Control.Modal.container = $(document.createElement('div')); - Control.Modal.container.id = 'modal_container'; - Control.Modal.container.hide(); - Control.Modal.loading = $(document.createElement('div')); - Control.Modal.loading.id = 'modal_loading'; - Control.Modal.loading.hide(); - var body_tag = document.getElementsByTagName('body')[0]; - body_tag.appendChild(Control.Modal.overlay); - body_tag.appendChild(Control.Modal.container); - body_tag.appendChild(Control.Modal.loading); - Control.Modal.container.observe('mouseout',function(event){ - if(!Control.Modal.disableHoverClose && Control.Modal.current && Control.Modal.current.options.hover && !Position.within(Control.Modal.container,Event.pointerX(event),Event.pointerY(event))) - Control.Modal.close(); - }); - } - }, - open: function(contents,options){ - options = options || {}; - if(!options.contents) - options.contents = contents; - var modal_instance = new Control.Modal(false,options); - modal_instance.open(); - return modal_instance; - }, - close: function(force){ - if(typeof(force) != 'boolean') - force = false; - if(Control.Modal.current) - Control.Modal.current.close(force); - }, - attachEvents: function(){ - Event.observe(window,'load',Control.Modal.load); - Event.observe(window,'unload',Event.unloadCache,false); - }, - center: function(element){ - if(!element._absolutized){ - element.setStyle({ - position: 'absolute' - }); - element._absolutized = true; - } - var dimensions = element.getDimensions(); - Position.prepare(); - var offset_left = (Position.deltaX + Math.floor((Control.Modal.getWindowWidth() - dimensions.width) / 2)); - var offset_top = (Position.deltaY + ((Control.Modal.getWindowHeight() > dimensions.height) ? Math.floor((Control.Modal.getWindowHeight() - dimensions.height) / 2) : 0)); - element.setStyle({ - top: ((dimensions.height <= Control.Modal.getDocumentHeight()) ? ((offset_top != null && offset_top > 0) ? offset_top : '0') + 'px' : 0), - left: ((dimensions.width <= Control.Modal.getDocumentWidth()) ? ((offset_left != null && offset_left > 0) ? offset_left : '0') + 'px' : 0) - }); - }, - getWindowWidth: function(){ - return (self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0); - }, - getWindowHeight: function(){ - return (self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0); - }, - getDocumentWidth: function(){ - return Math.min(document.body.scrollWidth,Control.Modal.getWindowWidth()); - }, - getDocumentHeight: function(){ - return Math.max(document.body.scrollHeight,Control.Modal.getWindowHeight()); - }, - onKeyDown: function(event){ - if(event.keyCode == Event.KEY_ESC) - Control.Modal.close(); - } -}); -Object.extend(Control.Modal.prototype,{ - mode: '', - html: false, - href: '', - element: false, - src: false, - imageLoaded: false, - ajaxRequest: false, - initialize: function(element,options){ - this.element = $(element); - this.options = { - beforeOpen: Prototype.emptyFunction, - afterOpen: Prototype.emptyFunction, - beforeClose: Prototype.emptyFunction, - afterClose: Prototype.emptyFunction, - onSuccess: Prototype.emptyFunction, - onFailure: Prototype.emptyFunction, - onException: Prototype.emptyFunction, - beforeImageLoad: Prototype.emptyFunction, - afterImageLoad: Prototype.emptyFunction, - autoOpenIfLinked: true, - contents: false, - loading: false, //display loading indicator - fade: false, - fadeDuration: 0.75, - image: false, - imageCloseOnClick: true, - hover: false, - iframe: false, - iframeTemplate: new Template(''), - evalScripts: true, //for Ajax, define here instead of in requestOptions - requestOptions: {}, //for Ajax.Request - overlayDisplay: true, - overlayClassName: '', - overlayCloseOnClick: true, - containerClassName: '', - opacity: 0.3, - zIndex: 9998, - width: null, - height: null, - offsetLeft: 0, //for use with 'relative' - offsetTop: 0, //for use with 'relative' - position: 'absolute' //'absolute' or 'relative' - }; - Object.extend(this.options,options || {}); - var target_match = false; - var image_match = false; - if(this.element){ - target_match = Control.Modal.targetRegexp.exec(this.element.href); - image_match = Control.Modal.imgRegexp.exec(this.element.href); - } - if(this.options.position == 'mouse') - this.options.hover = true; - if(this.options.contents){ - this.mode = 'contents'; - }else if(this.options.image || image_match){ - this.mode = 'image'; - this.src = this.element.href; - }else if(target_match){ - this.mode = 'named'; - var x = $(target_match[1]); - this.html = x.innerHTML; - x.remove(); - this.href = target_match[1]; - }else{ - this.mode = (this.options.iframe) ? 'iframe' : 'ajax'; - this.href = this.element.href; - } - if(this.element){ - if(this.options.hover){ - this.element.observe('mouseover',this.open.bind(this)); - this.element.observe('mouseout',function(event){ - if(!Position.within(Control.Modal.container,Event.pointerX(event),Event.pointerY(event))) - this.close(); - }.bindAsEventListener(this)); - }else{ - this.element.onclick = function(event){ - this.open(); - Event.stop(event); - return false; - }.bindAsEventListener(this); - } - } - var targets = Control.Modal.targetRegexp.exec(window.location); - this.position = function(event){ - if(this.options.position == 'absolute') - Control.Modal.center(Control.Modal.container); - else{ - var xy = (event && this.options.position == 'mouse' ? [Event.pointerX(event),Event.pointerY(event)] : Position.cumulativeOffset(this.element)); - Control.Modal.container.setStyle({ - position: 'absolute', - top: xy[1] + (typeof(this.options.offsetTop) == 'function' ? this.options.offsetTop() : this.options.offsetTop) + 'px', - left: xy[0] + (typeof(this.options.offsetLeft) == 'function' ? this.options.offsetLeft() : this.options.offsetLeft) + 'px' - }); - } - if(Control.Modal.ie){ - Control.Modal.overlay.setStyle({ - height: Control.Modal.getDocumentHeight() + 'px', - width: Control.Modal.getDocumentWidth() + 'px' - }); - } - }.bind(this); - if(this.mode == 'named' && this.options.autoOpenIfLinked && targets && targets[1] && targets[1] == this.href) - this.open(); - }, - showLoadingIndicator: function(){ - if(this.options.loading){ - Control.Modal.loadingTimeout = window.setTimeout(function(){ - var modal_image = $('modal_image'); - if(modal_image) - modal_image.hide(); - Control.Modal.loading.style.zIndex = this.options.zIndex + 1; - Control.Modal.loading.update(''); - Control.Modal.loading.show(); - Control.Modal.center(Control.Modal.loading); - }.bind(this),250); - } - }, - hideLoadingIndicator: function(){ - if(this.options.loading){ - if(Control.Modal.loadingTimeout) - window.clearTimeout(Control.Modal.loadingTimeout); - var modal_image = $('modal_image'); - if(modal_image) - modal_image.show(); - Control.Modal.loading.hide(); - } - }, - open: function(force){ - if(!force && this.notify('beforeOpen') === false) - return; - if(!Control.Modal.loaded) - Control.Modal.load(); - Control.Modal.close(); - if(!this.options.hover) - Event.observe($(document.getElementsByTagName('body')[0]),'keydown',Control.Modal.onKeyDown); - Control.Modal.current = this; - if(!this.options.hover) - Control.Modal.overlay.setStyle({ - zIndex: this.options.zIndex, - opacity: this.options.opacity - }); - Control.Modal.container.setStyle({ - zIndex: this.options.zIndex + 1, - width: (this.options.width ? (typeof(this.options.width) == 'function' ? this.options.width() : this.options.width) + 'px' : null), - height: (this.options.height ? (typeof(this.options.height) == 'function' ? this.options.height() : this.options.height) + 'px' : null) - }); - if(Control.Modal.ie && !this.options.hover){ - $A(document.getElementsByTagName('select')).each(function(select){ - select.style.visibility = 'hidden'; - }); - } - Control.Modal.overlay.addClassName(this.options.overlayClassName); - Control.Modal.container.addClassName(this.options.containerClassName); - switch(this.mode){ - case 'image': - this.imageLoaded = false; - this.notify('beforeImageLoad'); - this.showLoadingIndicator(); - var img = document.createElement('img'); - img.onload = function(img){ - this.hideLoadingIndicator(); - this.update([img]); - if(this.options.imageCloseOnClick) - $(img).observe('click',Control.Modal.close); - this.position(); - this.notify('afterImageLoad'); - img.onload = null; - }.bind(this,img); - img.src = this.src; - img.id = 'modal_image'; - break; - case 'ajax': - this.notify('beforeLoad'); - var options = { - method: 'post', - onSuccess: function(request){ - this.hideLoadingIndicator(); - this.update(request.responseText); - this.notify('onSuccess',request); - this.ajaxRequest = false; - }.bind(this), - onFailure: function(){ - this.notify('onFailure'); - }.bind(this), - onException: function(){ - this.notify('onException'); - }.bind(this) - }; - Object.extend(options,this.options.requestOptions); - this.showLoadingIndicator(); - this.ajaxRequest = new Ajax.Request(this.href,options); - break; - case 'iframe': - this.update(this.options.iframeTemplate.evaluate({href: this.href, id: 'modal_iframe'})); - break; - case 'contents': - this.update((typeof(this.options.contents) == 'function' ? this.options.contents() : this.options.contents)); - break; - case 'named': - this.update(this.html); - break; - } - if(!this.options.hover){ - if(this.options.overlayCloseOnClick && this.options.overlayDisplay) - Control.Modal.overlay.observe('click',Control.Modal.close); - if(this.options.overlayDisplay){ - if(this.options.fade){ - if(Control.Modal.effects.overlayFade) - Control.Modal.effects.overlayFade.cancel(); - Control.Modal.effects.overlayAppear = new Effect.Appear(Control.Modal.overlay,{ - queue: { - position: 'front', - scope: 'Control.Modal' - }, - to: this.options.opacity, - duration: this.options.fadeDuration / 2 - }); - }else - Control.Modal.overlay.show(); - } - } - if(this.options.position == 'mouse'){ - this.mouseHoverListener = this.position.bindAsEventListener(this); - this.element.observe('mousemove',this.mouseHoverListener); - } - this.notify('afterOpen'); - }, - update: function(html){ - if(typeof(html) == 'string') - Control.Modal.container.update(html); - else{ - Control.Modal.container.update(''); - (html.each) ? html.each(function(node){ - Control.Modal.container.appendChild(node); - }) : Control.Modal.container.appendChild(node); - } - if(this.options.fade){ - if(Control.Modal.effects.containerFade) - Control.Modal.effects.containerFade.cancel(); - Control.Modal.effects.containerAppear = new Effect.Appear(Control.Modal.container,{ - queue: { - position: 'end', - scope: 'Control.Modal' - }, - to: 1, - duration: this.options.fadeDuration / 2 - }); - }else - Control.Modal.container.show(); - this.position(); - Event.observe(window,'resize',this.position,false); - Event.observe(window,'scroll',this.position,false); - }, - close: function(force){ - if(!force && this.notify('beforeClose') === false) - return; - if(this.ajaxRequest) - this.ajaxRequest.transport.abort(); - this.hideLoadingIndicator(); - if(this.mode == 'image'){ - var modal_image = $('modal_image'); - if(this.options.imageCloseOnClick && modal_image) - modal_image.stopObserving('click',Control.Modal.close); - } - if(Control.Modal.ie && !this.options.hover){ - $A(document.getElementsByTagName('select')).each(function(select){ - select.style.visibility = 'visible'; - }); - } - if(!this.options.hover) - Event.stopObserving(window,'keyup',Control.Modal.onKeyDown); - Control.Modal.current = false; - Event.stopObserving(window,'resize',this.position,false); - Event.stopObserving(window,'scroll',this.position,false); - if(!this.options.hover){ - if(this.options.overlayCloseOnClick && this.options.overlayDisplay) - Control.Modal.overlay.stopObserving('click',Control.Modal.close); - if(this.options.overlayDisplay){ - if(this.options.fade){ - if(Control.Modal.effects.overlayAppear) - Control.Modal.effects.overlayAppear.cancel(); - Control.Modal.effects.overlayFade = new Effect.Fade(Control.Modal.overlay,{ - queue: { - position: 'end', - scope: 'Control.Modal' - }, - from: this.options.opacity, - to: 0, - duration: this.options.fadeDuration / 2 - }); - }else - Control.Modal.overlay.hide(); - } - } - if(this.options.fade){ - if(Control.Modal.effects.containerAppear) - Control.Modal.effects.containerAppear.cancel(); - Control.Modal.effects.containerFade = new Effect.Fade(Control.Modal.container,{ - queue: { - position: 'front', - scope: 'Control.Modal' - }, - from: 1, - to: 0, - duration: this.options.fadeDuration / 2, - afterFinish: function(){ - Control.Modal.container.update(''); - this.resetClassNameAndStyles(); - }.bind(this) - }); - }else{ - Control.Modal.container.hide(); - Control.Modal.container.update(''); - this.resetClassNameAndStyles(); - } - if(this.options.position == 'mouse') - this.element.stopObserving('mousemove',this.mouseHoverListener); - this.notify('afterClose'); - }, - resetClassNameAndStyles: function(){ - Control.Modal.overlay.removeClassName(this.options.overlayClassName); - Control.Modal.container.removeClassName(this.options.containerClassName); - Control.Modal.container.setStyle({ - height: null, - width: null, - top: null, - left: null - }); - }, - notify: function(event_name){ - try{ - if(this.options[event_name]) - return [this.options[event_name].apply(this.options[event_name],$A(arguments).slice(1))]; - }catch(e){ - if(e != $break) - throw e; - else - return false; - } - } -}); -if(typeof(Object.Event) != 'undefined') - Object.Event.extend(Control.Modal); -Control.Modal.attachEvents(); \ No newline at end of file diff --git a/public/javascripts/control.progress_bar.js b/public/javascripts/control.progress_bar.js deleted file mode 100644 index 9967961..0000000 --- a/public/javascripts/control.progress_bar.js +++ /dev/null @@ -1,99 +0,0 @@ -/** - * @author Ryan Johnson - * @copyright 2007 LivePipe LLC - * @package Control.ProgressBar - * @license MIT - * @url http://livepipe.net/projects/control_progress_bar/ - * @version 1.0.1 - */ - -if(typeof(Control) == 'undefined') - Control = {}; -Control.ProgressBar = Class.create(); -Object.extend(Control.ProgressBar.prototype,{ - container: false, - containerWidth: 0, - progressContainer: false, - progress: 0, - executer: false, - active: false, - poller: false, - initialize: function(container,options){ - this.container = $(container); - this.containerWidth = this.container.getDimensions().width - (parseInt(this.container.getStyle('border-right-width').replace(/px/,'')) + parseInt(this.container.getStyle('border-left-width').replace(/px/,''))); - this.progressContainer = $(document.createElement('div')); - this.progressContainer.setStyle({ - width: this.containerWidth + 'px', - height: '100%', - position: 'absolute', - top: '0px', - right: '0px' - }); - this.container.appendChild(this.progressContainer); - this.options = { - afterChange: Prototype.emptyFunction, - interval: 0.25, - step: 1, - classNames: { - active: 'progress_bar_active', - inactive: 'progress_bar_inactive' - } - }; - Object.extend(this.options,options || {}); - this.container.addClassName(this.options.classNames.inactive); - this.active = false; - }, - setProgress: function(value){ - this.progress = value; - this.draw(); - if(this.progress >= 100) - this.stop(false); - this.notify('afterChange',this.progress,this.active); - }, - poll: function(url,interval){ - this.active = true; - this.poller = new PeriodicalExecuter(function(){ - new Ajax.Request(url,{ - onSuccess: function(request){ - this.setProgress(parseInt(request.responseText)); - if(!this.active) - this.poller.stop(); - }.bind(this) - }); - }.bind(this),interval || 3); - }, - start: function(){ - this.active = true; - this.container.removeClassName(this.options.classNames.inactive); - this.container.addClassName(this.options.classNames.active); - this.executer = new PeriodicalExecuter(this.step.bind(this,this.options.step),this.options.interval); - }, - stop: function(reset){ - this.active = false; - if(this.executer) - this.executer.stop(); - this.container.removeClassName(this.options.classNames.active); - this.container.addClassName(this.options.classNames.inactive); - if(typeof(reset) == 'undefined' || reset == true) - this.reset(); - }, - step: function(amount){ - this.active = true; - this.setProgress(Math.min(100,this.progress + amount)); - }, - reset: function(){ - this.active = false; - this.setProgress(0); - }, - draw: function(){ - this.progressContainer.setStyle({ - width: (this.containerWidth - Math.floor((this.progress / 100) * this.containerWidth)) + 'px' - }); - }, - notify: function(event_name){ - if(this.options[event_name]) - return [this.options[event_name].apply(this.options[event_name],$A(arguments).slice(1))]; - } -}); -if(typeof(Object.Event) != 'undefined') - Object.Event.extend(Control.ProgressBar); \ No newline at end of file diff --git a/public/javascripts/control.tabs.js b/public/javascripts/control.tabs.js deleted file mode 100644 index ec69bc4..0000000 --- a/public/javascripts/control.tabs.js +++ /dev/null @@ -1,159 +0,0 @@ -/** - * @author Ryan Johnson - * @copyright 2007 LivePipe LLC - * @package Control.Tabs - * @license MIT - * @url http://livepipe.net/projects/control_tabs/ - * @version 2.1.1 - */ - -if(typeof(Control) == 'undefined') - var Control = {}; -Control.Tabs = Class.create(); -Object.extend(Control.Tabs,{ - instances: [], - findByTabId: function(id){ - return Control.Tabs.instances.find(function(tab){ - return tab.links.find(function(link){ - return link.key == id; - }); - }); - } -}); -Object.extend(Control.Tabs.prototype,{ - initialize: function(tab_list_container,options){ - this.activeContainer = false; - this.activeLink = false; - this.containers = $H({}); - this.links = []; - Control.Tabs.instances.push(this); - this.options = { - beforeChange: Prototype.emptyFunction, - afterChange: Prototype.emptyFunction, - hover: false, - linkSelector: 'li a', - setClassOnContainer: false, - activeClassName: 'active', - defaultTab: 'first', - autoLinkExternal: true, - targetRegExp: /#(.+)$/, - showFunction: Element.show, - hideFunction: Element.hide - }; - Object.extend(this.options,options || {}); - (typeof(this.options.linkSelector == 'string') - ? $(tab_list_container).getElementsBySelector(this.options.linkSelector) - : this.options.linkSelector($(tab_list_container)) - ).findAll(function(link){ - return (/^#/).exec(link.href.replace(window.location.href.split('#')[0],'')); - }).each(function(link){ - this.addTab(link); - }.bind(this)); - this.containers.values().each(this.options.hideFunction); - if(this.options.defaultTab == 'first') - this.setActiveTab(this.links.first()); - else if(this.options.defaultTab == 'last') - this.setActiveTab(this.links.last()); - else - this.setActiveTab(this.options.defaultTab); - var targets = this.options.targetRegExp.exec(window.location); - if(targets && targets[1]){ - targets[1].split(',').each(function(target){ - this.links.each(function(target,link){ - if(link.key == target){ - this.setActiveTab(link); - throw $break; - } - }.bind(this,target)); - }.bind(this)); - } - if(this.options.autoLinkExternal){ - $A(document.getElementsByTagName('a')).each(function(a){ - if(!this.links.include(a)){ - var clean_href = a.href.replace(window.location.href.split('#')[0],''); - if(clean_href.substring(0,1) == '#'){ - if(this.containers.keys().include(clean_href.substring(1))){ - $(a).observe('click',function(event,clean_href){ - this.setActiveTab(clean_href.substring(1)); - }.bindAsEventListener(this,clean_href)); - } - } - } - }.bind(this)); - } - }, - addTab: function(link){ - this.links.push(link); - link.key = link.getAttribute('href').replace(window.location.href.split('#')[0],'').split('/').last().replace(/#/,''); - this.containers[link.key] = $(link.key); - link[this.options.hover ? 'onmouseover' : 'onclick'] = function(link){ - if(window.event) - Event.stop(window.event); - this.setActiveTab(link); - return false; - }.bind(this,link); - }, - setActiveTab: function(link){ - if(!link) - return; - if(typeof(link) == 'string'){ - this.links.each(function(_link){ - if(_link.key == link){ - this.setActiveTab(_link); - throw $break; - } - }.bind(this)); - }else{ - this.notify('beforeChange',this.activeContainer); - if(this.activeContainer) - this.options.hideFunction(this.activeContainer); - this.links.each(function(item){ - (this.options.setClassOnContainer ? $(item.parentNode) : item).removeClassName(this.options.activeClassName); - }.bind(this)); - (this.options.setClassOnContainer ? $(link.parentNode) : link).addClassName(this.options.activeClassName); - this.activeContainer = this.containers[link.key]; - this.activeLink = link; - this.options.showFunction(this.containers[link.key]); - this.notify('afterChange',this.containers[link.key]); - } - }, - next: function(){ - this.links.each(function(link,i){ - if(this.activeLink == link && this.links[i + 1]){ - this.setActiveTab(this.links[i + 1]); - throw $break; - } - }.bind(this)); - return false; - }, - previous: function(){ - this.links.each(function(link,i){ - if(this.activeLink == link && this.links[i - 1]){ - this.setActiveTab(this.links[i - 1]); - throw $break; - } - }.bind(this)); - return false; - }, - first: function(){ - this.setActiveTab(this.links.first()); - return false; - }, - last: function(){ - this.setActiveTab(this.links.last()); - return false; - }, - notify: function(event_name){ - try{ - if(this.options[event_name]) - return [this.options[event_name].apply(this.options[event_name],$A(arguments).slice(1))]; - }catch(e){ - if(e != $break) - throw e; - else - return false; - } - } -}); -if(typeof(Object.Event) != 'undefined') - Object.Event.extend(Control.Tabs); \ No newline at end of file diff --git a/public/javascripts/control.textarea.js b/public/javascripts/control.textarea.js deleted file mode 100644 index 0a25af0..0000000 --- a/public/javascripts/control.textarea.js +++ /dev/null @@ -1,118 +0,0 @@ -/** - * @author Ryan Johnson - * @copyright 2007 LivePipe LLC - * @package Control.TextArea - * @license MIT - * @url http://livepipe.net/projects/control_textarea/ - * @version 2.0.1 - */ - -if(typeof(Control) == 'undefined') - Control = {}; -Control.TextArea = Class.create(); -Object.extend(Control.TextArea.prototype,{ - onChangeTimeoutLength: 500, - element: false, - onChangeTimeout: false, - initialize: function(textarea){ - this.element = $(textarea); - $(this.element).observe('keyup',this.doOnChange.bindAsEventListener(this)); - $(this.element).observe('paste',this.doOnChange.bindAsEventListener(this)); - $(this.element).observe('input',this.doOnChange.bindAsEventListener(this)); - if(!!document.selection){ - $(this.element).observe('mouseup',this.saveRange.bindAsEventListener(this)); - $(this.element).observe('keyup',this.saveRange.bindAsEventListener(this)); - } - }, - doOnChange: function(event){ - if(this.onChangeTimeout) - window.clearTimeout(this.onChangeTimeout); - this.onChangeTimeout = window.setTimeout(function(){ - if(this.notify) - this.notify('change',this.getValue()); - }.bind(this),this.onChangeTimeoutLength); - }, - saveRange: function(){ - this.range = document.selection.createRange(); - }, - getValue: function(){ - return this.element.value; - }, - getSelection: function(){ - if(!!document.selection) - return document.selection.createRange().text; - else if(!!this.element.setSelectionRange) - return this.element.value.substring(this.element.selectionStart,this.element.selectionEnd); - else - return false; - }, - replaceSelection: function(text){ - var scroll_top = this.element.scrollTop; - if(!!document.selection){ - this.element.focus(); - var range = (this.range) ? this.range : document.selection.createRange(); - range.text = text; - range.select(); - }else if(!!this.element.setSelectionRange){ - var selection_start = this.element.selectionStart; - this.element.value = this.element.value.substring(0,selection_start) + text + this.element.value.substring(this.element.selectionEnd); - this.element.setSelectionRange(selection_start + text.length,selection_start + text.length); - } - this.doOnChange(); - this.element.focus(); - this.element.scrollTop = scroll_top; - }, - wrapSelection: function(before,after){ - this.replaceSelection(before + this.getSelection() + after); - }, - insertBeforeSelection: function(text){ - this.replaceSelection(text + this.getSelection()); - }, - insertAfterSelection: function(text){ - this.replaceSelection(this.getSelection() + text); - }, - injectEachSelectedLine: function(callback,before,after){ - this.replaceSelection((before || '') + $A(this.getSelection().split("\n")).inject([],callback).join("\n") + (after || '')); - }, - insertBeforeEachSelectedLine: function(text,before,after){ - this.injectEachSelectedLine(function(lines,line){ - lines.push(text + line); - return lines; - },before,after); - } -}); -if(typeof(Object.Event) != 'undefined') - Object.Event.extend(Control.TextArea); - -Control.TextArea.ToolBar = Class.create(); -Object.extend(Control.TextArea.ToolBar.prototype,{ - textarea: false, - container: false, - initialize: function(textarea,toolbar){ - this.textarea = textarea; - if(toolbar) - this.container = $(toolbar); - else{ - this.container = $(document.createElement('ul')); - this.textarea.element.parentNode.insertBefore(this.container,this.textarea.element); - } - }, - attachButton: function(node,callback){ - node.onclick = function(){return false;} - $(node).observe('click',callback.bindAsEventListener(this.textarea)); - }, - addButton: function(link_text,callback,attrs){ - var li = document.createElement('li'); - var a = document.createElement('a'); - a.href = '#'; - this.attachButton(a,callback); - li.appendChild(a); - Object.extend(a,attrs || {}); - if(link_text){ - var span = document.createElement('span'); - span.innerHTML = link_text; - a.appendChild(span); - } - this.container.appendChild(li); - } -}); \ No newline at end of file