Portal Home Page text
I need to add some permanent text on the homepage just above/below the search bar (which I will hide eventually along with the title text)
Any idea on how to do this? I've had a look but can't see anywhere to put it.
Thanks
Best Answer
-
Martin_Blomgren Customer Ninja IT Monkey ✭✭✭✭Based on your examples I figured you only needed to append text. Either way here's how you achieve what you want using the mutation observer in the alternative home (from what I can see in your screenshot).
custom.css:.service-request-body .search-title,<br>.service-request-body .search-wrapper {<br> display: none;<br>}
custom.js<div>var observer = new MutationObserver(function (mutations) {<br> var targetElement = $(".search-row .service-request-body");<br> console.log('Found target:', targetElement.length, targetElement);<br id="null"> if(targetElement.length > 0) {<br> targetElement.prepend('<h3>My Text Here</h3>');<br id="null"> observer.disconnect();<br> }<br>});<br id="null">// Notify me of everything!<br>var observerConfig = {<br> attributes: true,<br> childList: false,<br> characterData: false,<br> subtree: true<br>};<br id="null">// Node, config<br>$(document).ready(function () {<br> var targetNode = document.getElementById('main_wrapper');<br> observer.observe(targetNode, observerConfig);<br>});</div>
5
Answers
Does this thread help?
https://community.cireson.com/discussion/comment/4217#Comment_4217
Geoff
I'm guessing it'll be in the iis folder for CiresonPortal somewhere?
CiresonPortal/CustomSpace/custom.js
I have put this in and restarted the cache builder but i'm not seeing it
I left this over the weekend and it's still not working.
FYI what I done was put in the CustomSpace folder I created a custom.js and literally pasted
Thanks
I think it will be a timing issue. That code runs straight away at which point other code is still building the page so the element you are trying to find and insert before does not yet exist.
You can fix this with a small JavaScript timeout (bit of a dirty hack) or a Mutation Observer (quite complex JS)
Do you have any internal Web Developers you can tap into?
Geoff
It's been left a few weeks now and still not there, so it's definitely not working for us, so something is not quite right.
Please advise
As Geoff pointed out the easiest way is to use a timeout, see example below:
However based on your code the text would be inserted in the header which have a fixed position an height rendering it overlapping with the first menu item, it would require some css styling atleast if you want it positioned under the searchbar in the top navbar!
I've placed that code in custom.js and it's still not appearing on the home page for the portal
It's also best to wait for the DOM to be ready, otherwise it might not show, so wrap your code with the following statement:
(If you always want your custom code to show omit the if clause and only paste this into custom.js)
This will NOT be inserted in the header but will effectively let you know if it worked as I will show in the main content area.
To actually remove the title and search in the header use css and paste the following in custom.css:
And then append whatever you want in the header (custom.js):
BUT if you only want to add some custom text to the header I would use a CSS only solution and place it where needed, lot's of way really so this is just an example (custom.css):
That seems the closest but I need it just above "Need help finding what you are looking for" (this along with that search bar will be hidden eventually)
I've tried putting the div class there but that doesn't seem to be working, I assume it'll just be text.insertBefore('.divnamehere')?
Thanks
Based on your code snippet (#side_nav_toggle) I thought that you wanted to insert your custom text into the header.
To use a CSS only solution (no need to touch custom.js), remove all custom code from the thread in custom.js & custom.css and place the following in custom.css:
Clear your browser cache between edits to make sure that the new content gets downloaded!
Thats exactly where it needs to be! The only thing is though is it possible it can be done in JS? That way I can style it how I want as it'll need to be in it's own div's.
I can do the styling just no idea about the JS and I believe you can't enter html code into the css content bit.
Thanks
Styling is always done with CSS, just a matter of if you want it to be in a custom.css file or inline in your html markup but if you want more elements than just a simple text string your'e force to go with JS.
To remove the search bar just use the first rule from above:
To add your custom html markup with jQuery:
This is where i'd like it to be
Almost, it all works great but when I hide use search-title {display:none;} it dissapears
We currently have the search title and search box, but as we only have 2 choices its pointless.
very close!
Is there a way what you posted to worth whether search-title is displayed or hidden?
So perhaps take a moment to better define your desired end result in greater detail?
Exactly like above, that way I can then put in my own css for "texthere" (or another css name I choose). Once I get something like that I can easily go from there with my own html & css to style how i'd like it to be, but it's just getting the baseline sorted first but like I said earlier JS goes straight through me.
Thanks
Still don't get your end-game here.
If you only want CSS styleable text then I would go for my CSS only solution otherwise Seth's mutation observer pattern (cleaner then timeouts) and prepend it into a element which you do not hide with 'display: none' - if you actually need other functionality which a text element cannot provide.
custom.css:
custom.js
Thank you all!!
Wicked thread, thank you.