Skip to content
Browse files

first commit

  • Loading branch information...
1 parent 92c79e7 commit 1be679899a5d8f882a15572aed83a64d9dbdc89a @petejkim committed Apr 14, 2009
Showing with 6,407 additions and 0 deletions.
  1. +22 −0 MIT-LICENSE.txt
  2. +7 −0 README
  3. +257 −0 socks.common.js
  4. +89 −0 socks.element.control.button.js
  5. +76 −0 socks.element.control.check.js
  6. +89 −0 socks.element.control.editbox.js
  7. +77 −0 socks.element.control.editline.js
  8. +91 −0 socks.element.control.image.js
  9. +138 −0 socks.element.control.js
  10. +153 −0 socks.element.control.listbox.js
  11. +117 −0 socks.element.control.progress.js
  12. +105 −0 socks.element.control.radio.js
  13. +65 −0 socks.element.html.js
  14. +691 −0 socks.element.js
  15. +38 −0 socks.element.textblock.banner.js
  16. +38 −0 socks.element.textblock.caption.js
  17. +38 −0 socks.element.textblock.inscription.js
  18. +109 −0 socks.element.textblock.js
  19. +38 −0 socks.element.textblock.para.js
  20. +38 −0 socks.element.textblock.subtitle.js
  21. +38 −0 socks.element.textblock.tagline.js
  22. +38 −0 socks.element.textblock.title.js
  23. +45 −0 socks.element.textfragment.br.js
  24. +38 −0 socks.element.textfragment.code.js
  25. +38 −0 socks.element.textfragment.del.js
  26. +38 −0 socks.element.textfragment.em.js
  27. +38 −0 socks.element.textfragment.ins.js
  28. +49 −0 socks.element.textfragment.js
  29. +124 −0 socks.element.textfragment.link.js
  30. +38 −0 socks.element.textfragment.span.js
  31. +38 −0 socks.element.textfragment.strong.js
  32. +38 −0 socks.element.textfragment.sub.js
  33. +38 −0 socks.element.textfragment.sup.js
  34. +145 −0 socks.event.js
  35. +631 −0 socks.init.js
  36. +26 −0 socks.js
  37. +116 −0 socks.slot.app.js
  38. +468 −0 socks.slot.canvas.js
  39. +25 −0 socks.slot.flow.js
  40. +797 −0 socks.slot.js
  41. +25 −0 socks.slot.stack.js
  42. +1,146 −0 socks.style.js
  43. +24 −0 socks.timer.animate.js
  44. +57 −0 socks.timer.every.js
  45. +73 −0 socks.timer.js
