Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made responsive + wrap fix #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "WideArea",
"description": "Create expandable textarea and write large amount of text easily.",
"version": "0.2.0",
"version": "0.4.0",
"author": "Afshin Mehrabani <[email protected]>",
"repository": {
"type": "git",
Expand Down
96 changes: 53 additions & 43 deletions widearea.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,57 @@
/* ----------------------------------- */
/* Text Area Wrapper */
/* ----------------------------------- */
.widearea-wrapper {
position:relative;
width:100%;
height:auto;
margin-bottom:1rem;
border-width:5px;
border-style:solid;
border-color:#eee;
box-shadow:0px 0px 2px rgba(0,0,0,0.4);
}
.widearea {
padding-right: 25px;
width:100%;
padding-right: 25px;
margin-bottom:0;
}
.widearea:focus {
box-shadow:none;
}
.widearea-icons {
position:absolute;
top:5px;
right:5px;
width:16px;
height:16px;
padding:0;
}
.widearea-icon {
height: 16px;
width: 17px;
background-repeat: no-repeat;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
filter: alpha(opacity=50);
-khtml-opacity: 0.5;
opacity: 0.5;
display: block;
-webkit-transition: all 0.1s ease-out;
-moz-transition: all 0.1s ease-out;
-ms-transition: all 0.1s ease-out;
-o-transition: all 0.1s ease-out;
transition: all 0.1s ease-out;
}
.widearea-icon:hover {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=100);
-khtml-opacity: 1;
opacity: 1;
}

/* ----------------------------------- */
/* Full Screen */
/* ----------------------------------- */
.widearea-overlayLayer {
position: fixed;
top: 0;
Expand Down Expand Up @@ -29,13 +79,10 @@
}

.widearea-overlayLayer.light textarea {
color: #ccc;
color: #222;
background-color: #fff;
}

.widearea-overlayLayer.light textarea:hover, .widearea-overlayLayer.light textarea:focus {
color: black;
}
/* Dark color scheme */
.widearea-overlayLayer.dark {
background-color: #2F3030;
Expand All @@ -46,10 +93,6 @@
background-color: #2F3030;
}

.widearea-overlayLayer.dark textarea:hover, .widearea-overlayLayer.dark textarea:focus {
color: #eee;
}

.widearea-wrapper > .widearea-icons {
z-index: 999998;
}
Expand Down Expand Up @@ -81,39 +124,6 @@ textarea.widearea-fullscreen {
padding-right: 20px;
}

.widearea-icons {
width: 16px;
height: 16px;
position: absolute;
top: 0;
right: 0;
padding-top: 6px;
padding-right: 5px;
}

.widearea-icon {
height: 16px;
width: 17px;
background-repeat: no-repeat;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
filter: alpha(opacity=50);
-khtml-opacity: 0.5;
opacity: 0.5;
display: block;
-webkit-transition: all 0.1s ease-out;
-moz-transition: all 0.1s ease-out;
-ms-transition: all 0.1s ease-out;
-o-transition: all 0.1s ease-out;
transition: all 0.1s ease-out;
}

.widearea-icon:hover {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=100);
-khtml-opacity: 1;
opacity: 1;
}

.widearea-icon.fullscreen {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlI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wBxOoi3gGsdTk9sUGWMu56i27GACvhagdnO0ozvsq8Z9ztnp9ws4+GJdwJgKYyyo+0AhbMCDOwNzKtnnMSasW6CjtQeQakdO2fcR25Q/Fusr/PwRrX+jVSK1uIPqTGBmpHJVjrDXUjlhKov1YxLb5/wWYADvoXd4CZG5iQAAAABJRU5ErkJggg==);
}
Expand All @@ -130,4 +140,4 @@ textarea.widearea-fullscreen {
height: 18px;
clear: both;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpEQkQ1QjdDM0I3MzgxMUUyQjA3QkQ4Nzg0REMzNTFCNyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpEQkQ1QjdDNEI3MzgxMUUyQjA3QkQ4Nzg0REMzNTFCNyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjVEMEQ4QkRFQjczMDExRTJCMDdCRDg3ODREQzM1MUI3IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkRCRDVCN0MyQjczODExRTJCMDdCRDg3ODREQzM1MUI3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+AzMsvAAAATRJREFUeNpibJq8jAEHcABibSDmB+L/QPwBiK8D8QFkRbU5kWCaBYsBUUBcAMSmOCw4CsTTgBjFBUxIbGYgngrES6GGnAfiaiiNDKyhaqYiOwTZIJAtWUD8CYhTgdgIiNuA+B4Ol2VBDUMxKBCI04D4NxC7AfEcJA1sDLhBWvOU5cEwg9iBuBPJlpMMpIF6oGHsTNDwUIV6YQ4D6UAXZAbIIGOowAoG8oEByCA+KOcJBQYJMTFQB3AwQaMbBGQoMOgpyKCzUE4EBQZdBBl0GohvA7ESEKeQYchlkBkgg34CcTlS6jYn0aBGYMb9CQvs9UA8C4hZgXgXmst+4TFkFtCQteh5LQvqIlBymA3E54C4CuplbACkNhvGQS5G/kIljiIVI4bEFiPYyqNlUExUwQYDAAEGANGJQntFVY0xAAAAAElFTkSuQmCC);
}
}
109 changes: 6 additions & 103 deletions widearea.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* WideArea v0.3.0
* WideArea v0.4.0
* https://github.com/usablica/widearea
* MIT licensed
*
Expand Down Expand Up @@ -165,115 +165,17 @@
//go to next wideArea
++this._wideAreaId;

