We already have the font awesome widget implemented and now need to somehow have a text field with that image as optional. We want the font awesome to either be a stand alone widget or else to be able to have text associated with it.
We were able to do that, however, we need to be able to change the size, font, color etc to the image (font awesome icon) but not the text and vice versa.
Below is our code as of now:
JS files:
win-font-awesome.js:
Code: Select all
pui.widgets.add({
name: "Font Awesome",
newId: "fontAwesome",
defaults: {
"width":"13px",
"height":"16px",
/*"text align":"center",
"cursor":"pointer",*/
"description":" "
},
propertySetters: {
"field type": function(params) {
if (params.design) {
params.properties["css class"] = '';
params.dom.innerHTML = "<i class='fa fa-" + params.properties["font awesome type"] + "'>" + params.properties["description"] + "</i>";
} else {
params.dom.className = "fa fa-" + params.properties["font awesome type"];
if (typeof params.properties.description === "undefined") {
params.dom.innerText = " ";
} else {
params.dom.innerText = " " + params.properties.description;
}
params.dom.style.fontSize = parseInt(params.properties["height"]) < parseInt(params.properties["width"]) ? params.properties["height"] : params.properties["width"];
params.dom.setAttribute("win-customwidget","1");
addEvent(params.dom, "click", function() {
params.dom.setAttribute("win-clicked", "1");
pui.click();
});
}
},
"font awesome type": function(params) {
if (params.design) {
params.dom.innerHTML = "<i class='fa fa-" + params.newValue + "'>" + params.properties["description"] + "</i>";
params.dom.firstChild.style.fontSize = parseInt(params.properties["height"]) < parseInt(params.properties["width"]) ? params.properties["height"] : params.properties["width"];
} else {
params.dom.className = "fa fa-" + params.properties["font awesome type"];
params.dom.style.fontSize = parseInt(params.properties["height"]) < parseInt(params.properties["width"]) ? params.properties["height"] : params.properties["width"];
}
},
"height": function(params) {
if (params.design) {
params.dom.firstChild.style.fontSize = parseInt(params.value) < parseInt(params.properties["width"]) ? params.value : params.properties["width"];
}
},
"width": function(params) {
if (params.design) {
params.dom.firstChild.style.fontSize = parseInt(params.value) < parseInt(params.properties["height"]) ? params.value : params.properties["height"]
}
},
"description": function(params) {
if (params.design) {
params.dom.innerHTML = "<i class='fa fa-" + params.properties["font awesome type"] + "'>" + params.newValue + "</i>";
params.dom.firstChild.style.fontSize = parseInt(params.properties["height"]) < parseInt(params.properties["width"]) ? params.properties["height"] : params.properties["width"];
}
}
}
});
//the Other... option in choices allows the users to pick a different option than what is listed
pui.addCustomProperty({
name: "font awesome type",
help: "sets the type of the font awesome widget",
choices: [
"adjust",
"arrows",
"arrow-right",
"bars",
"bell",
"caret-down",
"caret-up",
"check",
"check-circle-o",
"chevron-left",
"chevron-right",
"circle-o",
"clock-o",
"cog",
"ellipsis-v",
"file-excel-o",
"history",
"minus-circle",
"minus-square-o",
"mobile",
"pencil-square-o",
"plus",
"plus-square-o",
"question-circle",
"refresh",
"search",
"sort",
"times",
"times-circle-o",
"truck",
"user",
"Other..."
],
controls: ["Font Awesome"],
category: "Font Awesome"
});
if (typeof WinSupply === "undefined") WinSupply = {};
WinSupply.fontAwesomeSubmit = function(response) {
var widgets = document.querySelectorAll("div[win-customwidget]");
for( var i=0; i < widgets.length; i++){
if (widgets[i].pui && widgets[i].pui.fieldName) {
var idVar = widgets[i].pui.formatName + "." + widgets[i].pui.fieldName;
var attr = widgets[i].getAttribute("win-clicked");
if (attr && attr=="1") {
response[idVar] = "1";
}
else if (attr && attr=="2") {
response[idVar] = "2";
}
else {
response[idVar] = "0";
}
}
}
return true;
}
Code: Select all
pui.toolbox.add({
category: "Font Awesome",
widget: "Font Awesome",
text: "Font Awesome Plus",
proxyHeight: 16,
proxyWidth: 250,
proxyHTML: '<i class="fa fa-plus"></i>',
defaults: {
"font awesome type":"plus",
}
});
Code: Select all
<span class="font-awesome">
<i class="fa fa-plus"></i>
<input type="text" value=""></label>
</span>
There is no associated css code for this particular widget.
Do you have an insight for us on how to make this change?
Thanks,
Sondra