View
22 MIT-LICENSE.txt
@@ -0,0 +1,22 @@
+Copyright (c) 2009 Peter Jihoon Kim
+
+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.
View
7 README
@@ -0,0 +1,7 @@
+Socks 0.7 (Armadillo)
+
+Copyright (c) 2009 Peter Jihoon Kim
+
+Licensed under the MIT License (MIT-LICENSE.txt)
+
+http://wiki.github.com/petejkim/socks
View
257 socks.common.js
@@ -0,0 +1,257 @@
+/*
+ * Socks .Common
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ Socks.Common = (function(){
+ return {
+ // transforms keycode to string
+ keyCodeToString : function(keyCode) {
+ switch(keyCode) {
+ case 8: return 'backspace';
+ case 9: return 'tab';
+ case 13: return 'enter';
+ case 16: return 'shift';
+ case 17: return 'control';
+ case 18: return 'alt';
+ case 19: return 'break';
+ case 20: return 'capslock';
+ case 27: return 'escape';
+ case 33: return 'pageup';
+ case 34: return 'pagedown';
+ case 35: return 'end';
+ case 36: return 'home';
+ case 37: return 'left';
+ case 38: return 'up';
+ case 39: return 'right';
+ case 40: return 'down';
+ case 45: return 'insert';
+ case 46: return 'delete';
+ case 48: return '0';
+ case 49: return '1';
+ case 50: return '2';
+ case 51: return '3';
+ case 52: return '4';
+ case 53: return '5';
+ case 54: return '6';
+ case 55: return '7';
+ case 56: return '8';
+ case 57: return '9';
+ case 61: return '=';
+ case 65: return 'a';
+ case 66: return 'b';
+ case 67: return 'c';
+ case 68: return 'd';
+ case 69: return 'e';
+ case 70: return 'f';
+ case 71: return 'g';
+ case 72: return 'h';
+ case 73: return 'i';
+ case 74: return 'j';
+ case 75: return 'k';
+ case 76: return 'l';
+ case 77: return 'm';
+ case 78: return 'n';
+ case 79: return 'o';
+ case 80: return 'p';
+ case 81: return 'q';
+ case 82: return 'r';
+ case 83: return 's';
+ case 84: return 't';
+ case 85: return 'u';
+ case 86: return 'v';
+ case 87: return 'w';
+ case 88: return 'x';
+ case 89: return 'y';
+ case 90: return 'z';
+ case 96: return 'numpad0';
+ case 97: return 'numpad1';
+ case 98: return 'numpad2';
+ case 99: return 'numpad3';
+ case 100: return 'numpad4';
+ case 101: return 'numpad5';
+ case 102: return 'numpad6';
+ case 103: return 'numpad7';
+ case 104: return 'numpad8';
+ case 105: return 'numpad9';
+ case 106: return '*';
+ case 107: return '+';
+ case 109: return '-';
+ case 110: return '.';
+ case 111: return '/';
+ case 112: return 'f1';
+ case 113: return 'f2';
+ case 114: return 'f3';
+ case 115: return 'f4';
+ case 116: return 'f5';
+ case 117: return 'f6';
+ case 118: return 'f7';
+ case 119: return 'f8';
+ case 120: return 'f9';
+ case 121: return 'f10';
+ case 122: return 'f11';
+ case 123: return 'f12';
+ case 144: return 'numlock';
+ case 145: return 'scrolllock';
+ case 186: return ';';
+ case 187: return '=';
+ case 188: return ',';
+ case 189: return '-';
+ case 190: return '.';
+ case 191: return '/';
+ case 192: return '`';
+ case 219: return '[';
+ case 220: return "\\";
+ case 221: return ']';
+ case 222: return "'";
+ }
+ return String.fromCharCode(keyCode).toLowerCase();
+ },
+
+ // gets rid of whitespaces in the beginning and the end of the string
+ trim : function(str) {
+ return str.replace(/^\s\s*/,'').replace(/\s\s*$/,'');
+ },
+
+ // create clearfix div at the end of the element
+ insertClearDiv : function(el) {
+ var clearDiv = document.createElement('div');
+ clearDiv.style.clear = 'both';
+ el.appendChild(clearDiv);
+ return el;
+ },
+
+ // look for socks element in the array
+ findElement : function(arr) {
+ var el;
+ if(arr.length > 0) {
+ for(var i=0; i<arr.length; i++) {
+ if(arr[i] instanceof Socks.Element || arr[i] instanceof Socks.Slot) {
+ el=arr[i];
+ break;
+ }
+ }
+ }
+ return el;
+ },
+
+ // look for function in the array
+ findFunction : function(arr) {
+ var fun;
+ if(arr.length > 0) {
+ for(var i=0; i<arr.length; i++) {
+ if(Socks.Common.type(arr[i]) === 'Function') {
+ fun=arr[i];
+ break;
+ }
+ }
+ }
+ return fun;
+ },
+
+ // get type of an object
+ type : function(obj) {
+ var t;
+ if(typeof obj === 'object') {
+ Array.prototype._socks_type = 'Array';
+ Boolean.prototype._socks_type = 'Boolean';
+ Date.prototype._socks_type = 'Date';
+ Function.prototype._socks_type = 'Function';
+ Number.prototype._socks_type = 'Number';
+ RegExp.prototype._socks_type = 'RegExp';
+ String.prototype._socks_type = 'String';
+
+ if(obj._socks_type !== undefined) {
+ t = obj._socks_type;
+ } else {
+ t = 'Object';
+ }
+
+ delete Array.prototype._socks_type;
+ delete Boolean.prototype._socks_type;
+ delete Date.prototype._socks_type;
+ delete Function.prototype._socks_type;
+ delete Number.prototype._socks_type;
+ delete RegExp.prototype._socks_type;
+ delete String.prototype._socks_type;
+
+ return t;
+ } else {
+ t = typeof obj;
+ return t.charAt(0).toUpperCase()+t.substring(1);
+ }
+ },
+
+ toBoolean : function(obj) {
+ var b;
+ if(typeof obj === 'boolean') {
+ return obj;
+ } else {
+ Boolean.prototype._socks_to_b = function() { return this.valueOf(); };
+ Number.prototype._socks_to_b = function() { return (this.valueOf() !== 0 ? true : false); };
+ String.prototype._socks_to_b = function() { return (this.toLowerCase() === 'true' ? true : false); };
+
+ if(obj._socks_to_b !== undefined) {
+ b = obj._socks_to_b();
+ } else {
+ b = false;
+ }
+
+ delete Boolean.prototype._socks_to_b;
+ delete Number.prototype._socks_to_b;
+ delete String.prototype._socks_to_b;
+
+ return b;
+ }
+ },
+
+ first : function(arr,num) {
+ if(num === undefined || num === 1) {
+ return arr[0];
+ }
+
+ var newArray=[];
+
+ for(var i=0; i<num; i++){
+ if(arr[i] === undefined) {
+ break;
+ } else {
+ newArray.push(arr[i]);
+ }
+ }
+
+ return newArray;
+ },
+
+ map : function(arr,fun) {
+ var newArray=[];
+
+ for(var i=0; i<arr.length; i++) {
+ newArray.push(fun(arr[i]));
+ }
+
+ return newArray;
+ },
+
+ removeItems : function(arr,item) {
+ var newArray=[];
+ for(var i=0; i<arr.length; i++) {
+ if(arr[i] !== item) {
+ newArray.push(arr[i]);
+ }
+ }
+ return newArray;
+ }
+ };
+ })();
+
+})(window.SOCKS);
+
View
89 socks.element.control.button.js
@@ -0,0 +1,89 @@
+/*
+ * Socks .Element.Control.Button
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ var type = Socks.Common.type;
+
+ Socks.Element.Control.Button = function(parent, style, text, fun) {
+ this._socks_type = 'Socks.Element.Control.Button';
+ this._elementId = window.Socks._nextElementId++;
+ this._parent = parent;
+ // create style object
+ this._style = new Socks.Style();
+
+ // set the text
+ if(text !== undefined) {
+ this._text = text;
+ } else {
+ this._text = 'Button';
+ }
+
+ // create element in the DOM
+ this._createElement();
+
+ // set the default event type
+ this._defaultEventType = "click";
+
+ // set the default event
+ if(fun !== undefined) {
+ this.setFunction(fun); // sets this
+ }
+
+ // set styles
+ this.setStyle(style);
+ };
+
+ Socks.Element.Control.Button.prototype = new Socks.Element.Control();
+
+ Socks.Element.Control.Button.prototype._createElement = function() {
+ if(this._element === undefined) {
+ this._element = document.createElement('input');
+ this._element.type = 'submit';
+ this._element.value = this._text;
+ this._element.style.zIndex = 1;
+
+ this.setStyle({fontSize:11,margin:0,padding:0});
+ // set layout related styles
+ this._setLayout();
+ // insert the element into the parent
+ if(!window.Socks.msie) {
+ this._insertIntoParent(this._element);
+ } else {
+ // ie margin inheritance bug
+ var wrapperDiv = document.createElement('div');
+ // ie button expansion bug
+ this._element.style.display = 'inline';
+ wrapperDiv.appendChild(this._element);
+ this._insertIntoParent(wrapperDiv);
+ }
+ } else {
+ this._element.value = this._text;
+ this.setStyle(this.getStyle());
+ }
+ return this._element;
+ };
+
+ Socks.Element.Control.Button.prototype.getText = function() {
+ return this._text;
+ };
+
+ Socks.Element.Control.Button.prototype.setText = function(text) {
+ this._text = text.toString();
+
+ if(this._element !== undefined) {
+ this._element.value = this._text;
+ }
+ return this;
+ };
+
+})(window.SOCKS);
+
View
76 socks.element.control.check.js
@@ -0,0 +1,76 @@
+/*
+ * Socks .Element.Control.Check
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ var toBoolean = Socks.Common.toBoolean;
+
+ Socks.Element.Control.Check = function(parent, style, fun) {
+ this._socks_type = 'Socks.Element.Control.Check';
+ this._elementId = window.Socks._nextElementId++;
+ this._parent = parent;
+
+ // create style object
+ this._style = new Socks.Style();
+
+ // create element in the DOM
+ this._createElement();
+
+ // set the default event type
+ this._defaultEventType = "click";
+
+ // set the default event
+ if(fun !== undefined) {
+ this.setFunction(fun);
+ }
+
+ //set styles
+ this.setStyle(style);
+ };
+
+ Socks.Element.Control.Check.prototype = new Socks.Element.Control();
+
+ Socks.Element.Control.Check.prototype._createElement = function() {
+ if(this._element === undefined) {
+ this._element = document.createElement('input');
+ this._element.type = 'checkbox';
+ this._element.style.zIndex = 1;
+
+ this.setStyle({margin:0,padding:0});
+
+ // set layout related styles
+ this._setLayout();
+ // insert the element into the parent
+ this._insertIntoParent(this._element);
+ } else {
+ this.setStyle(this.getStyle());
+ }
+ return this._element;
+ };
+
+ Socks.Element.Control.Check.prototype.isSelected = function() {
+ this._selected = this._element.checked;
+ return this._selected;
+ };
+
+ Socks.Element.Control.Check.prototype.setSelected = function(selected) {
+ selected = toBoolean(selected);
+ this._selected = selected;
+
+ if(this._element !== undefined) {
+ this._element.checked = (this._selected ? 'checked' : '');
+ }
+
+ return this;
+ };
+
+})(window.SOCKS);
+
View
89 socks.element.control.editbox.js
@@ -0,0 +1,89 @@
+/*
+ * Socks .Element.Control.EditBox
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ Socks.Element.Control.EditBox = function(parent, style, text, fun) {
+ this._socks_type = 'Socks.Element.Control.EditBox';
+ this._elementId = window.Socks._nextElementId++;
+ this._parent = parent;
+
+ // create style object
+ this._style = new Socks.Style();
+
+ // set the text
+ if(text !== undefined) {
+ this._text = text;
+ } else {
+ this._text = '';
+ }
+
+ // create element in the DOM
+ this._createElement();
+
+ // set the default event type
+ this._defaultEventType = "change";
+
+ // set the default event
+ if(fun !== undefined) {
+ this.setFunction(fun); // sets this
+ }
+
+ //set styles
+ this.setStyle(style);
+ };
+
+ Socks.Element.Control.EditBox.prototype = new Socks.Element.Control();
+
+ Socks.Element.Control.EditBox.prototype._createElement = function() {
+ if(this._element === undefined) {
+ this._element = document.createElement('textarea');
+ this._element.value = this._text;
+ this._element.style.zIndex = 1;
+
+ this.setStyle({fontFamily:'sans-serif',fontSize:12,padding:0,margin:0});
+
+ // set layout related styles
+ this._setLayout();
+ // insert the element into the parent
+ if(!window.Socks.msie) {
+ this._insertIntoParent(this._element);
+ } else {
+ // ie margin inheritance bug
+ var wrapperDiv = document.createElement('div');
+ wrapperDiv.appendChild(this._element);
+ this._insertIntoParent(wrapperDiv);
+ }
+ } else {
+ this._element.value = this._text;
+ this.setStyle(this.getStyle());
+ }
+ return this._element;
+ };
+
+ Socks.Element.Control.EditBox.prototype.getText = function() {
+ if(this._element !== undefined) {
+ this._text = this._element.value;
+ }
+ return this._text;
+ };
+
+ Socks.Element.Control.EditBox.prototype.setText = function(text) {
+ this._text = text.toString();
+
+ if(this._element !== undefined) {
+ this._element.value = this._text;
+ }
+ return this;
+ };
+
+})(window.SOCKS);
+
View
77 socks.element.control.editline.js
@@ -0,0 +1,77 @@
+/*
+ * Socks .Element.Control.EditLine
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ Socks.Element.Control.EditLine = function(parent, style, text, fun) {
+ this._socks_type = 'Socks.Element.Control.EditLine';
+ this._elementId = window.Socks._nextElementId++;
+ this._parent = parent;
+
+ // create style object
+ this._style = new Socks.Style();
+
+ // set the text
+ if(text !== undefined) {
+ this._text = text;
+ } else {
+ this._text = '';
+ }
+
+ // create element in the DOM
+ this._createElement();
+
+ // set the default event type
+ this._defaultEventType = "change";
+
+ // set the default event
+ if(fun !== undefined) {
+ this.setFunction(fun); // sets this
+ }
+
+ //set styles
+ this.setStyle(style);
+ };
+
+ Socks.Element.Control.EditLine.prototype = new Socks.Element.Control();
+
+ Socks.Element.Control.EditLine.prototype._createElement = function() {
+ if(this._element === undefined) {
+ this._element = document.createElement('input');
+ this._element.type = 'text';
+ this._element.value = this._text;
+ this._element.style.zIndex = 1;
+
+ this.setStyle({fontFamily:'sans-serif',fontSize:12,padding:0,margin:0});
+
+ // set layout related styles
+ this._setLayout();
+ // insert the element into the parent
+ if(!window.Socks.msie) {
+ this._insertIntoParent(this._element);
+ } else {
+ // ie margin inheritance bug
+ var wrapperDiv = document.createElement('div');
+ wrapperDiv.appendChild(this._element);
+ this._insertIntoParent(wrapperDiv);
+ }
+ } else {
+ this._element.value = this._text;
+ this.setStyle(this.getStyle());
+ }
+ return this._element;
+ };
+
+ Socks.Element.Control.EditLine.prototype.getText = Socks.Element.Control.EditBox.prototype.getText;
+ Socks.Element.Control.EditLine.prototype.setText = Socks.Element.Control.EditBox.prototype.setText;
+
+})(window.SOCKS);
+
View
91 socks.element.control.image.js
@@ -0,0 +1,91 @@
+/*
+ * Socks .Element.Control.Image
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ var type = Socks.Common.type;
+
+ Socks.Element.Control.Image = function(parent, style, image, text, fun) {
+ this._socks_type = 'Socks.Element.Control.Image';
+ this._elementId = window.Socks._nextElementId++;
+ this._parent = parent;
+
+ // create style object
+ this._style = new Socks.Style();
+
+ // image URI
+ this._image = (image !== undefined ? image : '');
+
+ // alternative text
+ this._text = (text !== undefined ? text : '');
+
+ // create element in the DOM
+ this._createElement();
+
+ // set the default event type
+ this._defaultEventType = "click";
+
+ // set the default event
+ if(fun !== undefined) {
+ this.setFunction(fun); // sets this
+ }
+
+ // set styles
+ this.setStyle(style);
+ };
+
+ Socks.Element.Control.Image.prototype = new Socks.Element.Control();
+
+ Socks.Element.Control.Image.prototype._createElement = function() {
+ if(this._element === undefined) {
+ this._element = document.createElement('img');
+ this._element.src = this._image;
+ this._element.alt = this._text;
+ this._element.style.zIndex = 1;
+
+ this.setStyle({margin:0,padding:0});
+
+ // set layout related styles
+ this._setLayout();
+ // insert the element into the parent
+ this._insertIntoParent(this._element);
+ } else {
+ this._element.src = this._image;
+ this._element.alt = this._text;
+ this.setStyle(this.getStyle());
+ }
+ return this._element;
+ };
+
+
+ Socks.Element.Control.Image.prototype.getImage = function() {
+ return this._text;
+ };
+
+ Socks.Element.Control.Image.prototype.setImage = function(image) {
+ this._image = image.toString();
+
+ if(this._element !== undefined) {
+ this._element.value = this._text;
+ }
+ return this;
+ };
+
+ Socks.Element.Control.Image.prototype.getText = Socks.Element.Control.Button.prototype.getText;
+ Socks.Element.Control.Image.prototype.setText = Socks.Element.Control.Button.prototype.setText;
+ Socks.Element.Control.Image.prototype.setDisabled =
+ Socks.Element.Control.Image.prototype.focus =
+ Socks.Element.Control.Image.prototype.blur = function() {
+ return this;
+ };
+
+})(window.SOCKS);
+
View
138 socks.element.control.js
@@ -0,0 +1,138 @@
+/*
+ * Socks .Element.Control
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ var toBoolean = Socks.Common.toBoolean;
+ var type = Socks.Common.type;
+
+ Socks.Element.Control = function() {
+ this._socks_type = 'Socks.Element.Control';
+ };
+
+ Socks.Element.Control.prototype = new Socks.Element();
+
+ Socks.Element.Control.prototype.isDisabled = function() {
+ if('_disabled' in this) {
+ return this._disabled;
+ } else {
+ return false;
+ }
+ };
+
+ Socks.Element.Control.prototype.setDisabled = function(disabled) {
+ disabled = toBoolean(disabled);
+ this._disabled = disabled;
+
+ if(this._element !== undefined) {
+ this._element.disabled = (this._disabled ? 'disabled' : '');
+ }
+ return this;
+ };
+
+ Socks.Element.Control.prototype.disable = function() {
+ return this.setDisabled(true);
+ };
+
+ Socks.Element.Control.prototype.enable = function() {
+ return this.setDisabled(false);
+ };
+
+ Socks.Element.Control.prototype.focus = function(){
+ if(this._element !== undefined) {
+ this._element.focus();
+ }
+ return this;
+ };
+
+ Socks.Element.Control.prototype.blur = function(){
+ if(this._element !== undefined) {
+ this._element.blur();
+ }
+ return this;
+ };
+
+ //------------------------------------------------------
+ // Events
+
+ // gets the default event's function
+ Socks.Element.Control.prototype.getFunction = function() {
+ if(this._events !== undefined) {
+ var defaultEvent = this._events[this._defaultEventType];
+
+ if(defaultEvent !== undefined) {
+ return defaultEvent.getFunction();
+ }
+ }
+ return null;
+ };
+
+ // sets the default event's function
+ Socks.Element.Control.prototype.setFunction = function(fun) {
+ if(this._events === undefined) {
+ this._events = {};
+ }
+ var defaultEvent = this._events[this._defaultEventType];
+
+ if(defaultEvent !== undefined) {
+ defaultEvent.setFunction(fun); // set function
+ defaultEvent.addListener(); // re-add event listener
+ } else {
+ this._events[this._defaultEventType] = this.addEvent(this._defaultEventType, fun);
+ }
+ return this;
+ };
+
+ Socks.Element.Control.prototype._onKeyAction = function(eventType, args) {
+ var preventDefault = false;
+ var stopPropagation = true;
+ var fun;
+ eventType = eventType || 'keydown';
+
+ for(var i=0; i<args.length; i++) {
+ var arg = args[i];
+ switch(type(arg)) {
+ case 'Object':
+ if('preventDefault' in arg) {
+ preventDefault = arg.preventDefault;
+ }
+ if('stopPropagation' in arg) {
+ stopPropagation = arg.stopPropagation;
+ }
+ break;
+ case 'Function':
+ fun = arg;
+ }
+ }
+
+ if(fun !== undefined) {
+ var funWrapper = function(e) {
+ var key = Socks.Common.keyCodeToString(e.keyCode);
+ fun.call(this, key, e);
+ };
+
+ return this.addEvent({type:eventType, preventDefault:preventDefault, stopPropagation:stopPropagation}, funWrapper);
+ }
+ return null;
+ };
+
+ Socks.Element.Control.prototype.onKeyDown = function() {
+ // onKeyDown { |key, e| }
+ return this._onKeyAction('keydown',arguments);
+ };
+
+ Socks.Element.Control.prototype.onKeyUp = function() {
+ // onKeyUp { |key, e| }
+ return this._onKeyAction('keyup',arguments);
+ };
+
+})(window.SOCKS);
+
View
153 socks.element.control.listbox.js
@@ -0,0 +1,153 @@
+/*
+ * Socks .Element.Control.ListBox
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ var type = Socks.Common.type;
+
+ Socks.Element.Control.ListBox = function(parent, style, array, text, fun) {
+ this._socks_type = 'Socks.Element.Control.ListBox';
+ this._elementId = window.Socks._nextElementId++;
+ this._parent = parent;
+
+ // create style object
+ this._style = new Socks.Style();
+
+ // set the listbox contents
+ if(array !== undefined) {
+ this._contents = array;
+ } else {
+ this._contents = [];
+ }
+
+ // set the text
+ if(text !== undefined) {
+ this._default = text;
+ }
+
+ // create element in the DOM
+ this._createElement();
+
+ // set the default event type
+ this._defaultEventType = "change";
+
+ // set the default event
+ if(fun !== undefined) {
+ this.setFunction(fun); // sets this
+ }
+
+ //set styles
+ this.setStyle(style);
+ };
+
+ Socks.Element.Control.ListBox.prototype = new Socks.Element.Control();
+
+ Socks.Element.Control.ListBox.prototype._createChildNodes = function() {
+ if(this._element !== undefined) {
+ //remove all childnodes
+ while(this._element.firstChild) {
+ this._element.removeChild(this._element.firstChild);
+ }
+
+ for(var i=0; i<this._contents.length; i++) {
+ var optionElement;
+ switch(type(this._contents[i])) {
+ case 'String': // option
+ // create option element and append it
+ optionElement = document.createElement('option');
+ optionElement.appendChild(document.createTextNode(this._contents[i]));
+ optionElement.value = this._contents[i];
+ if(this._contents[i] === this._default) {
+ optionElement.selected = 'selected';
+ }
+ this._element.appendChild(optionElement);
+ break;
+ case 'Array': // option groups
+ if(this._contents[i].length > 0 && type(this._contents[i][0]) === 'String') {
+ // create option group element
+ var optGroupElement = document.createElement('optgroup');
+ // set option group label
+ optGroupElement.label = this._contents[i][0];
+ // options within the group
+ for(var j=1; j<this._contents[i].length; j++) {
+ if(type(this._contents[i][j]) === 'String') {
+ // create option element and append it
+ optionElement = document.createElement('option');
+ optionElement.appendChild(document.createTextNode(this._contents[i][j]));
+ optionElement.value = this._contents[i][j];
+ if(this._contents[i][j] === this._default) {
+ optionElement.selected = 'selected';
+ }
+ optGroupElement.appendChild(optionElement);
+ } else {
+ // remove item if not applicable
+ this._contents[i].splice(j,1);
+ j--;
+ }
+ }
+ //append option group element
+ this._element.appendChild(optGroupElement);
+ }
+ break;
+ default:
+ // remove item if not applicable
+ this._contents.splice(i,1);
+ i--;
+ }
+ }
+ }
+ return this._element;
+ };
+
+ Socks.Element.Control.ListBox.prototype._createElement = function() {
+ if(this._element === undefined) {
+ this._element = document.createElement('select');
+ this._element.style.zIndex = 1;
+
+ this._createChildNodes();
+
+ this.setStyle({fontSize:11,margin:0,padding:0});
+
+ // set layout related styles
+ this._setLayout();
+ // insert the element into the parent
+ if(!window.Socks.msie) {
+ this._insertIntoParent(this._element);
+ } else {
+ // ie margin inheritance bug
+ var wrapperDiv = document.createElement('div');
+ wrapperDiv.appendChild(this._element);
+ this._insertIntoParent(wrapperDiv);
+ }
+ } else {
+ this.setStyle(this.getStyle());
+ }
+ return this._element;
+ };
+
+ Socks.Element.Control.ListBox.prototype.getSelected = function() {
+ if(this._element !== undefined) {
+ return this._element.value;
+ }
+ return null;
+ };
+
+ Socks.Element.Control.ListBox.prototype.setSelected = function(name) {
+ name = name.toString();
+
+ if(this._element !== undefined) {
+ this._element.value = name;
+ }
+ return this;
+ };
+
+})(window.SOCKS);
+
View
117 socks.element.control.progress.js
@@ -0,0 +1,117 @@
+/*
+ * Socks .Element.Control.Progress
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ var type = Socks.Common.type;
+
+ Socks.Element.Control.Progress = function(parent, style) {
+ this._socks_type = 'Socks.Element.Control.Progress';
+ this._elementId = window.Socks._nextElementId++;
+ this._parent = parent;
+
+ // create style object
+ this._style = new Socks.Style();
+
+ // create pseudo 'bar' object
+ this._bar = {};
+
+ // create style object for the bar
+ this._bar._style = new Socks.Style();
+
+ // create element in the DOM
+ this._createElement();
+
+ //set styles
+ this.setStyle(style);
+ };
+
+ Socks.Element.Control.Progress.prototype = new Socks.Element.Control();
+
+ Socks.Element.Control.Progress.prototype._createElement = function() {
+ if(this._element === undefined) {
+ this._element = document.createElement('div');
+
+ this._bar._element = document.createElement('div');
+ this._bar._element.style.display = 'block';
+ this._element.style.zIndex = 1;
+
+ this._element.appendChild(this._bar._element);
+
+ this.setStyle({margin:0,padding:1,width:200,height:10,backgroundColor:'#fff',border:{color:"#999",width:1}});
+ this.setBarStyle({width:0,height:"100%",backgroundColor:'#3875d7'});
+
+ // set layout related styles
+ this._setLayout();
+ // insert the element into the parent
+ this._insertIntoParent(this._element);
+ } else {
+ if('_bar' in this) {
+ this.setBarStyle(this.getBarStyle());
+ this.setBarStyle({width:((this._fraction*100).toString()+'%')});
+ }
+ this.setStyle(this.getStyle());
+ }
+ return this._element;
+ };
+
+ Socks.Element.Control.Progress.prototype.getBarStyle = function() {
+ if('_style' in this._bar) {
+ return this._bar._style;
+ }
+ return {};
+ };
+
+ Socks.Element.Control.Progress.prototype.setBarStyle = function(style) {
+ if(!('_style' in this._bar)) {
+ this._bar._style = new Socks.Style();
+ }
+ this._bar._style.setStyle(style,this._bar);
+
+ return this;
+ };
+
+ Socks.Element.Control.Progress.prototype.getFraction = function() {
+ return this._fraction;
+ };
+
+ Socks.Element.Control.Progress.prototype.setFraction = function(fraction) {
+ if(type(fraction) === 'Number') {
+ if(fraction < 0) {
+ fraction = 0;
+ } else if(fraction > 1) {
+ fraction = 1;
+ }
+ this._fraction = fraction;
+ if(this._bar._element !== undefined) {
+ this.setBarStyle({width:((this._fraction*100).toString()+'%')});
+ }
+ }
+ return this;
+ };
+
+ Socks.Element.Control.Progress.prototype.isDisabled = function() {
+ return false;
+ };
+
+ Socks.Element.Control.Progress.prototype.getFunction = function() {
+ return null;
+ };
+
+ Socks.Element.Control.Progress.prototype.setDisabled =
+ Socks.Element.Control.Progress.prototype.focus =
+ Socks.Element.Control.Progress.prototype.blur =
+ Socks.Element.Control.Progress.prototype.setFunction = function() {
+ return this;
+ };
+
+})(window.SOCKS);
+
View
105 socks.element.control.radio.js
@@ -0,0 +1,105 @@
+/*
+ * Socks .Element.Control.Radio
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ var toBoolean = Socks.Common.toBoolean;
+
+ Socks.Element.Control.Radio = function(parent, style, name, fun) {
+ this._socks_type = 'Socks.Element.Control.Radio';
+ this._elementId = window.Socks._nextElementId++;
+ this._parent = parent;
+
+ // create style object
+ this._style = new Socks.Style();
+
+ // sets the name
+ if(name !== undefined) {
+ this._name = name;
+ } else {
+ this._name = "radio_" + this._parent._slotId.toString();
+ }
+
+ // create element in the DOM
+ this._createElement();
+
+ // set the default event type
+ this._defaultEventType = "click";
+
+ // set the default event
+ if(fun !== undefined) {
+ this.setFunction(fun); // sets this
+ }
+
+ //set styles
+ this.setStyle(style);
+ };
+
+ Socks.Element.Control.Radio.prototype = new Socks.Element.Control();
+
+ Socks.Element.Control.Radio.prototype._createElement = function() {
+ if(this._element === undefined) {
+ this._element = document.createElement('input');
+ this._element.type = 'radio';
+ this._element.name = this._name;
+
+ var context = this;
+ if(this._element.outerHTML && this._element.outerHTML.indexOf('radio') !== -1 && this._element.outerHTML.indexOf('name') === -1) {
+ // IE radio bug workaround - http://msdn.microsoft.com/en-us/library/ms534184(VS.85).aspx
+ this._element = document.createElement('<INPUT type=radio name='+this._name+'>');
+ } else if(this._element.outerHTML && this._element.outerHTML.indexOf('name') === -1) {
+ // Safari 2 radio bug workaround
+ this._element.setAttribute('type','radio');
+ this._element.setAttribute('name',this._name);
+ var radioWorkaround = function(e) {
+ // if radio buttons are not wrapped in the same form element, they don't belong to the same group.
+ // so the other radio buttons have to be manually deselected.
+ var inputs = document.getElementsByTagName('input');
+ for(var i=0; i<inputs.length; i++) {
+ if(inputs[i].getAttribute('name') === context._element.getAttribute('name') && inputs[i].getAttribute('type') === 'radio' && inputs[i] !== context._element) {
+ inputs[i].checked = false;
+ }
+ }
+ };
+ this.addEvent('click', function(e) {radioWorkaround(e);});
+ }
+
+ this._element.style.zIndex = 1;
+
+ this.setStyle({margin:1,padding:0});
+
+ // set layout related styles
+ this._setLayout();
+ // insert the element into the parent
+ this._insertIntoParent(this._element);
+ } else {
+ this.setStyle(this.getStyle());
+ }
+ return this._element;
+ };
+
+ Socks.Element.Control.Radio.prototype.isSelected = function() {
+ this._selected = this._element.checked;
+ return this._selected;
+ };
+
+ Socks.Element.Control.Radio.prototype.setSelected = function(selected) {
+ selected = toBoolean(selected);
+ this._selected = selected;
+
+ if(this._element !== undefined) {
+ this._element.checked = (this._selected ? 'checked' : '');
+ }
+ return this;
+ };
+
+})(window.SOCKS);
+
View
65 socks.element.html.js
@@ -0,0 +1,65 @@
+/*
+ * Socks .Element.HTML
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ Socks.Element.HTML = function(parent, style, text) {
+ this._socks_type = 'Socks.Element.HTML';
+ this._elementId = window.Socks._nextElementId++;
+ this._parent = parent;
+
+ // create style object
+ this._style = new Socks.Style();
+
+ // innerHTML
+ this._innerHTML = (text !== undefined ? text : '');
+
+ // create element in the DOM
+ this._createElement();
+
+ // set styles
+ this.setStyle(style);
+ };
+
+ Socks.Element.HTML.prototype = new Socks.Element.Control();
+
+ Socks.Element.HTML.prototype._createElement = function() {
+ if(this._element === undefined) {
+ this._element = document.createElement('div');
+ this._element.innerHTML = this._innerHTML;
+ this._element.style.zIndex = 1;
+
+ // set layout related styles
+ this._setLayout();
+ // insert the element into the parent
+ this._insertIntoParent(this._element);
+ } else {
+ this._element.innerHTML = this._innerHTML;
+ this.setStyle(this.getStyle());
+ }
+ return this._element;
+ };
+
+ Socks.Element.HTML.prototype.getHTML = function() {
+ return this._innerHTML;
+ };
+
+ Socks.Element.HTML.prototype.setHTML = function(html) {
+ this._innerHTML = html.toString();
+
+ if(this._element !== undefined) {
+ this._element.innerHTML = this._innerHTML;
+ }
+ return this;
+ };
+
+})(window.SOCKS);
+
View
691 socks.element.js
@@ -0,0 +1,691 @@
+/*
+ * Socks .Element
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ var trim = Socks.Common.trim;
+ var type = Socks.Common.type;
+
+ Socks.Element = function() {
+ this._socks_type = 'Socks.Element';
+ };
+
+ Socks.Element.prototype._insertIntoParent = function(el) {
+ if(this._parent !== undefined) {
+ var i;
+ if(this._parent._insertElement.firstChild === null) {
+ // if it's an empty slot, just insert the new element in.
+ // this really should not happen.
+ this._parent._insertElement.appendChild(el);
+ } else {
+ switch(this._parent._insertPolicy || 'append') {
+ case 'append':
+ // insert it before the last element (last element is the clearfix div)
+ this._parent._insertElement.insertBefore(el, this._parent._insertElement.lastChild);
+ break;
+ case 'prepend':
+ // insert it at the beginning
+ this._parent._insertElement.insertBefore(el, this._parent._insertElement.firstChild);
+ break;
+ case 'before':
+ for(i=0; i<this._parent._insertElement.childNodes.length; i++) {
+ // look for the other element
+ if(this._parent._insertElement.childNodes[i] === this._parent._insertPosition._element) {
+ // if the other element exists, insert the new element before the other element
+ this._parent._insertElement.insertBefore(el, this._parent._insertPosition._element);
+ break;
+ }
+ }
+ break;
+ case 'after':
+ for(i=0; i<this._parent._insertElement.childNodes.length; i++) {
+ // look for the other element
+ if(this._parent._insertElement.childNodes[i] === this._parent._insertPosition._element) {
+ // if the other element exists, insert the new element before the other element
+ this._parent._insertElement.insertBefore(el, this._parent._insertPosition._element.nextSibling);
+ break;
+ }
+ }
+ }
+ }
+ }
+ return this;
+ };
+
+ Socks.Element.prototype._setLayout = function() {
+ if(this._element !== undefined) {
+ this._element.style.display = 'block';
+ this._element.style.position = 'relative';
+ this._element.style.overflow = 'visible';
+
+ if(this._parent !== undefined) {
+ if(this._parent._slotType === 'flow') {
+ if('cssFloat' in this._element.style) {
+ this._element.style.cssFloat = 'left';
+ } else if('styleFloat' in this._element.style) {
+ this._element.style.styleFloat = 'left'; // MSIE
+ }
+ } else {
+ if('cssFloat' in this._element.style) {
+ this._element.style.cssFloat = 'none';
+ } else if('styleFloat' in this._element.style) {
+ this._element.style.styleFloat = 'none'; // MSIE
+ }
+ this._element.clear = 'both';
+ }
+ }
+ }
+ return this;
+ };
+
+ //------------------------------------------------------
+ // Events
+
+ // returns SOCKS.Event object
+ Socks.Element.prototype.addEvent = function() {
+ if(this._events === undefined) {
+ this._events = {};
+ }
+
+ if(arguments.length > 0) {
+ var eventType = 'click';
+ var preventDefault = false;
+ var stopPropagation = true;
+ var fun;
+
+ for(var i=0; i<arguments.length; i++) {
+ var arg = arguments[i];
+ switch(type(arg)) {
+ case 'String':
+ eventType = arg;
+ break;
+ case 'Object':
+ if('type' in arg) {
+ eventType = arg.type;
+ }
+ if('preventDefault' in arg) {
+ preventDefault = arg.preventDefault;
+ }
+ if('stopPropagation' in arg) {
+ stopPropagation = arg.stopPropagation;
+ }
+ break;
+ case 'Function':
+ fun = arg;
+ }
+ }
+
+ var event = new Socks.Event(this, this._element, eventType, preventDefault, stopPropagation, fun);
+ if(this._events[eventType] !== undefined) {
+ this.removeEvent(this._events[eventType]);
+ }
+ this._events[eventType] = event;
+ return event;
+ }
+ return null;
+ };
+
+ Socks.Element.prototype.removeEvent = function(event) {
+ event.remove();
+ if(this._events !== undefined) {
+ // erase this event from the events object
+ var type = event.getType();
+ if(type in this._events) {
+ delete this._events[type];
+ }
+ }
+ return this;
+ };
+
+ Socks.Element.prototype.clearEvents = function() {
+ if(this._events !== undefined) {
+ // remove events
+ for(var eventType in this._events) {
+ if(this._events.hasOwnProperty(eventType)) {
+ this._events[eventType].remove();
+ delete this._events[eventType];
+ }
+ }
+ }
+ return this;
+ };
+
+ Socks.Element.prototype.getEvents = function() {
+ if(this._events === undefined) {
+ this._events = {};
+ }
+ return this._events;
+ };
+
+ Socks.Element.prototype._onAction = function(eventType, args) {
+ var preventDefault = false;
+ var stopPropagation = true;
+ var fun;
+ eventType = eventType || 'click';
+
+ for(var i=0; i<args.length; i++) {
+ var arg = args[i];
+ switch(type(arg)) {
+ case 'Object':
+ if('preventDefault' in arg) {
+ preventDefault = arg.preventDefault;
+ }
+ if('stopPropagation' in arg) {
+ stopPropagation = arg.stopPropagation;
+ }
+ break;
+ case 'Function':
+ fun = arg;
+ }
+ }
+
+ if(fun !== undefined) {
+ return this.addEvent({type:eventType, preventDefault:preventDefault, stopPropagation:stopPropagation}, fun);
+ }
+ return null;
+ };
+
+ Socks.Element.prototype._onMouseAction = function(eventType, args) {
+ var preventDefault = false;
+ var stopPropagation = true;
+ var fun;
+ eventType = eventType || 'click';
+
+ for(var i=0; i<args.length; i++) {
+ var arg = args[i];
+ switch(type(arg)) {
+ case 'Object':
+ if('preventDefault' in arg) {
+ preventDefault = arg.preventDefault;
+ }
+ if('stopPropagation' in arg) {
+ stopPropagation = arg.stopPropagation;
+ }
+ break;
+ case 'Function':
+ fun = arg;
+ }
+ }
+
+ if(fun !== undefined) {
+ var funWrapper = function(e) {
+ // get left and top coordinates
+ // http://www.quirksmode.org/js/events_properties.html#position
+ var left = 0, top = 0;
+ if(e.pageX || e.pageY) {
+ left = e.pageX;
+ top = e.pageY;
+ } else
+ if(e.clientX || e.clientY) {
+ left = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
+ top = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
+ }
+
+ fun.call(this, left, top, e);
+ };
+
+ return this.addEvent({type:eventType, preventDefault:preventDefault, stopPropagation:stopPropagation}, funWrapper);
+ }
+ return null;
+ };
+
+ Socks.Element.prototype.onClick = function() {
+ // onClick { |left, top, e| }
+ return this._onMouseAction('click',arguments);
+ };
+
+ Socks.Element.prototype.onContextMenu = function() {
+ // onContextMenu { |left, top, e| }
+ var addPreventDefault = true;
+ var args=[];
+ for(var i=0; i<arguments.length; i++) {
+ var arg = arguments[i];
+ if(type(arg) === 'Object') {
+ if(!('preventDefault' in arg)) {
+ arg.preventDefault = true;
+ }
+ addPreventDefault = false;
+ }
+ args.push(arg);
+ }
+
+ if(addPreventDefault) {
+ args.push({preventDefault:true});
+ }
+ return this._onMouseAction('contextmenu',args);
+ };
+
+ Socks.Element.prototype.onMouseDown = function() {
+ // onMouseDown { |left, top, e| }
+ return this._onMouseAction('mousedown',arguments);
+ };
+
+ Socks.Element.prototype.onMouseMove = function() {
+ // onMouseMove { |left, top, e| }
+ return this._onMouseAction('mousemove',arguments);
+ };
+
+ Socks.Element.prototype.onMouseUp = function() {
+ // onMouseUp { |left, top, e| }
+ return this._onMouseAction('mouseup',arguments);
+ };
+
+ Socks.Element.prototype.onMouseOut = function() {
+ // onMouseOut { |e| }
+ return this._onMouseOut('mouseout',arguments);
+ };
+
+ Socks.Element.prototype.onMouseOver = function() {
+ // onMouseOver { |e| }
+ return this._onMouseOver('mouseover',arguments);
+ };
+
+ //------------------------------------------------------
+ // Common
+
+ Socks.Element.prototype.getStyle = function() {
+ if('_style' in this) {
+ return this._style;
+ }
+ return {};
+ };
+
+ Socks.Element.prototype.setStyle = function(style) {
+ if(!('_style' in this)) {
+ this._style = new Socks.Style();
+ }
+ this._style.setStyle(style,this);
+
+ return this;
+ };
+
+ Socks.Element.prototype.getTooltip = function() {
+ if('_tooltip' in this) {
+ return this._tooltip;
+ }
+ return false;
+ };
+
+ Socks.Element.prototype.setTooltip = function(tooltip) {
+ this._tooltip = tooltip.toString();
+
+ if(this._element !== undefined) {
+ this._element.title = this._tooltip;
+ }
+ return this;
+ };
+
+ Socks.Element.prototype.getContents = function() {
+ if(this._contents !== undefined) {
+ return this._contents;
+ }
+ return [];
+ };
+
+ Socks.Element.prototype.getParent = function() {
+ if(this._parent !== undefined) {
+ return this._parent;
+ }
+ return null;
+ };
+
+ Socks.Element.prototype.getApp = function() {
+ var e = this;
+ while(true) {
+ if('_appId' in e) {
+ break;
+ }
+ e = e._parent;
+ }
+ return e;
+ };
+
+ Socks.Element.prototype.getId = function() {
+ if(this._element !== undefined) {
+ return this._element.id;
+ }
+ return '';
+ };
+
+ Socks.Element.prototype.setId = function(id) {
+ id=id.toString();
+
+ if(this._element !== undefined) {
+ this._element.id=id;
+ }
+ return this;
+ };
+
+ Socks.Element.prototype.getClassNames = function(className) {
+ if(this._element !== undefined) {
+ if(this._element.className !== '') {
+ this._element.className = trim(this._element.className);
+ return this._element.className.split(/\ \ */);
+ }
+ }
+ return [];
+ };
+
+ Socks.Element.prototype.setClassName = function(className) {
+ className=className.toString();
+
+ if(this._element !== undefined) {
+ this._element.className = className;
+ }
+ return this;
+ };
+
+ Socks.Element.prototype.addClassName = function(className) {
+ className=className.toString();
+
+ if(this._element !== undefined) {
+ if(this._element.className === '') {
+ this._element.className=className;
+ } else {
+ var tempClassName = this.getClassNames();
+ for(var i=0; i<tempClassName.length; i++) {
+ if(tempClassName[i] === className) {
+ return;
+ }
+ }
+ tempClassName.push(className);
+ this._element.className = tempClassName.join(' ');
+ }
+ }
+ return this;
+ };
+
+ Socks.Element.prototype.removeClassName = function(className) {
+ className=className.toString();
+
+ if(this._element !== undefined) {
+ if(this._element.className !== '') {
+ var tempClassName = this.getClassNames();
+ for(var i=0; i<tempClassName.length; i++) {
+ if(tempClassName[i] === className) {
+ tempClassName.splice(i,1);
+ i--;
+ }
+ }
+ this._element.className = tempClassName.join(' ');
+ }
+ }
+ return this;
+ };
+
+ Socks.Element.prototype.getOffsetWidth = function() {
+ if(this._element !== undefined) {
+ return this._element.offsetWidth;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.getOffsetHeight = function() {
+ if(this._element !== undefined) {
+ return this._element.offsetHeight;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.getOffsetLeft = function() {
+ if(this._element !== undefined) {
+ return this._element.offsetLeft;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.getOffsetTop = function() {
+ if(this._element !== undefined) {
+ return this._element.offsetTop;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.getClientWidth = function() {
+ if(this._element !== undefined) {
+ return this._element.clientWidth;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.getClientHeight = function() {
+ if(this._element !== undefined) {
+ return this._element.clientHeight;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.getClientLeft = function() {
+ if(this._element !== undefined) {
+ return this._element.clientLeft;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.getClientTop = function() {
+ if(this._element !== undefined) {
+ return this._element.clientTop;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.getScrollWidth = function() {
+ if(this._element !== undefined) {
+ return this._element.scrollWidth;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.getScrollHeight = function() {
+ if(this._element !== undefined) {
+ return this._element.scrollHeight;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.getScrollLeft = function() {
+ if(this._element !== undefined) {
+ return this._element.scrollLeft;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.getScrollTop = function() {
+ if(this._element !== undefined) {
+ return this._element.scrollTop;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.setScrollLeft = function(scrollLeft) {
+ scrollLeft=parseInt(scrollLeft,10);
+ if(this._element !== undefined) {
+ this._element.scrollLeft = scrollLeft;
+ }
+ return this;
+ };
+
+ Socks.Element.prototype.setScrollTop = function(scrollTop) {
+ scrollTop=parseInt(scrollTop,10);
+ if(this._element !== undefined) {
+ this._element.scrollTop = scrollTop;
+ }
+ return this;
+ };
+
+ Socks.Element.prototype.getScrollLeftMax = function() {
+ if(this._element !== undefined) {
+ return this._element.scrollWidth - this._element.clientWidth;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.getScrollTopMax = function() {
+ if(this._element !== undefined) {
+ return this._element.scrollHeight - this._element.clientHeight;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.move = function(left, top) {
+ this.setStyle({left:left, top:top});
+ return this;
+ };
+
+ Socks.Element.prototype.displace = function(left, top) {
+ this.setStyle({displaceLeft:left, displaceTop:top});
+ return this;
+ };
+
+ Socks.Element.prototype.getGutterRight = function() {
+ if(this._element !== undefined) {
+ var curStyle = this.getStyle();
+ var borderWidth = ('borderWidth' in curStyle ? curStyle.borderWidth : 0);
+ var borderSize = ('borderLeftWidth' in curStyle ? curStyle.borderLeftWidth : borderWidth) + ('borderRightWidth' in curStyle ? curStyle.borderRightWidth : borderWidth);
+ // offsetwidth - borderleft - borderright - clientwidth
+ return this._element.offsetWidth - borderSize - this._element.clientWidth;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.getGutterBottom = function() {
+ if(this._element !== undefined) {
+ var curStyle = this.getStyle();
+ var borderWidth = ('borderWidth' in curStyle ? curStyle.borderWidth : 0);
+ var borderSize = ('borderTopWidth' in curStyle ? curStyle.borderTopWidth : borderWidth) + ('borderBottomWidth' in curStyle ? curStyle.borderBottomWidth : borderWidth);
+ // offsetheight - bordertop - borderbottom - clientheight
+ return this._element.offsetHeight - borderSize - this._element.clientHeight;
+ }
+ return 0;
+ };
+
+ Socks.Element.prototype.isScrollable = function() {
+ if('scrollable' in this.getStyle()) {
+ return this.getStyle().scrollable;
+ }
+ return false;
+ };
+
+ Socks.Element.prototype.show = function() {
+ this.setStyle({hidden:false});
+ return this;
+ };
+
+ Socks.Element.prototype.hide = function() {
+ this.setStyle({hidden:true});
+ return this;
+ };
+
+ Socks.Element.prototype.toggle = function() {
+ if('hidden' in this.getStyle() && this.getStyle().hidden === true) {
+ this.show();
+ } else {
+ this.hide();
+ }
+ return this;
+ };
+
+ Socks.Element.prototype.visible = function() {
+ this.setStyle({invisible:false});
+ return this;
+ };
+
+ Socks.Element.prototype.invisible = function() {
+ this.setStyle({invisible:true});
+ return this;
+ };
+
+ Socks.Element.prototype.toggleVisibility = function() {
+ if('invisible' in this.getStyle() && this.getStyle().invisible === true) {
+ this.visible();
+ } else {
+ this.invisible();
+ }
+ return this;
+ };
+
+ Socks.Element.prototype.remove = function(dontRemoveItselfFromParent) {
+ //remove all children
+ if(this._contents) {
+ while(this._contents[0] !== undefined) {
+ if(this._contents[0] instanceof Socks.Element || this._contents[0] instanceof Socks.Slot) {
+ this._contents[0].remove(true);
+ }
+ this._contents.splice(0,1);
+ }
+ delete this._contents;
+ }
+
+ if(this._parent) {
+ if(!dontRemoveItselfFromParent && this._parent._contents !== undefined) {
+ for(var i=0; i<this._parent._contents.length; i++) {
+ if(this._parent._contents[i] === this) {
+ this._parent._contents.splice(i,1);
+ i--;
+ }
+ }
+ }
+ delete this._parent;
+ }
+
+ //remove events
+ if(this._events) {
+ this.clearEvents();
+ delete this._events;
+ }
+
+ //remove style
+ if(this._style) {
+ delete this._style;
+ }
+
+ //remove fun
+ if(this._fun) {
+ delete this._fun;
+ }
+
+ //remove elements
+ if(this._element) {
+ while(this._element.firstChild) {
+ this._element.removeChild(this._element.firstChild);
+ }
+ if(this._element.parentNode !== null) {
+ this._element.parentNode.removeChild(this._element);
+ }
+ delete this._element;
+ }
+
+ if(this instanceof Socks.Slot) {
+ if(this instanceof Socks.Slot.Canvas && this._canvasElement) {
+ while(this._canvasElement.firstChild) {
+ this._canvasElement.removeChild(this._canvasElement.firstChild);
+ }
+ if(this._canvasElement.parentNode !== null) {
+ this._canvasElement.parentNode.removeChild(this._canvasElement);
+ }
+ delete this._canvasElement;
+ }
+ if(this._insertElement) {
+ while(this._insertElement.firstChild) {
+ this._insertElement.removeChild(this._insertElement.firstChild);
+ }
+ if(this._insertElement.parentNode !== null) {
+ this._insertElement.parentNode.removeChild(this._insertElement);
+ }
+ delete this._insertElement;
+ }
+ }
+
+ return this;
+ };
+
+})(window.SOCKS);
+
View
38 socks.element.textblock.banner.js
@@ -0,0 +1,38 @@
+/*
+ * Socks .Element.TextBlock.Banner
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ Socks.Element.TextBlock.Banner = function(parent, style, array) {
+ this._socks_type = 'Socks.Element.TextBlock.Banner';
+ this._elementId = window.Socks._nextElementId++;
+ this._parent = parent;
+
+ // create style object
+ this._style = new Socks.Style();
+
+ if(array !== undefined) {
+ this._contents = array;
+ } else {
+ this._contents = [];
+ }
+
+ // create element in the DOM
+ this._createElement('h1', {margin:0, padding:0, fontSize:48, fontWeight:'normal'});
+
+ //set styles
+ this.setStyle(style);
+ };
+
+ Socks.Element.TextBlock.Banner.prototype = new Socks.Element.TextBlock();
+
+})(window.SOCKS);
+
View
38 socks.element.textblock.caption.js
@@ -0,0 +1,38 @@
+/*
+ * Socks .Element.TextBlock.Caption
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ Socks.Element.TextBlock.Caption = function(parent, style, array) {
+ this._socks_type = 'Socks.Element.TextBlock.Caption';
+ this._elementId = window.Socks._nextElementId++;
+ this._parent = parent;
+
+ // create style object
+ this._style = new Socks.Style();
+
+ if(array !== undefined) {
+ this._contents = array;
+ } else {
+ this._contents = [];
+ }
+
+ // create element in the DOM
+ this._createElement('h5', {margin:0, padding:0, fontSize:14, fontWeight:'normal'});
+
+ //set styles
+ this.setStyle(style);
+ };
+
+ Socks.Element.TextBlock.Caption.prototype = new Socks.Element.TextBlock();
+
+})(window.SOCKS);
+
View
38 socks.element.textblock.inscription.js
@@ -0,0 +1,38 @@
+/*
+ * Socks .Element.TextBlock.Inscription @VERSION
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ Socks.Element.TextBlock.Inscription = function(parent, style, array) {
+ this._socks_type = 'Socks.Element.TextBlock.Inscription';
+ this._elementId = window.Socks._nextElementId++;
+ this._parent = parent;
+
+ // create style object
+ this._style = new Socks.Style();
+
+ if(array !== undefined) {
+ this._contents = array;
+ } else {
+ this._contents = [];
+ }
+
+ // create element in the DOM
+ this._createElement('h6', {margin:0, padding:0, fontSize:10, fontWeight:'normal'});
+
+ //set styles
+ this.setStyle(style);
+ };
+
+ Socks.Element.TextBlock.Inscription.prototype = new Socks.Element.TextBlock();
+
+})(window.SOCKS);
+
View
109 socks.element.textblock.js
@@ -0,0 +1,109 @@
+/*
+ * Socks .Element.TextBlock
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *
+ * Licensed under the MIT License (MIT-LICENSE.txt)
+ *
+ * http://wiki.github.com/petejkim/socks
+ *
+ */
+
+(function(Socks){
+
+ var type = Socks.Common.type;
+
+ Socks.Element.TextBlock = function() {
+ this._socks_type = 'Socks.Element.TextBlock';
+ };
+
+ Socks.Element.TextBlock.prototype = new Socks.Element();
+
+ Socks.Element.TextBlock.prototype._createChildNodes = function() {
+ if(this._element !== undefined) {
+ //remove all childnodes
+ while(this._element.firstChild) {
+ this._element.removeChild(this._element.firstChild);
+ }
+
+ for(var i=0; i<this._contents.length; i++) {
+ if(type(this._contents[i]) === 'String') {
+ this._element.appendChild(document.createTextNode(this._contents[i]));
+ } else if(this._contents[i] instanceof Socks.Element.TextFragment) {
+ this._element.appendChild(this._contents[i]._getElement());
+ } else {
+ this._contents.splice(i,1);
+ i--;
+ }
+ }
+ }
+ return this._element;
+ };
+
+ Socks.Element.TextBlock.prototype._createElement = function(tag, style) {
+ if(this._element === undefined) {
+ this._element = document.createElement(tag);
+
+ this._createChildNodes();
+
+ if(style !== undefined) {
+ this.setStyle(style);
+ }
+
+ // set layout related styles
+ this._setLayout();
+ // insert the element into the parent
+ this._insertIntoParent(this._element);
+ } else {
+ this._createChildNodes();
+ this.setStyle(this.getStyle());
+ }
+ return this._element;
+ };
+
+ Socks.Element.TextBlock.prototype.getText = function() {
+ var text = '';
+
+ for(var i=0; i<this._contents.length; i++) {
+ if(type(this._contents[i]) === 'String') {
+ text += this._contents[i];
+ } else if(this._contents[i] instanceof Socks.Element.TextFragment) {
+ text += this._contents[i].getText();
+ }
+ }
+
+ return text;
+ };
+
+ Socks.Element.TextBlock.prototype.setText = function() {
+ var array=[];
+ if(arguments.length > 0) {
+ for(var i=0; i<arguments.length; i++) {
+ switch(type(arguments[i])) {
+ case 'Number':
+ case 'Boolean':
+ case 'String':
+ array.push(arguments[i].toString());
+ break;
+ case 'Function':
+ if(arguments[i] === Socks.Slot.prototype.br) {
+ var newBrElement = new Socks.Element.TextFragment.Br(this);
+ //this._contents.push(newBrElement);
+ array.push(newBrElement);
+ }
+ break;
+ default:
+ if(arguments[i] instanceof Socks.Element.TextFragment) {
+ array.push(arguments[i]);
+ }
+ }
+ }
+ }
+
+ this._contents = array;
+ this._createChildNodes();
+ return this;
+ };
+
+})(window.SOCKS);
+
View
38 socks.element.textblock.para.js
@@ -0,0 +1,38 @@
+/*
+ * Socks .Element.TextBlock.Para
+ *
+ * Copyright (c) 2009 Peter Jihoon Kim
+ *