Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function k8rBox( div ){
- var focused,box,activeText;
- var box = document.getElementById(div);
- activeText = document.createElement('input');
- activeText.setAttribute('type','text');
- activeText.onkeydown = function(){
- fitBoxToText();
- }
- activeText.onfocus = function(){ focused = 1;}
- activeText.onblur = function(){ focused = 0;}
- if (activeText.style.fontSize == "")
- activeText.style.fontSize = "14px";
- if (activeText.style.fontWeight == "")
- activeText.style.fontWeight = "normal";
- if (activeText.style.fontVariant == "")
- activeText.style.fontVariant = "normal";
- if (activeText.style.fontStyle == "")
- activeText.style.fontStyle = "normal";
- if (activeText.style.fontFamily == "")
- activeText.style.fontFamily = "verdana";
- box.appendChild(activeText);
- this.bubbleUp = function(){
- repositionActiveText();
- }
- this.repositionActiveText = function(){
- }
- box.onclick = function(){
- activeText.focus();
- };
- this.fitBoxToText = function(){
- var sizeTester = document.createElement('span');
- setTimeout(function(){
- sizeTester.innerHTML = activeText.value;
- sizeTester.style.position = 'absolute';
- sizeTester.style.left = "-19px";
- sizeTester.style.top = "-49px";
- sizeTester.style.fontSize = activeText.style.fontSize;
- sizeTester.style.fontWeight = activeText.style.fontWeight;
- sizeTester.style.fontVariant = activeText.style.fontVariant;
- sizeTester.style.fontStyle = activeText.style.fontStyle;
- sizeTester.style.fontFamily = activeText.style.fontFamily;
- box.appendChild(sizeTester);
- activeText.style.width = sizeTester.offsetWidth+10+"px";
- box.removeChild(sizeTester);
- sizeTester = null;
- },0001); // we're doing a delay because this fires before the actual value change
- }
- fitBoxToText();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement