");
- html.push("");
-
- $('#poll').html(html.join(''));
- }else{
- showResult(data);
+ if (haveTopic) {
+ var prefs = new gadgets.Prefs();
+ var topicId = pollId.replace("poll", "topic");
+ var topicURL = window.location.protocol + "//" + window.location.host + parent.parent.eXo.env.portal.context + "/" + parent.parent.eXo.env.portal.portalName + "/forum/topic/" + topicId;
+ tbl.push('
');
+ } else {
+ tbl.push('
' + question + '
');
+ }
+
+ tbl.push('
');
+ tbl.push('');
+ for ( var i = 0, len = options.length; i < len; i++) {
+ var result = Math.round(vote[i]);
+ var style = "";
+ if (result > 5) {
+ var style = 'width:' + result + '%;';
+ } else {
+ var style = 'width:' + result + '%;';
+ }
+
+ tbl.push('' + options[i] + ' | | ' + result + '% |
');
+ }
+ tbl.push('');
+ tbl.push('
');
+ tbl.push('
');
+ if (data.isAgainVote) {
+ tbl.push("");
+ $("#btnVoteAgain").live("click", function() {
+ showPoll(data, true);
+ });
+ }
+ tbl.push(' ' + msgTotal + ': ' + voters + ' ' + msgVoter + '');
+ tbl.push('
');
+
+ $("#poll").html(tbl.join(''));
+ // Adjust width of progress bar if it's too short
+ var featPoll = document.getElementById('uiFeaturePoll');
+ var labelVote = featPoll.getElementsByClassName('label-vote');
+ var isWindowMode = featPoll.offsetWidth < 400 ? false : true;
+ if (!isWindowMode) {
+ $(featPoll).addClass('minimize');
+ var children = featPoll.getElementsByTagName('td');
+ if (children)
+ children[0].style.width = 105;
+ }
+ else {
+ $(featPoll).addClass('maximize');
}
- adjustHeight();
+
+ makeTooltipForLabel(labelVote, isWindowMode);
+ adjustHeight();
}
-function showResult(data){
- var prefs = new gadgets.Prefs();
- var voters = data.infoVote[data.infoVote.length-1];
- var options = data.option;
- var vote = data.vote;
- var question = data.question;
- var msgOption = prefs.getMsg('option');
- var msgPercent = prefs.getMsg('percent');
- var msgVoter = prefs.getMsg('voter');
- var msgTotal = prefs.getMsg('total');
- var pollId = data.id;
- var parentPath = data.parentPath;
- var haveTopic = parentPath.indexOf("ForumData/CategoryHome"); //check topic of poll if toptic is exist
- var tbl = [];
-
- if(haveTopic){
- var prefs = new gadgets.Prefs();
- var topicId= pollId.replace("poll","topic");
- var topicURL = window.location.protocol + "//" + window.location.host + parent.parent.eXo.env.portal.context + "/"+ parent.parent.eXo.env.portal.portalName + "/forum/topic/" + topicId;
- tbl.push('
');
- }
- else{
- tbl.push('
' + question + '
');
- }
-
- tbl.push('
');
- tbl.push('');
- for(var i = 0, len = options.length; i < len; i++){
- var result = Math.round(vote[i]);
- var style ="";
- if(result>5){
- var style = 'width:' + result + '%;';
- }
- else{
- var style = 'width:' + result + '%;';
- }
-
- tbl.push('' + options[i] + ' | | ' + result + '% |
');
- }
- tbl.push('');
- tbl.push('
');
- tbl.push('
');
- if(data.isAgainVote){
- tbl.push("");
- $("#btnVoteAgain").live("click", function(){
- showPoll(data, true);
- });
- }
- tbl.push(' '+ msgTotal +': ' + voters + ' ' + msgVoter +'');
- tbl.push('
');
-
- $("#poll").html(tbl.join(''));
- adjustHeight();
+function makeTooltipForLabel(labels, mode) {
+ if (labels) {
+ for (var j = 0; j < labels.length; j++) {
+ var width = labels[j].offsetWidth;
+ console.log(width);
+
+ if (mode == false) {
+ if (width > 105)
+ setAttribute(labels[j], 'data-toggle', 'tooltip');
+ labels[j].style.width = 100;
+ }
+ }
+ }
}
-function doVote(el){
- var votes = [];
- $(".radio:checked").each(function(){
- votes.push($(this).val());
- });
-
- if(votes.length < 1) {
- $("input:checked").each(function() {
- votes.push($(this).val());
- });
- if(votes.length < 1) return;
- }
-
- var pollId = el.form.elements["pollid"].value;
- var url = baseURL + "votepoll/" + pollId + "/" + votes.join(":");
- $.getJSON(url,showResult);
+function setAttribute(element, property, value) {
+ return element.setAttribute(property, value);
+}
+
+function doVote(el) {
+ var votes = [];
+ $(".radio:checked").each(function() {
+ votes.push($(this).val());
+ });
+
+ if (votes.length < 1) {
+ $("input:checked").each(function() {
+ votes.push($(this).val());
+ });
+ if (votes.length < 1) {
+ return;
+ }
+ }
+
+ var pollId = el.form.elements["pollid"].value;
+ var url = baseURL + "votepoll/" + pollId + "/" + votes.join(":");
+ $.getJSON(url, showResult);
}
-function changeVote(obj){
- var selectedValue = obj.options[obj.selectedIndex].value;
- var url = baseURL + "viewpoll/" + selectedValue;
- $.getJSON(url,function(data){
- showPoll(data, false);
- });
- config();
+function changeVote(obj) {
+ var selectedValue = obj.options[obj.selectedIndex].value;
+ var url = baseURL + "viewpoll/" + selectedValue;
+ var prefs = new gadgets.Prefs();
+ prefs.set('votedValue', selectedValue);
+ $.getJSON(url, function(data) {
+ showPoll(data, false);
+ });
+ config();
}
-function config(){
- if($('#listpoll').is(':visible'))
- $('#listpoll').fadeOut("fast",adjustHeight);
- else
- $('#listpoll').fadeIn("fast",adjustHeight);
- adjustHeight();
+function config() {
+ if ($('#listpoll').is(':visible')) {
+ $('#listpoll').fadeOut("fast", adjustHeight);
+ } else {
+ $('#listpoll').fadeIn("fast", adjustHeight);
+ }
+ adjustHeight();
}
-function adjustHeight(){
- gadgets.window.adjustHeight($('.uiGadgetThemes').outerHeight());
+function adjustHeight() {
+ gadgets.window.adjustHeight($('.uiGadgetThemes').outerHeight());
}
gadgets.util.registerOnLoadHandler(init);
\ No newline at end of file
diff --git a/samples/gadgets-sample/gadgets/src/main/webapp/skin/less/Poll.less b/samples/gadgets-sample/gadgets/src/main/webapp/skin/less/Poll.less
index a406f5f01f..d86364da2a 100644
--- a/samples/gadgets-sample/gadgets/src/main/webapp/skin/less/Poll.less
+++ b/samples/gadgets-sample/gadgets/src/main/webapp/skin/less/Poll.less
@@ -1,10 +1,24 @@
.uiGadgetThemes{
.gadContent {
padding: 8px 16px;
+ .question, .question .text{
+ color: #2f5e92;
+ }
.question{
- margin: 10px 0px 12px 0px;
+ margin: 5px 0 10px;
text-decoration: none;
- color: #2f5e92;
+ display: inline-block;
+ line-height: 18px;
+ > i {
+ float: left;
+ margin-right: 5px;
+ margin-top: 1px;
+ }
+ .text {
+ display: block;
+ line-height: 18px;
+ margin-left: 21px;
+ }
}
.poll{
h6{
@@ -38,14 +52,15 @@
width: 100%;
margin: 10px 0;
.label-vote{
- max-width: 170px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
+ display: inline-block;
}
.percent{
- width: 40px;
- padding-left: 12px;
+ width: 35px;
+ padding-left: 2px;
+ text-align: right;
}
}
@@ -69,17 +84,34 @@
}
.horizontalBG{
+ width: 100%;
height: 10px;
border-radius: 5px;
- background-image: linear-gradient(to bottom, #d3d3d3, #eaeaea);
- box-shadow: 0 1px 1px #C0C0C0 inset;
+ background-color: #dcdcdc;
+ background-image: -moz-linear-gradient(top, #d3d3d3, #eaeaea);
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#d3d3d3), to(#eaeaea));
+ background-image: -webkit-linear-gradient(top, #d3d3d3, #eaeaea);
+ background-image: -o-linear-gradient(top, #d3d3d3, #eaeaea);
+ background-image: linear-gradient(to bottom, #d3d3d3, #eaeaea);
+ background-repeat: repeat-x;
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd3d3d3', endColorstr='#ffeaeaea', GradientType=0);
+ -webkit-box-shadow: 0 1px 1px #c0c0c0 inset;
+ -moz-box-shadow: 0 1px 1px #c0c0c0 inset;
+ box-shadow: 0 1px 1px #c0c0c0 inset;
overflow: hidden;
}
.horizontalBar {
height: 10px;
border-radius: 5px 0 0 5px;
- background-image: linear-gradient(to bottom, #5d83c3, #456697);
+ background-color: #5377b1;
+ background-image: -moz-linear-gradient(top, #5d83c3, #456697);
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#5d83c3), to(#456697));
+ background-image: -webkit-linear-gradient(top, #5d83c3, #456697);
+ background-image: -o-linear-gradient(top, #5d83c3, #456697);
+ background-image: linear-gradient(to bottom, #5d83c3, #456697);
+ background-repeat: repeat-x;
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5d83c3', endColorstr='#ff456697', GradientType=0);
}
.listpoll {
@@ -98,6 +130,7 @@
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
+ text-align: left;
}
}
.selectbox{
@@ -136,4 +169,31 @@
margin: 0px;
}
}
-}
\ No newline at end of file
+ &.minimize {
+ .voteResult {
+ table-layout: fixed;
+ }
+ .gadContent {
+ .listpoll {
+ .control-group {
+ .control-label {
+ width: auto;
+ float: none;
+ padding: 0;
+ margin: 0 0 8px;
+ }
+ .controls {
+ margin-left: 0;
+ }
+ }
+ }
+ }
+ }
+ &.maximize {
+ .voteResult {
+ .label-vote {
+ padding-right: 10px;
+ }
+ }
+ }
+}