is it possible to add my blogposts to JCarousel instead of a html code? It should look like this:
=> EXAMPLE
On this site the content is just html, but I want my blogpost to show off.
Let's say I wrote 5 blogposts, so the Slider must show me the 5 blogposts.
Hope someone can help me out!
Greetings
Nico
You'll need to create a macro (xslt or razor) that will display your blog post nodes and then target them with jquery to load the jcarousel. Below is an example of a razor script that does this using the code from the example you referenced:
#using umbraco.MacroEngines
#inherits DynamicNodeContext
#try
{
<script type="text/javascript" src="http://www.fdp-bw.de/jcarousel/lib/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="http://www.fdp-bw.de/jcarousel/lib/jquery.jcarousel.pack.js"></script>
<link rel="stylesheet" type="text/css" href="http://www.fdp-bw.de/jcarousel/lib/jquery.jcarousel.css" />
<link rel="stylesheet" type="text/css" href="http://www.fdp-bw.de/jcarousel/skins/tango/skin.css" />
<style type="text/css">
/**
* Additional styles for the controls.
*/
.jcarousel-control {
margin-bottom: 10px;
text-align: center;
}
.jcarousel-control a {
font-size: 75%;
text-decoration: none;
padding: 0 5px;
margin: 0 0 5px 0;
border: 1px solid #fff;
color: #eee;
background-color: #4088b8;
font-weight: bold;
}
.jcarousel-control a:focus,
.jcarousel-control a:active {
outline: none;
}
.jcarousel-scroll {
margin-top: 10px;
text-align: center;
}
.jcarousel-scroll form {
margin: 0;
padding: 0;
}
.jcarousel-scroll select {
font-size: 75%;
}
#mycarousel-next,
#mycarousel-prev {
cursor: pointer;
margin-bottom: -10px;
text-decoration: underline;
font-size: 11px;
}
</style>
<script type="text/javascript">
/**
* We use the initCallback callback
* to assign functionality to the controls
*/
function mycarousel_initCallback(carousel) {
jQuery('.jcarousel-control a').bind('click', function () {
carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
return false;
});
jQuery('.jcarousel-scroll select').bind('change', function () {
carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
return false;
});
jQuery('#mycarousel-next').bind('click', function () {
carousel.next();
return false;
});
jQuery('#mycarousel-prev').bind('click', function () {
carousel.prev();
return false;
});
};
// Ride the carousel...
jQuery(document).ready(function () {
jQuery("#mycarousel").jcarousel({
scroll: 1,
visible: 1,
auto: 10,
wrap: "last",
initCallback: mycarousel_initCallback,
// This tells jCarousel NOT to autobuild prev/next buttons
buttonNextHTML: null,
buttonPrevHTML: null
});
});
</script>
<div id="mycarousel" class="jcarousel-skin-tango">
<ul>
#foreach (var post in Model.AncestorOrSelf().Descendants("umbBlogPost"))
{
<li>
<h2>#post.Name</h2>
<div>#post.bodyText</div>
</li>
}
</ul>
<div class="jcarousel-control">
#for (int i = 0; i < Model.AncestorOrSelf().Descendants("umbBlogPost").Count(); i++)
{
#(i + 1)
}
</div>
</div>
}
catch (Exception e)
{
<!-- #e.ToString() -->
}
That will give you all of the posts. You may want to do some ordering and filtering and then get the top five or whatever:
var posts = Model.AncestorOrSelf().Descendants("umbBlogPost").OrderBy("PostDate desc").Take(5);
Related
I've just started some days ago working with JQuery UI to allow some drag and drop and sorting on my homepage. In the code shown below, i wanted to add "+" and "-" to correct the equation "1_2_3=6", so the "+" has to been dropped two times to make the equation correct.
At the moment, it nearly works perfect. I can add as many "+" and "-" as I want, I can sort them into the equation. The only problem is, that I cannot remove any "+" or "-".
Can you give me any hint, how to be able to remove the signs by moving them out of the sortable window?
Thanks for your help!
<html>
<head>
<style>
#draggable { list-style-type: none; margin: 0; padding: 0; }
#draggable li { display: inline-block; margin: 1%; padding: 1%; font-size: 10vw; text-align:center; min-width:20px; border-style: solid; border-width: medium; border-color:black; background-color:grey;}
#sortable { float:left; list-style-type: none; width:100%; }
#sortable li { display: inline-block; margin: 0; padding: 0; font-size: 10vw; text-align:center; min-width:20px;}
</style>
<script src="jquery-1.12.4.js"></script>
<script src="jquery-ui.min.js"></script>
<script>
$( function() {
$( ".clone").draggable({
cursor:"move",
revert: "invalid",
connectToSortable: '#sortable',
helper: 'clone'
});
$( "#sortable").sortable({
connectWith: "ul",
cancel: ".ui-state-disabled",
});
} );
</script>
</head>
<body>
<ul id="draggable">
<li class="clone">+</li>
<li class="clone">-</li>
</ul>
<ul id="sortable">
<li class="ui-state-disabled">1</li>
<li class="ui-state-disabled">2</li>
<li class="ui-state-disabled">3=6</li>
</ul>
</body>
</html>
You can create a div when the UI components are dropped into the div you can remove the dropped component.
Sample code.
//HTML
<div class="removeDiv">
<p>Drop to remove</p>
</div>
//Style
.removeDiv{
width:100px;
height:100px;
background-color:red;
margin-top:150px;
}
//Script
$('.removeDiv').droppable({
over: function(event, ui) {
ui.draggable.remove();
}
});
This should get your work done.
Here's a fiddle for the above code. JS Fiddle
Expanding on my comment. Your code may look something like this.
$(function() {
$(".clone").draggable({
cursor: "move",
revert: "invalid",
connectToSortable: '#sortable',
helper: 'clone'
});
$("#sortable").sortable({
connectWith: "ul",
cancel: ".ui-state-disabled",
});
$(".trash").droppable({
accept: "#sortable > li",
classes: {
"ui-droppable-hover": "ui-state-highlight"
},
drop: function(event, ui) {
deleteItem(ui.draggable);
}
});
function deleteItem($o) {
$o.fadeOut().remove();
}
});
#draggable {
list-style-type: none;
margin: 0;
padding: 0;
}
#draggable li {
display: inline-block;
margin: 1%;
padding: 1%;
font-size: 10vw;
text-align: center;
min-width: 20px;
border-style: solid;
border-width: medium;
border-color: black;
background-color: grey;
}
#sortable {
list-style-type: none;
width: 100%;
}
#sortable li {
display: inline-block;
margin: 0;
padding: 0;
font-size: 10vw;
text-align: center;
min-width: 20px;
}
.trash {
width: 50px;
height: 50px;
border: 1px solid #000;
border-radius: 6px;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div class="drag-items" style="display: block;">
<ul id="draggable">
<li class="clone">+</li>
<li class="clone">-</li>
</ul>
</div>
<div class="problem" style="display: block;">
<ul id="sortable">
<li class="ui-state-disabled">1</li>
<li class="ui-state-disabled">2</li>
<li class="ui-state-disabled">3=6</li>
</ul>
</div>
<div class="trash">
<span class="ui-icon ui-icon-trash"></span>
</div>
In this code, add a small section for items to be dragged to and when they are dropped, they are removed. Also has visual feedback.
I have a jQuery tab, I have some tabs. I have a jquery-ui accordion with two panels, section 1 and section 2 in the first tab. Also another accordion with two panels in the second tab. For some reason, the panels' (divs within h3 tags) height for accordion on second tab are set to 0px and display:none and vertical scroll is appearing for both panels as i have seen with internet explorer debugger (see image attached in the link): http://snag.gy/6pmYd.jpg
The problem is only with the accordion on the second tab: panels are not resized to the tallest one. is it a bug of jQuery tab?
<style>
/* IE has layout issues when sorting (see #5413) */
.group { zoom: 1 }
</style>
<div id="tabs">
<ul>
<li>Components</li>
<li>Capsules</li>
</ul>
<div id="ComponentsTab">
<div id="accordion"> <!-- style= "width: 790px;" -->
<div class="group">
<!-- First Panel 'Add Component' -->
<h3>Add component</h3>
<div>
#using (Html.BeginForm("AddField", "Configure", FormMethod.Post))
{
<label id="NumberOfItems" for="amount">#Resource.ComponentNumberOfItems</label>
<input type="text" name="amount" id="amount" />
<div id="slider-range-max"></div>
<div id="componentId">
#Html.LabelFor(m => m.ComponentViewModel.SelectedCompTypeId, new { #id = "componentIdLabel" })
#Html.DropDownListFor(m => m.ComponentViewModel.SelectedCompTypeId,
Model.ComponentViewModel.CompTypeItems)
</div>
<div class="componentGroup">
<label id="NameCompLabel" for="NameComp">Name:</label>
#Html.TextBox("NameComp", null, new { #class = "textStyle" })
</div>
<div class="componentGroup">
<label id="DescCompLabel" for="DescComp">Description:</label>
#Html.TextBox("DescComp", null, new { #class = "textStyle" })
</div>
<div class="componentGroup">
<input id="submitAddComp" type="submit" value="#Resource.ButtonTitleAddComponent" />
</div>
}
</div> <!-- end first panel 'Add Component' -->
</div> <!-- end group -->
<div class="group">
<!-- Second Panel 'Filter' -->
<h3>Filters</h3>
<div>
#using (Ajax.BeginForm("Search", "Component",
new AjaxOptions
{
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "jqGrid",
OnSuccess = "showGrid()"
}))
{
<!-- Drop down list for component types -->
<div id = "componentTypeFilter">
#Html.LabelFor(m => m.ComponentViewModel.SelectedCompTypeId, new { id = "componentFilterLabel" })
#Html.DropDownListFor(m => m.ComponentViewModel.SelectedCompTypeId, Model.ComponentViewModel.CompTypeItems)
</div>
<!-- Apply filter button for components -->
<div id="ApplyFilterComponents" >
<input type="submit" name="_search" value="#Resource.CaptionComponentApplyFilter" />
</div>
}
</div>
</div> <!--end group -->
</div> <!-- end accordion -->
<!--
<div id="jqGrid">
#Html.Partial("../Grids/_ComponentGrid")
</div>
-->
</div> <!-- End First tab -->
<div id="OthersTab">
<div id="accordion2"> <!-- style ="width: 790px;" -->
<div class="group">
<h3>Add others</h3>
<div>
#using (Html.BeginForm("AddOthers", "Configure", FormMethod.Post))
{
<div id="itemId">
#Html.LabelFor(m => m.ItemViewModel.SelectedItemTypeId, new { #id = "itemIdLabel" })
#Html.DropDownListFor(m => m.ItemViewModel.SelectedItemTypeId,
Model.ItemViewModel.TypeItems)
</div>
<div class="itemGroup">
<label id="NameItemLabel" for="NameItem">Name:</label>
#Html.TextBox("NameItem", null, new { #class = "textStyle" })
</div>
<div class="itemGroup">
<label id="DescItemLabel" for="DescItem">Description:</label>
#Html.TextBox("DescItem", null, new { #class = "textStyle" })
</div>
<div class="itemGroup">
<input id="submitAddItem" type="submit" value="#Resource.ButtonTitleAddItem" />
</div>
}
</div>
</div> <!--end group -->
<div class="group">
<h3>Filters</h3>
<div>
#using (Ajax.BeginForm("Search", "Items",
new AjaxOptions
{
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "jqGridItems",
OnSuccess = "showGridItems()"
}))
{
<!-- Drop down list of item types -->
<div id = "itemTypeFilter">
#Html.LabelFor(m => m.ItemViewModel.SelectedItemTypeId, new { id = "itemFilterLabel" })
#Html.DropDownListFor(m => m.ItemViewModel.SelectedItemTypeId,
Model.ItemViewModel.TypeItems)
</div>
<!-- Apply filter button for items -->
<div id="ApplyFilterItems" >
<input type="submit" name="_search" value="#Resource.CaptionItemsApplyFilter" />
</div>
}
</div>
</div> <!-- end group -->
</div> <!-- end accordion -->
<!--
<div id="jqGridItems">
#Html.Partial("../Grids/_ItemsGrid")
</div>
-->
</div> <!-- end second tab -->
</div> <!-- End tabs -->
SCRIPTS:
<script type="text/javascript" src="#Url.Content("~/Scripts/jquery-1.9.1.js")"></script>
<script type="text/javascript">
// -------------------------------------------------------------------------------------------------
// Slider functionality
// -------------------------------------------------------------------------------------------------
$(function () {
$("#slider-range-max").slider({
range: "max",
min: 1,
max: 255,
value: 1,
slide: function (event, ui) {
$("#amount").val(ui.value);
}
});
$("#amount").val($("#slider-range-max").slider("value"));
});
function showTabs() {
$("#tabs").tabs ();
};
$(document).ready(function () {
showTabs();
});
// Below makes tabs sortable (Their position can be altered)
$(function () {
var tabs = $("#tabs").tabs();
tabs.find(".ui-tabs-nav").sortable({
axis: "x",
stop: function () {
tabs.tabs("refresh");
}
});
});
$(function () {
function subscribe_accordion_to_hoverintent_event(accordionId) {
$(accordionId).accordion({
header: "> div > h3",
event: "click hoverintent"
});
}
subscribe_accordion_to_hoverintent_event("#accordion");
subscribe_accordion_to_hoverintent_event("#accordion2");
});
// Collapse content
$(function () {
function set_accordion_as_collapsible(accordionId) {
$(accordionId).accordion({
collapsible: true//,
//eightStyle: "auto"
});
}
set_accordion_as_collapsible("#accordion");
set_accordion_as_collapsible("#accordion2");
});
// Sortable functionality
$(function () {
function set_accordion_as_sortable(accordionId) {
$(accordionId).sortable({
axis: "y",
handle: "h3",
stop: function (event, ui) {
// IE doesn't register the blur when sorting
// so trigger focusout handlers to remove .ui-state-focus
ui.item.children("h3").triggerHandler("focusout");
}
});
}
set_accordion_as_sortable("#accordion");
set_accordion_as_sortable("#accordion2");
});
/*
* hoverIntent | Copyright 2011 Brian Cherne
* http://cherne.net/brian/resources/jquery.hoverIntent.html
* modified by the jQuery UI team
*/
$.event.special.hoverintent = {
setup: function () {
$(this).bind("mouseover", jQuery.event.special.hoverintent.handler);
},
teardown: function () {
$(this).unbind("mouseover", jQuery.event.special.hoverintent.handler);
},
handler: function (event) {
var currentX, currentY, timeout,
args = arguments,
target = $(event.target),
previousX = event.pageX,
previousY = event.pageY;
function track(event) {
currentX = event.pageX;
currentY = event.pageY;
};
function clear() {
target
.unbind("mousemove", track)
.unbind("mouseout", clear);
clearTimeout(timeout);
}
function handler() {
var prop,
orig = event;
if ((Math.abs(previousX - currentX) +
Math.abs(previousY - currentY)) < 7) {
clear();
event = $.Event("hoverintent");
for (prop in orig) {
if (!(prop in event)) {
event[prop] = orig[prop];
}
}
// Prevent accessing the original event since the new event
// is fired asynchronously and the old event is no longer
// usable (#6028)
delete event.originalEvent;
target.trigger(event);
} else {
previousX = currentX;
previousY = currentY;
timeout = setTimeout(handler, 100);
}
}
timeout = setTimeout(handler, 100);
target.bind({
mousemove: track,
mouseout: clear
});
}
};
</script>
CSS:
.elementStatus
{
visibility: hidden;
}
.image{
/*float: left;
margin-top: 2px;
padding-top: 1px;
padding-left: 10px;
width: 35px;*/
margin-top: 5px;
text-align: center;
vertical-align: middle;
}
.text{
/*float: left;
margin-top: 1px;
padding-left: 14px;
padding-bottom: 2px;
width: 35%;*/
font-weight: bold;
font-size: 1em;
text-align: center;
vertical-align: middle;
margin-bottom: 2px;
}
#accordion2 .ui-accordion-content
{
max-height: 400px;
overflow-y: auto;
}
#accordion, #accordion2
{
width: 790px;
padding-top: 10px;
margin-top: 10px;
margin-left: 0px;
margin-right: 0px;
}
#ComponentTypeFilterLabel
{
font-size: 1em;
margin-top: 11px;
float: left;
}
#componentTypeFilter, #itemTypeFilter
{
margin-top: 10px;
margin-left: 12px;
float: left;
}
#ApplyFilterComponents, #ApplyFilterItems
{
padding-left: 20px;
float: left;
}
#ApplyFilterComponents input, #ApplyFilterItems input
{
margin-top: 22px;
font-size: 1em;
}
#NumberOfItems
{
text-align: left;
width: 150px;
float: left;
margin-right: 1px;
padding-top: 5px;
font-size: 1em;
}
#amount
{
text-align: left;
color: #f6931f;
font-weight: bold;
border-top-color: currentColor;
border-right-color: currentColor;
border-bottom-color: currentColor;
border-left-color: currentColor;
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
margin-top: 0px;
margin-left: 1px;
width: 555px;
padding-top: 5px;
padding-left: 5px;
padding-right: 1px;
margin-right: 1px;
}
#componentFilterLabel, #itemFilterLabel
{
font-size: 1em;
}
#componentId, #itemId
{
height: 55px;
font-size: 1em;
float: left;
text-align: left;
font-weight: 600;
}
#componentIdLabel, #itemIdLabel
{
margin-bottom: 5px;
height: 21px;
margin-top: 25px;/*0px; */
padding-bottom: 0px;
font-size: 1em;
}
#NameCompLabel, #NameItemLabel
{
margin-left: 0px;
margin-top: 25px;
padding-left: 14px;
font-size: 1em;
}
#DescCompLabel, #DescItemLabel
{
margin-left: 5px;
margin-top: 25px;
padding-left: 10px;
font-size: 1em;
}
#NameComp, #NameItem
{
float: left;
margin-left: 15px;
margin-top: 0px;
font-size: 1em;
}
#DescComp, #DescItem
{
float: left;
margin-top: 0px;
margin-left: 15px;
font-size: 1em;
}
#submitAddComp, #submitAddItem
{
margin-top: 40px;
margin-left: 15px;
font-size: 1em;
}
.componentGroup, .itemGroup
{
float: left;
}
.textStyle
{
width : 150px;
}
this cause to make visible vertical scroll bars in each panel that I do not want that.
so If I uncheck those attributes from ie dev tools (debugger) then all panels will be set to the height of the tallest panel that is what i want. So how to set it in the divs? with inline style or css?
ALMOST WORKING:
I have upated my script, now it is almost working. What I have done is to modify the code inside $(document).ready(...), see below:
$(document).ready(function () {
var tabs = $("#tabs").tabs({
activate: function (event, ui) {
$("#accordion2").accordion({
activate: function (event, ui) {
$(ui.newPanel).css('height', '100');
$(ui.newPanel).css('min-height', '100');
$(ui.newPanel).css('max-height', '400');
}
}); // End Accordion
} // End Activate tab
}); // End tabs
tabs.find(".ui-tabs-nav").sortable({
axis: "x",
stop: function () {
tabs.tabs("refresh");
}
});
});
The rest of code is kept the same as posted here above.
The problem now is the following: Initially first tab is active, and so first accordion shown with its first panel activated and expanded. Then when I switch to second tab, ONLY THE FIRST TIME, second accordion (accordion2) is show and its first panel activated, but the panel is not adjusting to its content: it is showing vertical scroll bar and i do not want that. Then If i switch to first tab and then again to second tab, then it works, accordion2 is activated and its first panel activated and shown, no vertical scroll bar is appearing and panel it is adjusting perfectly to its content. The problem is the first time i am switching from first tab to second tab where accordion2 is. So how to force panel for accordion2 to be adjusted to its content?
FINAL SOLUTION
$(document).ready(function () {
$("#accordion2").accordion({
header: "> div > h3",
event: "click hoverintent",
collapsible: true
});
var tabs = $("#tabs").tabs();
});
and in css file:
#accordion2 .ui-accordion-content
{
height: 100px;
max-height: 400px;
}
Please, do not downvote!
$("#DivName" ).accordion({
heightStyle: "content"
});
This is certainly what you and me are looking for. HeightStyle set to 'content' solved my issue.
The reason for height being set to 0 is because the other tabs are hidden and height gets calculated dynamically when accordion plugin is constructed. one way to solve the issue is use the tab activate event and construct the accordion only when the tab is active to the hight is set correctly. [JSFiddle]http://jsfiddle.net/8tBtR/
$(function(){
$( "#tabs" ).tabs({
activate: function( event, ui ) {
if((ui.newPanel.attr('id') === 'tabs-2') && (checkIfNotAccordion) )
{
$('#accordion2').accordion();
}
}
});
});
I created a jquery combobox which even when I open it using the button I want it to close when clicking on the page body. I'm using jQuery v1.10.1 and jQuery UI v1.10.3. When I originally wrote it I was using v111 and I had an onclick in the body to close it but when I upgraded the auto-complete never stayed open. I tried to make a jfiddle http://jsfiddle.net/abakoltuv/Lmbdn/ but the button doesn't work at all.
local css:
.textbox, input.combobox {
border: 1px solid #666666;
color: black;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
}
span.combobox {
border-bottom: 1px solid #666666;
border-right: 1px solid #666666;
border-top: 1px solid #666666;
cursor: pointer;
display: inline-block;
font-size: 10px;
height: 8px;
padding: 2px 2px 4px;
position: relative;
top: 1px;
width: 10px;
}
<b>Brand</b><br />
<input type="text" onChange="setChangedFlag()" field="BRAND_ID" value="" id="BRAND_ID_display" name="BRAND_ID_display" size="22" class="combobox" style="width: 121px;"><span onClick="click_combobox_open('BRAND_ID_display')" class="combobox">▼</span>
<br /><input type="text" value="" id="BRAND_ID" name="BRAND_ID" style="background-color:#CCCCCC" class="textbox" size="22">
<script language="javascript" type="text/javascript">
<!--
$(document).ready(function() {
setup_combobox();
});
function setup_combobox()
{
var largest_size;
var data = [{"id":"1","value":"Able Planet"},{"id":"86","value":"Able Planet 123"},{"id":"2","value":"Acecad"},{"id":"3","value":"Action Life Media"},{"id":"4","value":"Adobe"},{"id":"5","value":"Bose"},{"id":"6","value":"Canon"},{"id":"7","value":"Delkin"}];
$("input.combobox").autocomplete({
html: 'html',
minLength: 0,
source: data ,
select: function(event, ui) {
if (ui.item) {
var width1 = $('#'+this.id).width();
$('#'+this.id).width((ui.item.value.length * 2/3) + 'em');
var width2 = $('#'+this.id).width();
if(width1 > width2)
$('#'+this.id).width(width1);
$('#'+this.id.substring(0, this.id.length - 8)).val(ui.item.id);
};
}
});
}
function click_combobox_open(display_ID)
{
var width1 = $('#'+display_ID).width();
$('#'+display_ID).width(($('#'+display_ID).val().length * 2/3) + 'em');
var width2 = $('#'+display_ID).width();
if(width1 > width2)
$('#'+display_ID).width(width1);
else
$('#'+display_ID).width(width2);
if(!$('#'+display_ID).autocomplete('widget').is(':visible'))
{
$('#'+display_ID).autocomplete('search','');
}
else
{
$('#'+display_ID).autocomplete('close');
}
}
//-->
</script>
Thanks
Aba
I finally figured it out I just needed to focus on the text box after opening it.
function click_combobox_open(display_ID)
{
var width1 = $('#'+display_ID).width();
$('#'+display_ID).width(($('#'+display_ID).val().length * 2/3) + 'em');
var width2 = $('#'+display_ID).width();
if(width1 > width2)
$('#'+display_ID).width(width1);
else
$('#'+display_ID).width(width2);
if(!$('#'+display_ID).autocomplete('widget').is(':visible'))
{
$('#'+display_ID).autocomplete('search','');
**$('#'+display_ID).focus();**
}
else
{
$('#'+display_ID).autocomplete('close');
}
}
I've learned how to create a jquery ui tab, thanks to http://jqueryui.com/tabs, and customized the look of it. I've been searching the web on how to highlight a selected tab by changing it's background color when someone clicks on it. So far, it's been frustrated and unsuccessful.
Here's the HTML Code Use:
<!DOCTYPE html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" >
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.js"></script>
<script>
$(function() {
$( "#tabs" ).tabs();
});
</script>
<title>Jquery Tab Test</title>
</head>
<body>
<div id="tab-wrapper">
<div id="tabs">
<ul>
<li>Tab 1</li>
<li>Tab 2</li>
<li>Tab 3</li>
</ul>
<br class="clearboth" />
<div id="tabs1" class="tab-content">
Content 1
</div>
<div id="tabs2" class="tab-content">
Content 2
</div>
<div id="tabs3" class="tab-content tabs3">
Content 3
</div>
</div>
</div>
</body>
and CSS:
body, html {
height: 101%;
}
body {
font-family: arial;
}
.clearboth {
clear: both;
padding: 0;
margin: 0;
}
#tab-wrapper {
background-color: #f00fff;
border: solid 1px #909090;
padding: 5px;
width: 330px;
}
#tabs {
overflow: hidden;
}
#tabs ul li,
#tabs ul {
margin: 0;
padding: 0;
list-style: none;
}
#tabs ul a {
float: left;
padding: 5px;
display: block;
width: 100px;
text-align: center;
text-decoration: none;
color: #000000;
height: 20px;
line-height: 20px;
font-size: 10pt;
font-weight: bold;
background-color: #cccccc;
}
#tabs ul a:hover {
background-color: #f1f1f1;
}
#tabs .tab-content {
padding: 5px;
display: block;
background-color: #f1f1f1;
font-size: 10pt;
height: 300px;
border-top: solid 1px #000000;
}
Please help if anyone can.
Jquery assigns the selected tab the class="ui-tabs-active" so to style it simply hook your css into it as follows:
#tabs .ui-tabs-active {
background: yellow;
}
This works for me:
#tabs .ui-tabs-active {
background: yellow;
}
but the above answer did not - the order in the css file is important - the above is after hover.
I am trying to show Jquery UI tooltip on page load with a close/cross mark icon inside tool tip content. Tooltip should be closed on clicking X icon. I dont want to use any plugins. Please suggest logic.
Tried the below code to hide tooltip after 5 seconds.
var dur=5000;
$(document).tooltip({
show:{
effect:'slideDown'
},
track:true,
open: function( event, ui ) {
setTimeout(function(){
$(ui.tooltip).hide();
}, dur);
}
});
Tried below code to Show tooltip
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function () {
$(document).tooltip({
position: {
using: function (position, feedback) {
$(this).css(position);
$("<div>")
.addClass("arrow")
.addClass(feedback.vertical)
.addClass(feedback.horizontal)
.appendTo(this);
}
}
});
});
</script>
<style>
.ui-tooltip, .arrow:after {
background: black;
}
.ui-tooltip {
padding: 10px 20px;
color: white;
font: 8px "Helvetica Neue", Sans-Serif;
text-transform: uppercase;
}
.arrow {
width: 70px;
height: 16px;
overflow: hidden;
position: absolute;
left: 50%;
margin-left: -35px;
bottom: -16px;
}
.arrow.top {
top: -16px;
bottom: auto;
}
.arrow.left {
left: 80%;
}
.arrow:after {
content: "";
position: absolute;
left: 20px;
top: -20px;
width: 25px;
height: 25px;
box-shadow: 6px 5px 9px -9px black;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
tranform: rotate(45deg);
}
.arrow.top:after {
bottom: -20px;
top: auto;
}
</style>
</head>
<body>
<p title="Sample Tool Tip Text">Tooltips</p>
</body>
</html>
If you want to use the tooltip in this manner, you cannot use $(document).tooltip(). Instead, you would have to use $(selector).tooltip().focus(), which will force the tooltip open.
Then you would need to bind a click event and do the following: $(selector).tooltip("destroy").
Using your jsfiddle, I've done the following changes:
HTML:
<p id="p1" title="Sample Tool Tip Text">Tooltips</p>
JAVASCRIPT:
$(function () {
$("#p1").tooltip({
items: "p", //use this to override content - in this example, I am using "p" but you can also use classes/id's/etc
content: function (){
if ($(this).is("p") ) {
var text = $(this).attr("title");
return text + '<span style="position:absolute;top:0;right:0;" class="tooltipClose ui-icon ui-icon-circle-close"></span>';
}
},
position: {
using: function (position, feedback) {
$(this).css(position);
$("<div>")
.addClass("arrow")
.addClass(feedback.vertical)
.addClass(feedback.horizontal)
.appendTo(this);
}
}
}).focus();
$(".tooltipClose").click(function(){
$("#p1").tooltip("destroy");
});
});
Here is a demo: http://jsfiddle.net/u8kX9/9/
Hope this is what you're looking for! Let me know if you need anything else!