Created
December 1, 2016 21:25
-
-
Save EliJDonahue/672550ed875ce45892ea31332e6f917a to your computer and use it in GitHub Desktop.
Javascript helper functions for overriding default field styles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ////////////////////// Configurable variables ///////////////////////////// | |
| var imgRoot = '../customer/svg/'; | |
| var searchBtn = imgRoot + 'search.svg'; | |
| var dateBtn = imgRoot + 'calendar.svg'; | |
| ////////////////////// Helpful functions ////////////////////////////////// | |
| // function to replace a class name for specified elements | |
| replaceClass = function(els, oldClass, newClass) | |
| { | |
| while (els.length > 0) | |
| { | |
| els[0].className = els[0].className.replace(new RegExp('(?:^|\\s)'+ | |
| oldClass + '(?:\\s|$)'), newClass); | |
| } | |
| }; | |
| // sets a specific attribute for all elements in a collection | |
| setAttributeOnAll = function(els, attrName, attrVal) | |
| { | |
| for (var i=0; i < els.length; i++) | |
| els[i].setAttribute(attrName,attrVal); | |
| }; | |
| // appends a value to an attribute for all elements in a collection | |
| // can be used to append class name | |
| appendAttributeOnAll = function(els, attrName, attrVal) | |
| { | |
| for (var i=0; i < els.length; i++) | |
| { | |
| var curr = els[i].getAttribute(attrName); | |
| els[i].setAttribute(attrName, curr + ' ' + attrVal); | |
| } | |
| }; | |
| // get element associated with an item property's "button" | |
| getItemFieldButton = function(field) | |
| { | |
| var itms = document.getElementsByClassName(field); | |
| return itms[0].getElementsByClassName("sys_f_input_image"); | |
| }; | |
| // replace icon on an item property's "button" | |
| updateItemFieldIcon = function(field,icon) | |
| { | |
| var btn = getItemFieldButton(field); | |
| setAttributeOnAll(btn,'src',icon); | |
| return btn; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment