I'm trying to modify the tree control example so that it nests ul's inside an li, this is my template:
template:
'<li>' +
'{{if folders && folders.length}}' +
'<span class="toggle">{^{:expanded ? "-" : "+"}}</span>' +
'{{else}}' +
'<span class="spacer">•</span>' +
'{{/if}}' +
'{{>name}}' +
'{^{if expanded}}' +
'<ul>' +
'{{for folders}}' +
'{^{tree/}}' +
'{{/for}}' +
'</ul>' +
'{{/if}}' +
'</li>',
And my tag is:
{^{tree _data/}}
This produces the desired html - but also raises a second click event which subsequently collapses the just expanded list items?
Any help appreciated, thanks.
This is because you have combined two <li>s into one, and the event bubbling of the click event is now triggering other toggle events on tree nodes higher up. (Before, the self.contents("li").first() selector was ensuring that a bubble click event from deeper down was not captured. But now deeper nodes are under the same li as the parent nodes.)
So one fix is to prevent bubbling. Return false from the handler (or call event.stopPropagation()).
self.contents("li")
.on("click", ".toggle", function() {
self.toggle();
return false;
});
Another is to associate the click event with the span, not the li, so it doesn't find multiple .toggle targets:
var self = this;
self.contents("li").find(".toggle")
.on("click", function() {
self.toggle();
});
Another alternative is to use the {{on}} tag binding for the click handler. In fact the whole implementation is then simpler:
$.views.tags({
tree: {
template: '<li>' +
'{{if folders && folders.length}}' +
'<span data-link="{on ~tag.toggle} {:expanded ? \'-\' : \'+\'}" class="toggle"></span>' +
'{{else}}' +
'<span class="spacer">•</span>' +
'{{/if}}' +
'{{>name}}' +
'{^{if expanded}}' +
'<ul>' +
'{{for folders}}' +
'{{tree/}}' +
'{{/for}}' +
'</ul>' +
'{{/if}}' +
'</li>',
//METHODS
toggle: function() {
var data = this.tagCtx.view.data;
$.observable(data).setProperty("expanded", !data.expanded);
}
}
});
I will probably switch the sample to take this approach...
Related
hello someone can help me with this ?
I what to change my process indicator from SAPUI5 to make something like this
enter image description here
the idea is show how much percent are favor about something and how much percent is against
thanks
you can create a custom control like this or added some code to the onAfterRendering event.
ProgressIndicator.extend("ProgressIndicatorEx", {
renderer: {},
onAfterRendering: function() {
if (ProgressIndicator.prototype.onAfterRendering) {
ProgressIndicator.prototype.onAfterRendering.apply(this, arguments);
}
var percentValue = this.getPercentValue();
this.$().find("#" + this.getId() + "-bar").html('<span id="' + this.getId() + '-textLeft" class="sapMPIText sapMPITextRight" style="color: #FFF; margin-right:8px">' + percentValue + '%</span>');
var rightBar = this.$().find("#" + this.getId() + "-remainingBar");
rightBar.html('<span id="' + this.getId() + '-textRight" class="sapMPIText sapMPITextRight" style="color: #FFF">' + (100 - percentValue) + '%</span>');
rightBar.css("background-color", "#c00")
rightBar.css("border-color", "#c00")
}
demo: https://jsbin.com/yawiqam/edit?js,output
I have FullCalendar up and running on my site with the events being pulled from google calendars. It all works great, except when I switch to the yearList view. Yes it shows all of the events properly, but I was wondering if there is a way to have it focus on the closest event to the current date
i.e. it's July and when you switch to listYear view it starts at January.
I don't want to disable past events or anything like that.
So I guess the question is: Can you get the closest event to the current date, and have the list scrollTop to that event?
Any help would be greatly appreciated!
in action:
www.pvband.org/schedule/
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,listYear'
},
displayEventTime: true,
displayEventEnd: true,
//removed google api key and cal events for this snipet
eventClick: function(event) {
if (event.url) {
var fancyContent = ('<div><div class="eventDetailsHeader">Event Details</div> <div class="eventDetails"> <label><b>Event: </b></label>' + event.title + '<br>' + '<label><b>Date: </b></label>' + event.start.format('ddd, MMM DD, YYYY') + '<br>' + '<label><b>Start Time: </b></label>' + event.start.format('h:mm a') + '<br>' + '<label><b>End Time: </b></label>' + event.end.format('h:mm a') + '<br>' + '<label><b>Location: </b></label>' + event.location + '<br>' + '</div></div>');
$.fancybox.open({
src : fancyContent,
type : 'html',
})
return false;
}
},
loading: function(bool) {
$('#loading').toggle(bool);
}
});
I'm working on a small app where the user move the background with his mouse or his finger on the screen.
You can find a demo here: http://kaleidoscope-experiment.herokuapp.com/
The background-position is defined by the position of the cursor/finger using this kind of code:
// mobile
position = e.touches[0].pageX + 'px ' + e.touches[0].pageY + 'px';
// desktop
position = e.pageX + 'px ' + e.pageY + 'px';
However, I have significant lags on mobile and tablet and the background is "clipping".
Do you know if there is any alternative to background-position (transform?), to move the background based on the cursor/mouse position?
If you want to roll your own just use a combination of the jQuery mousemove function in combination with CSS3 transforms. Something along the lines of this:
$( "#target" ).mousemove(function( event ) {
var msg = "Handler for .mousemove() called at ";
msg += event.pageX + ", " + event.pageY;
console.log( "<div>" + msg + "</div>" );
$("#movingobject").css('transform', 'translate(' + event.pageY /4 + 'px,' + -event.pageX /4+ 'px)');
});
Here is the reference fiddle that i got from stackoverflow
http://jsfiddle.net/ZmZhw/
There are number of js plugin that are available which will give u some smooth transition and performance also.
I have a map drawn using leaflet. In that map I have drawn several markers at different locations. On clicking the marker I am creating a popup div that shows some message.
I have the code:
markers.on("click", function(d) {
div.html("This is Some info").style(
"left", (d3.event.pageX) + "px").style(
"top", (d3.event.pageY - 80) + "px");
}
So the div appears in the location where I clicked i.e. at the location of the marker.
Now if I drag the map the markers move along with the map but the div remains at the same location.
How can I change the style of div with drag event so that the div also moves along with marker?
I was trying the following code in the drag event method:
if(d.code==clickedcode)
{
console.log((map.latLngToLayerPoint([ d.lat, d.lon ]).x) + "px , "
+(map.latLngToLayerPoint([ d.lat, d.lon ]).y - 80) + "px");
div.style["left"]=(map.latLngToLayerPoint([ d.lat, d.lon ]).x) + "px";
div.style["top"]=(map.latLngToLayerPoint([ d.lat, d.lon ]).y - 80) + "px";
}
But it still shows the same pixel position as previous time.
You could try using the map 'drag' event to calculate the shift and then apply that to your div location. Something along these lines...
var startCoords;
var startLat;
var startLng;
var movedCoords;
var shiftLat;
var shiftLng;
map.on('dragstart', function() {
startCoords = map.getCenter();
startLat = startCoords.lat;
startLng = startCoords.lng;
console.log("STARTED FROM: " + startLat + "," +startLng);
});
map.on('drag', function() {
movedCoords = map.getCenter();
shiftLat = startLat - movedCoords.lat;
shiftLng = startLng - movedCoords.lng;
console.log("Shifted: " + shiftLat + "," + shiftLng);
//apply shift to custom div here...
});
I am new to jsPlumb. I have created dynamic divs by reading a table from database and I have connected these divs by using JsPlumb connectors. The divs have been made draggable. The connectors are showing up correctly when the page loads, but when I drag or move the divs the connectors breaks off and moved to top. If I create a static divs which are not coming from database then the connectors are working perfectly and when I drag/move the divs then the connectors are also moving along the divs connected to source and target divs.
After doing a complete search on google and by going through jsPlumb documents, I did not find any solution for this.
Can anyone tell me as what should be done to have the connectors stay connected to source and destination even when we drag or move the divs.
Here is what I have done:
JsPlumb Code for one connection:
jsPlumb.ready(function() {
jsPlumb.connect({
source: "FDiv1",
target: "IDiv1",
connector: ["Flowchart"],
anchors: ["RightMiddle", "LeftMiddle"],
paintStyle: {
lineWidth: 2,
strokeStyle: "rgb(189, 11, 50)",
outlineColor: "#666",
outlineWidth: 1
},
hoverPaintStyle: { strokeStyle: "#7ec3d9" },
detachable: false,
endpoint: "Blank",
endpointsOnTop: false,
deleteEndpointsOnDetach: false,
endpointStyle: { fillStyle: "#a7b04b" },
overlays: [ "Arrow" ]
});
jsPlumb.draggable($(".bg"));
});
I have hardcoded the source and target here which later I should be getting these dynamically to connect all other divs.
Here is the dynamic divs code in code behind.
foreach (DataRow dt in ds.Tables[0].Rows)
{
HtmlGenericControl myDiv = new HtmlGenericControl("div");
HtmlGenericControl myDiv2 = new HtmlGenericControl("div");
//********Source Div**************
myDiv.ID = "FDiv" + j;
myDiv.Attributes.Add("class", "bg");
myDiv.Style.Add(HtmlTextWriterStyle.MarginLeft, "30px");
myDiv.Style.Add(HtmlTextWriterStyle.MarginTop, top + "px");
myDiv.InnerHtml = "Filename: " + dt["Column1"].ToString() + "<br>" + myDiv.ID;
PlaceHolder1.Controls.Add(myDiv);
//************Target Div****************
myDiv2.ID = "IDiv" + j;
myDiv2.Attributes.Add("class", "bg");
myDiv2.Style.Add(HtmlTextWriterStyle.MarginLeft, "260px");
myDiv2.Style.Add(HtmlTextWriterStyle.MarginTop, top + "px");
myDiv2.InnerHtml = "Filename: " + dt["Column2"].ToString() + "<br>" + myDiv2.ID;
PlaceHolder1.Controls.Add(myDiv2);
top = top + 140;
j = j + 1;
}
Instead of making the DIV draggable as jsPlumb.draggable($(".bg"));
Try making the DIV draggable during its creation.
i.e.
Source Div
myDiv.ID = "FDiv" + j;
myDiv.Attributes.Add("class", "bg");
myDiv.Style.Add(HtmlTextWriterStyle.MarginLeft, "30px");
myDiv.Style.Add(HtmlTextWriterStyle.MarginTop, top + "px");
myDiv.InnerHtml = "Filename: " + dt["Column1"].ToString() + "<br>" + myDiv.ID;
jsPlumb.draggable($('#FDiv' + j)); // make it draggable
PlaceHolder1.Controls.Add(myDiv);
`
||y for target DIV
I had a similar issue with dynamically created divs and solved it by not using jsPlumb.draggable(element) but instead jQuery and jsPumb.repaint(element) as follows (the example is a bit overkill with the use of repaint but you get the picture):
element.draggable({
step: function () {
jsPlumb.repaint(element);
},
drag:function(){
jsPlumb.repaint(element);
},
stop:function(){
jsPlumb.repaint(element);
}
});
Hope this helps you.