I'm new here so i'll ask. I have a dynamic slider that gets the height dynamically. So I need to get this dynamic height and pass the value to the top css.
I added this function in the function.js file
$('.navbar-inverse').css("top", 922);
and it gets the value, but I need this value to be dynamic and not inserted manually.
The height value comes from a class name fs-stretcher
Any help would be great. tks
Try
$('.navbar-inverse').css("top", $('.fs-stretcher').height())
This needs to be part of an event handler if you want the dynamic value. You call it a slider but I'm not sure what exactly the event is so we'll go with...scrolling down the page (just change the word scroll to whatever you use).
$('.navbar-inverse').on('scroll', function() {
$(this).css('top', $('.fs-stretcher').height());
});
Related
I want to Change the value assigned to a Document Property in spot fire. Lets say i have created a new document property called "Test1" as a string and assign it a value "a". Is there are way to change this value using Javascript every time i load the spotfire dashboard ?
I'm unaware of a way to use JavaScript for this, but you can assign a string document property via custom expression (if it's a List Box) or run an IronPython script each time the value changes. So, you could set the expression to the current date, datetimenow() and then every time it's loaded the IronPython script would fire. However, I don't see why you'd need the property control for this.
I suppose it really depends on what you want the document property to be set to. Is it data from your tables? Output from complex code? These are all things to consider.
1) Create an input type property control using the Document Property you want to change.
2) Edit Html to assign parent element an id say "testInput". And add the script as shown below in the Edit HTML window.
<span id="testInput"><SpotfireControl id="7db34e6c423240f59fc99e6b80fa23ec" /></span>
<script>
$("#testInput input").val("after");
$("#testInput input").focus();
$("#testInput input").blur();
</script>
3) This script will change the document property value to "after" whenever you open a file.
As you comment seemed to suggest, something you can do is write this code in Python and attach the script to an action control, e.i. a Link or a Button. Something simple like: Document.Properties["Test1"] = newValue
or even: Document.Properties[changingProperty] = newValue
allowing the code to be more reusable.
Then you insert Javascript into the Text Area as well to the effect of: $("#VeryLongSpotfireControlID").click();
Which should simulate clicking on action control, which in turn triggers the Python script to update the value. Just be careful not to use this approach when it would result in reloading the text area HTML, as this will re-trigger the Javascript, thus creating an endless loop.
I believe I have found a possible solution/work-around for the issue, entirely based on pure JavaScript (since TIBCO removed jQuery starting from Spotfire X). The solution is to force a simulated Enter Keystroke while focusing the input box to trigger updating the Document Property. (No data function and R needed)
HTML (SpotfireControl Element is an single line input-box for a Doc. Prop.):
<div id="container"><SpotfireControl id="b8534f13dc62416db6d4eaab16030f5e" /></div>
JS (focus and blur might no longer be needed for this solution, but I'm still keeping them just in case):
const inputConfirmationEvent = new KeyboardEvent("keypress", {
keyCode: 13,
bubbles: true,
cancelable: false
});
var elem = document.querySelector("#container input");
elem.value = "stringValue";
elem.blur();
elem.focus();
document.querySelector("#container input").dispatchEvent(inputConfirmationEvent);
Hope it helps someone.
Best,
Aaron
I'm using select2 which takes in rails instance variables. Due to the design layout, I can't just scale down the original select2 input. I have to create another.
The problem: A rails partial including the logic for the select2 interferes with the logic I need for the mobile select2 feature. So, it needs to not exist, not simply to be hidden (display: none) , etc..
I was able to get the mobile to work by using remove() on the original partial, but how can I get it back. Maybe something with a page-width conditional, but I'm not sure how that would work.
this is the element / render I neeed to have removed then to have it 'un-removed': (haml markup)
.divider-row
.row-border.vOne
#vCompare
= render 'compare', :categories => #categories, :v_friends => #v_friends
my JS:
if (screen.width < 760){
$('#vCompare').remove();
}
how would I get this information back, when the screen size was over 760? append?
Im trying to use detach and appendTo() as some have suggested below:
$('.compare-searchM').on('change', function () {
$('#vCompare').detach();
})
$(window).resize(function() {
$('#vCompare').appendTo($('#vAppend'));
sizing();
});
haml / markup :
.row-border
#vAppend
#vCompare
= render 'compare', :categories => #categories,
the detach is working, but I must not be understanding something with appendto()
Instead of using .remove() you can use .detach() and store the jquery object in some other variable, like
$vCompare = $('#vCompare').detach();
in your media queries, Later you can use this depending upon your media queries. for more info look .detach() | jQuery. hope this would help you.
When you add the item to the page, try storing it as a variable first and then adding it from there, somewhat like this:
var vCompare = $("<div/>",{id:"vCompare"});
vCompare.appendTo("body");
The div object will be stored in the variable vCompare, so you can still remove it with .remove();:
$('#vCompare').remove();
And then add it back later with the .appendTo(); line seen in the first code snippet.
Hope this helps!
Yes, you should use append here. But before you should get proper position from where you removing the element. You can do it via .index()
So, when you want to restore removed element, use .before() on the found by index element.
If lists, or whatever, have a big difference between mobile and desktop, I'd prefer to create two lists, one of which is shown for mobile and another for desktop.
I have 5 windowDiv on my page that have a button with id "#button". The button's purpose is to change the size of the windowDiv. The windowDiv has a large version (called windowDiv) and a small version (windowDivSmall).
The top container div of the page is called topContainerDiv.
The problem is that I can't get this to work for just one windowDiv, let alone all 5 of them. I know I need to use topContainer.replaceChild(windowDiv, windowDivSmall); but I just can't get it to work.
What I currently have is the following:
$("#button").click(function() {
$(topContainerDiv).replaceChild(this.windowDivSmall, this.windowDiv);
// The code above is broken and doesn't work. Help!
});
I suspect you to use 5 #button.
You cannot.
change in HTML id="button" for class="button" and update your jquery :
$(".button").click(function() {
// correct jquery functions to call here :)
});
replaceChild is a JavaScript function. You are calling this function on a jQuery object. You could try the jQuery replaceWith method`: http://api.jquery.com/replaceWith/
I have a div:
<div id="div" style="height:150px; border:solid thin blue;"></div>
is there a way to retrieve the original div height? The div is resizable, so the user may have resized it before my code loads.
Note: my code is a jQuery plugin, so I have no clue about what happened to the element before my plugin is called (so please don't tell me to store height in element data...)
jqFiddle in this demo, I want to get the 150 after resizing the div.
Any help would be greatly appreciated!
No, because resizable() method override inline style height value.
You need to store it somewhere else.
For example before making div resizable:
var originalHeight = $('#div').height();
$('#div').resizable();
$('#cmd').button().click(function(){
alert(originalHeight);
});
I don't know of a way to get old data from the DOM, but could you not insist on the plugin having an init function called and get the values then? You could also advise in your documentation that the elements not be moved until you've completed the init function, although if it's called via .ready() this should occur before the user has a chance to blink anyway.
How is the div resizable, using jquery-ui?
Another option might be to get the page again using ajax and then parse the page, but it would be a lot of effort and very messy.
originalHeight=0;
$(document).ready(function()
{
originalHeight= $("#div").height()
});
I'm working with on developing one of the social networking site and its having some notification features in left panel.
Whenever any user have played a game it will automatically change the number of notification count.
For that i have using below code line.
jQuery('#count_id').load('mypage.php');
But it will retrieve me whole site content with header,footer and content area in the response text, which is wrong as per my requirements.
but if i used below code of line
jQuery('#count_id').load('mypage.php #count_id');
then it will retrieve me a real count but add another div in between the original,
Original html:
<div id="count_id" class="notify">2</div>
and Code after retrieving response:
<div id="count_id" class="notify">
<div id="count_id" class="notify">1</div>
</div>
which is also not as expected. count are right but i don't want to add new div inside a original one.
What should i need to change in my code?
Thanks.
jQuery('#count_id').load('mypage.php #count_id > *');
That would bring only the DOM childs (the content)
Because this is how it works. Also it enables you to attach events to the element you load and delegate them inside this element (so new elements can also benefit from attached JavaScript events) - see .delegate().
If you want to replace the element, you can try the following:
jQuery.get('mypage.php', function(data){
jQuery('#count_id').replace(jQuery(data).find('#count_id'));
}, 'html');
I did not test it, but it should work.
Ivan Castellanos is however right. According to the documentation, you can provide any selector after the first space in the .load()'s parameter.
To retrieve count_id, you can directly get the html value in the div like this:
<script type='text/javascript'>
jQuery(document).ready(function()
{
countVal = $("#count_id").html(); //returns the html content inside the div, which is the count value
countVal = parseInt(countVal); //This will convert the string to type integer
});
</script>
Note:
If you want increase the count and update the div value, you can add the following lines:
countVal++;
$("#count_id").html(countVal);