I am working on a html5 mobile app project. I found that Onsen ui is very use full and started working on It .
Now I want to swipe between tabs like native android ui .please help
I made tab as this
<ons-tabbar position="top" >
<ons-tab page="page1.html" label="Mobile" active="true"></ons-tab>
<ons-tab page="page2.html" label="DTH"></ons-tab>
<ons-tab page="page3.html" label="Datacard"></ons-tab>
</ons-tabbar>
But how to add swipe to change between tabs.
Onsen UI doesn't have this feature. It includes the Hammer library to detect gestures, so you could listen to the drag event and switch tabs when the user drags left and right.
Something like this:
document.addEventListener('ons-tabbar:init', function(event) {
var tabbar = event.component,
el = tabbar._element[0],
nbrOfTabs = 4;
var hammer = new Hammer(el);
// Bind some events
hammer.on('drag', function(event) {
var dx = event.gesture.deltaX,
idx = tabbar.getActiveTabIndex(),
th = el.getBoundingClientRect().width / 2;
if (dx > th && idx !== -1) {
event.gesture.stopDetect();
tabbar.setActiveTab(Math.max(idx - 1, 0));
}
else if (dx < -th && idx !== -1) {
event.gesture.stopDetect();
tabbar.setActiveTab(Math.min(idx + 1, nbrOfTabs - 1));
}
});
});
http://codepen.io/argelius/pen/vELYaK
Related
I have created an onSelection changed method as per the tutorial set out here: Selection Override
i have set this up for multi-selection as well which works well.
However when I try to deselect a group selected component it doesn't trigger the onSelectionChange event as I have it coded (shown below). The method is never triggered.
But if I comment out this line:
viewerApp.getCurrentViewer().select(idsToSelect);
Then the toggle of selected components works perfectly. And triggers the onSelectionChnge event.
Any help? Is there an alternative to doing methods after the slection has changed? Possibly when a part is clicked?
The code looks like this:
viewerApp.getCurrentViewer().addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, onSelectionChanged);
function onSelectionChanged(data) {
console.log("selection changed event. Selected dbIds are: " + data.dbIdArray.toString());
if (data.dbIdArray.length > 0 && data.fragIdsArray.length > 0) {
var idsToSelect = [];
var selectionChanged = false;
for (var k = 0; k < data.dbIdArray.length; k++) {
var dbId = data.dbIdArray[k];
if (leafNodes.indexOf(dbId) > -1) {
dbId = viewerApp.getCurrentViewer().model.getData().instanceTree.nodeAccess.getParentId(dbId);
selectionChanged = true;
}
idsToSelect.push(dbId);
}
if (selectionChanged) {
viewerApp.getCurrentViewer().select(idsToSelect);
}
}
}
I have searched high and low and tried many different options from here, but i need a point in the right direction now :)
On this site:
http://www.michael-smith-engineers.co.uk
On the main nav, (in mobile view) if you click on Pumps, there should be further dropdown options, but i can not get this working. Any ideas would be appreciated.
I have tried adding the following script, without any luck...
<script>
// see whether device supports touch events (a bit simplistic, but...)
var hasTouch = ("ontouchstart" in window);
var iOS5 = /iPad|iPod|iPhone/.test(navigator.platform) && "matchMedia" in window;
// hook touch events for drop-down menus
// NB: if has touch events, then has standards event handling too
// but we don't want to run this code on iOS5+
if (hasTouch && document.querySelectorAll && !iOS5) {
var i, len, element,
dropdowns = document.querySelectorAll("#nav-site li.children > a");
function menuTouch(event) {
// toggle flag for preventing click for this link
var i, len, noclick = !(this.dataNoclick);
// reset flag on all links
for (i = 0, len = dropdowns.length; i < len; ++i) {
dropdowns[i].dataNoclick = false;
}
// set new flag value and focus on dropdown menu
this.dataNoclick = noclick;
this.focus();
}
function menuClick(event) {
// if click isn't wanted, prevent it
if (this.dataNoclick) {
event.preventDefault();
}
}
for (i = 0, len = dropdowns.length; i < len; ++i) {
element = dropdowns[i];
element.dataNoclick = false;
element.addEventListener("touchstart", menuTouch, false);
element.addEventListener("click", menuClick, false);
}
}
</script>
This script above is ridiculous for what i was trying so, tried this:
<script type="text/javascript">
function is_touch_device() {
return (('ontouchstart' in window) || (navigator.MaxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0));
}
if(is_touch_device()) {
jQuery('.toggle-menu').on('click', function(){
jQuery(this).toggleClass('activate');
jQuery(this).find('ul').slideToggle();
return false;
});
}
</script>
</head>
Still no luck tho?!!!!
how can I resize a window which is opened by a link with target_blank with Mootools?
Thank you
jsfiddle: http://jsfiddle.net/hxyTB/5/
klick
Try this:
The script/function is plain javascript and I added the event handler with Mootools ( the click event handler you have on your fiddle looks like jQuery to me). Check the function's parameters and change as you need.
Fiddle
document.getElements('a.window').addEvent('click',function(e){
e.stop();
NewWindow(this.href,'pagename','350','500','no','center');
return false
});
var win = null;
function NewWindow(mypage, myname, w, h, scroll, pos) {
if (pos == "center") {
LeftPosition = (screen.width) ? (screen.width - w) / 2 : 350;
TopPosition = (screen.height) ? (screen.height - h) / 2 : 500;
} else {
LeftPosition = 0;
TopPosition = 20
}
settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win = window.open(mypage, myname, settings);
}
You can read more about window.open() at MDN to adjust details. In the code above for example there is no url bar, and no scroll bar.
I used Mootools's .getElements(), this will work for other <a> with same class. If you have just one element you can use Mootools's .getElement(), without "s".
The title kinda says it all, i have a google maps api v3 and everything works fine except for one annoying new feature which i cant seem to fix.
You can show and hide markers by a click of a button which calls togglePOI(), but when i drag a marker and click hide and show again. All the markers appear except for the ones i have been dragging around. So the dragging seems to throw things into chaos. I’ve been have headaches over this one so any help would be greatly appreciated.
I cannot paste all the code in here, but if you want to see some other aspect that you think is causing this just ask and ill put it in.
var latlngs = new google.maps.MVCArray();
Map init etc
Marker creation
google.maps.event.addListener(locationMarker, "drag", function()
{
var index = findMarkerIndex(locationMarker, 1);
if (index >= 0)
{
var nLatLng = locationMarker.getPosition();
latlngs.setAt(index, nLatLng);
var nLat = nLatLng.lat();
var nLng = nLatLng.lng();
var modifiedLocation = {
Latitude: nLat,
Longitude: nLng
};
//SEND OUTPUT TO SELECT BOX
locations[index] = modifiedLocation;
document.getElementById('locations').options[index] = new Option('Num: ' + index + ' Pois: ' + nLat + ' - ' + nLng, data[4] + ',' + nLat + ',' + nLng + ',' + data[5]);
}
});
//FUNCTION CALLED FROM HTML BUTTON
function togglePOI()
{
if(togglePOIBool)
{
for(var i=0;i<markers.length;i++)
{
if (markers[i].category == 1) //ONLY HIDE CAT 1
markers[i].setMap(null);
}
togglePOIBool = false;
$("#togglePOIButton").val('Aan');
}
else
{
for(var i=0;i<markers.length;i++)
{
if (markers[i].category == 1)//ONLY SHOW CAT 1
markers[i].setMap(map);
}
togglePOIBool = true;
$("#togglePOIButton").val('Uit');
}
}
// Returns the index of the marker in the polyline.
function findMarkerIndex(locationMarker, option)
{
var index = -1;
for (var i = 0; i < markers.length; ++i)
{
if (markers[i] == locationMarker)
{
index = i;
break;
}
}
return index;
}
If it's OK for your application, replace setMap's with setVisible(true/false). When I tried this, it solves your problem.
http://jsfiddle.net/F3XbV/
You are not saving that position into markers array, I think it could solve the problem, insert this inside drag event:
markers[index].setPosition(locationMarker.getPosition());
Im creating an object to drag with "touchmove" in Y but i want it only to be dragged in one direction, up!
But it also makes it go down.. How can i solve this?
In each interval of Y some actions will take place there and the objective is to drag the item only in one way disabling the possibility to the user dont go to the previews actions.
Here is the code:
var moveMe = function(e) {
e.preventDefault();
var orig = e.originalEvent;
var y = event.touches[0].pageY;
if(y<=600 && y>420){
$(this).css({
top: orig.changedTouches[0].pageY
});
if(y<570 && y>=540){
}else {
if(y<540 && y>=510){
}else {
if(y<510 && y>=480){
}else {
if(y<480 && y>=450){
}else {
if(y<450 && y>=420){
}
}
}
}
}
}
};
$("#draggable").bind("touchstart touchmove", moveMe);
Not tested, but is it possible that you have a mistake in the following line?
var y = event.touches[0].pageY;
shoudn't you use here "e" instead of "event"?
hope it helps.