//set icons panel position
_renewIconsPosition(currentTextArea, wideAreaIcons);

// wrap textarea
currentTextArea.parentNode.insertBefore(wideAreaWrapper, currentTextArea);
wideAreaWrapper.appendChild(currentTextArea);

//append all prepared div(s)
wideAreaIcons.appendChild(fullscreenIcon);
wideAreaWrapper.appendChild(wideAreaIcons);

//and append it to the page
document.body.appendChild(wideAreaWrapper);

//add the textarea to internal variable
this._textareas.push(currentTextArea);
}

//set a timer to re-calculate the position of textareas, I don't know whether this is a good approach or not
this._timer = setInterval(function() {
for (var i = self._textareas.length - 1; i >= 0; i--) {
var currentTextArea = self._textareas[i];
//get the related icon panel. Using `getElementById` for better performance
var wideAreaIcons = document.getElementById("widearea-" + currentTextArea.getAttribute("data-widearea-id"));

//get old position
var oldPosition = _getOffset(wideAreaIcons);

//get the new element's position
var currentTextareaPosition = _getOffset(currentTextArea);

//only set the new position of old positions changed
if((oldPosition.left - currentTextareaPosition.width + 21) != currentTextareaPosition.left || oldPosition.top != currentTextareaPosition.top) {
//set icons panel position
_renewIconsPosition(currentTextArea, wideAreaIcons, currentTextareaPosition);
}
};
}, 200);
}

/**
* Set new position to icons panel
*
* @api private
* @method _renewIconsPosition
* @param {Object} textarea
* @param {Object} iconPanel
*/
function _renewIconsPosition(textarea, iconPanel, textAreaPosition) {
var currentTextareaPosition = textAreaPosition || _getOffset(textarea);
//set icon panel position
iconPanel.style.left = currentTextareaPosition.left + currentTextareaPosition.width - 21 + "px";
iconPanel.style.top = currentTextareaPosition.top + "px";
}

/**
* Get an element position on the page
* Thanks to `meouw`: http://stackoverflow.com/a/442474/375966
*
* @api private
* @method _getOffset
* @param {Object} element
* @returns Element's position info
*/
function _getOffset(element) {
var elementPosition = {};

//set width
elementPosition.width = element.offsetWidth;

//set height
elementPosition.height = element.offsetHeight;

//calculate element top and left
var _x = 0;
var _y = 0;
while(element && !isNaN(element.offsetLeft) && !isNaN(element.offsetTop)) {
_x += element.offsetLeft;
_y += element.offsetTop;
element = element.offsetParent;
}
//set top
elementPosition.top = _y;
//set left
elementPosition.left = _x;

return elementPosition;
}

/**
* Get an element CSS property on the page
* Thanks to JavaScript Kit: http://www.javascriptkit.com/dhtmltutors/dhtmlcascade4.shtml
*
* @api private
* @method _getPropValue
* @param {Object} element
* @param {String} propName
* @returns Element's property value
*/
function _getPropValue (element, propName) {
var propValue = '';
if (element.currentStyle) { //IE
propValue = element.currentStyle[propName];
} else if (document.defaultView && document.defaultView.getComputedStyle) { //Others
propValue = document.defaultView.getComputedStyle(element, null).getPropertyValue(propName);
}

//Prevent exception in IE
if(propValue.toLowerCase) {
return propValue.toLowerCase();
} else {
return propValue;
}
}

/**
Expand Down Expand Up @@ -482,3 +384,4 @@
exports.wideArea = wideArea;
return wideArea;
}));