web/rsln-opendata/res/metadataplayer/test/interface 1.2/source/ittabs.js
changeset 66 8a382087127f
equal deleted inserted replaced
65:e93dd6da4c6d 66:8a382087127f
       
     1 /**
       
     2  * Interface Elements for jQuery
       
     3  * TTabs
       
     4  * 
       
     5  * http://interface.eyecon.ro
       
     6  * 
       
     7  * Copyright (c) 2006 Stefan Petre
       
     8  * Dual licensed under the MIT (MIT-LICENSE.txt) 
       
     9  * and GPL (GPL-LICENSE.txt) licenses.
       
    10  *   
       
    11  *
       
    12  *
       
    13  */
       
    14 
       
    15 jQuery.iTTabs =
       
    16 {
       
    17 	doTab : function(e)
       
    18 	{
       
    19 		pressedKey = e.charCode || e.keyCode || -1;
       
    20 		if (pressedKey == 9) {
       
    21 			if (window.event) {
       
    22 				window.event.cancelBubble = true;
       
    23 				window.event.returnValue = false;
       
    24 			} else {
       
    25 				e.preventDefault();
       
    26 				e.stopPropagation();
       
    27 			}
       
    28 			if (this.createTextRange) {
       
    29 				document.selection.createRange().text="\t";
       
    30 				this.onblur = function() { this.focus(); this.onblur = null; };
       
    31 			} else if (this.setSelectionRange) {
       
    32 				start = this.selectionStart;
       
    33 				end = this.selectionEnd;
       
    34 				this.value = this.value.substring(0, start) + "\t" + this.value.substr(end);
       
    35 				this.setSelectionRange(start + 1, start + 1);
       
    36 				this.focus();
       
    37 			}
       
    38 			return false;
       
    39 		}
       
    40 	},
       
    41 	destroy : function()
       
    42 	{
       
    43 		return this.each(
       
    44 			function()
       
    45 			{
       
    46 				if (this.hasTabsEnabled && this.hasTabsEnabled == true) {
       
    47 					jQuery(this).unbind('keydown', jQuery.iTTabs.doTab);
       
    48 					this.hasTabsEnabled = false;
       
    49 				}
       
    50 			}
       
    51 		);
       
    52 	},
       
    53 	build : function()
       
    54 	{
       
    55 		return this.each(
       
    56 			function()
       
    57 			{
       
    58 				if (this.tagName == 'TEXTAREA' && (!this.hasTabsEnabled || this.hasTabsEnabled == false)) {
       
    59 					jQuery(this).bind('keydown', jQuery.iTTabs.doTab);
       
    60 					this.hasTabsEnabled = true;
       
    61 				}
       
    62 			}
       
    63 		);			
       
    64 	}
       
    65 };
       
    66 
       
    67 jQuery.fn.extend (
       
    68 	{
       
    69 		/**
       
    70 		 * Enable tabs in textareas
       
    71 		 * 
       
    72 		 * @name EnableTabs
       
    73 		 * @description Enable tabs in textareas
       
    74 		 *
       
    75 		 * @type jQuery
       
    76 		 * @cat Plugins/Interface
       
    77 		 * @author Stefan Petre
       
    78 		 */
       
    79 		EnableTabs : jQuery.iTTabs.build,
       
    80 		/**
       
    81 		 * Disable tabs in textareas
       
    82 		 * 
       
    83 		 * @name DisableTabs
       
    84 		 * @description Disable tabs in textareas
       
    85 		 *
       
    86 		 * @type jQuery
       
    87 		 * @cat Plugins/Interface
       
    88 		 * @author Stefan Petre
       
    89 		 */
       
    90 		DisableTabs : jQuery.iTTabs.destroy
       
    91 	}
       
    92 );