Categories
discuss

What’s the best way to handle longtap and double-tap events on mobile devices using jQuery?

I’m looking for the best solution to adding both “doubletap” and “longtap” events for use with jQuery’s live(), bind() and trigger(). I rolled my own quick solution, but it’s a little buggy. Does anyone have plugins they would recommend, or implentations of their own they’d like to share?

Answer

It has been reported to jQuery as a bug, but as doubletapping isn’t the same as doubleclicking, it does not have a high priority. However, mastermind Raul Sanchez coded a jquery solution for doubletap which you can probably use! Here’s the link, works on mobile Safari.

It’s easy to use:

$('selector').doubletap(function() {});

-edit-

And there’s a longtap plugin here! You can see a demo on your iPad or iPhone here.

Categories
discuss

scrollview with floating linearlayout will not scroll

Here is my gui xml:

<FrameLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/frameLayout"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ScrollView android:layout_width="fill_parent" android:id="@+id/scrollView"
        android:fillViewport="true" android:layout_height="fill_parent">

        <LinearLayout android:layout_width="fill_parent"
            android:orientation="vertical" android:id="@+id/contentLayout"
            android:padding="5dip" android:fadingEdge="vertical"
            android:layout_height="fill_parent">
            <TextView android:id="@+id/lblName" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:text="@string/label_name"></TextView>
            <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:id="@+id/nameLayout">
                <CheckBox android:layout_width="wrap_content"
                    android:layout_height="wrap_content" android:id="@+id/chkName"></CheckBox>
                <TextView android:layout_marginLeft="4dip"
                    android:layout_marginRight="4dip" android:id="@+id/txtName"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:textColor="@color/white" android:text="TextView"
                    android:layout_weight="1" android:textSize="20dip"></TextView>
            </LinearLayout>
            <TextView android:id="@+id/lblPhone" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:text="@string/label_phone"></TextView>
            <LinearLayout android:isScrollContainer="false"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:orientation="vertical" android:id="@+id/lstPhone"></LinearLayout>
            <TextView android:id="@+id/lblEmail" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:text="@string/label_email"></TextView>
            <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:orientation="vertical"
                android:id="@+id/lstEmail"></LinearLayout>
            <TextView android:id="@+id/lblAddress" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:text="@string/label_address"></TextView>
            <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:orientation="vertical"
                android:id="@+id/lstAddress"></LinearLayout>
        </LinearLayout>
    </ScrollView>
    <LinearLayout android:background="@color/grey"
        android:layout_width="fill_parent" android:paddingTop="5dip"
        android:layout_height="wrap_content" android:orientation="horizontal"
        android:layout_gravity="bottom|right" android:id="@+id/commandLayout">
        <Button android:id="@+id/btnToClipBoard" android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:text="To ClipBoard"
            android:layout_weight="1"></Button>
        <Button android:id="@+id/btnCancel" android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:text="Cancel"
            android:layout_weight="1"></Button>
    </LinearLayout>
</FrameLayout>

The LinearLayout id: commandLayout stays nicely at the bottom of the window. But the LinearLayout id: contentLayout won’t scroll. If I move the commandLayout inside the scrollView everything scrolls. That isn’t what I want though. I want to see the buttons no matter how long the contentLayout is. Any help would be greatly appreciated. I have spent most the day on this… Thanks.

Edit: Thanks for all of the responses. Changing from a FrameLayout to a RelativeLayout and setting the commandLayout align parent bottom and the scrollview align parent top was the solution that worked best.

Answer

I changed the base layout namely “frameLayout” into a relative layout.

I do this so that the “commandLayout” will be below of the “scrollView”. It doesn’t make sense if the things you’re going to show is hidden behind the “commandLayout”

I’ve added the alignParentBottom on “commandLayout”. I’ve also added layout_above=”@+id/commandLayout” over at the “scrollView”

this is the working xml and yes it does scroll =)

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/relativeLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ScrollView 
    android:layout_width="fill_parent"
    android:id="@+id/scrollView"
    android:fillViewport="true"
    android:layout_height="fill_parent"
    android:layout_above="@+id/commandLayout"
>
    <LinearLayout 
        android:layout_width="fill_parent"
        android:orientation="vertical"
        android:id="@+id/contentLayout"
        android:padding="5dip"
        android:fadingEdge="vertical"
        android:layout_height="fill_parent"
    >
        <TextView
            android:id="@+id/lblName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        >
        </TextView>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/nameLayout"
        >
            <CheckBox 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/chkName">
            </CheckBox>
            <TextView
                android:layout_marginLeft="4dip"
                android:layout_marginRight="4dip"
                android:id="@+id/txtName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FFFFFF"
                android:text="TextView"
                android:layout_weight="1"
                android:textSize="20dip">
            </TextView>
        </LinearLayout>

        <TextView
            android:id="@+id/lblPhone"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        >
        </TextView>
        <LinearLayout
            android:isScrollContainer="false"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/lstPhone">
        </LinearLayout>
        <TextView
            android:id="@+id/lblEmail"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        >
        </TextView>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/lstEmail"
        >
        </LinearLayout>
        <TextView
            android:id="@+id/lblAddress"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        >
        </TextView>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/lstAddress">
        </LinearLayout>
        <TextView
            android:id="@+id/LongText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="40sp"
            android:text="This is a super long text that will hopefully cover the whole screen so as the scroll will work."
        >
        </TextView>

         <TextView
            android:id="@+id/AnotherLongText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="40sp"
            android:text="This is another super long text to show that the scrolling will work even more!"
        >
        </TextView>
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:background="#737754"
    android:layout_width="fill_parent"
    android:paddingTop="5dip"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/commandLayout"
    android:layout_alignParentBottom="true"
>
    <Button
        android:id="@+id/btnToClipBoard"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="To ClipBoard"
        android:layout_weight="1">
    </Button>
    <Button
        android:id="@+id/btnCancel"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="Cancel"
        android:layout_weight="1">
    </Button>
</LinearLayout>
</RelativeLayout>
Categories
discuss

Sorting the Grouped data in GridPanel of EXTJS by group_sort_order

How to sort the EXT JS Grid Panel grouped data by its sortOrder

{Grouped data}                {Sort Order}

Audi                            [3]
    col11 col22 xol33
    col21 col23 cole3
Benz                            [1]
    col23 col32 cos32
    col32 dos34 sdfd2
Citron                          [4]
    jkj23 dfd23 fds23
    jkjkk jjkkk jkkkk
Nissan                          [2]
    col23 col32 cos32
    col32 dos34 sdfd2

Fot the above data I want to by sort its sort order (as i got sort order for each group element in my groupdatastore) as below

 Benz                            [1]
    col23 col32 cos32
    col32 dos34 sdfd2
 Nissan                          [2]
    col23 col32 cos32
    col32 dos34 sdfd2
 Audi                            [3]
    col11 col22 xol33
    col21 col23 cole3
 Citron                          [4]
    jkj23 dfd23 fds23
    jkjkk jjkkk jkkkk

Answer

Try setting these on the store:

remoteGroup:true,
remoteSort: true

And in you sql or what you use to get data out sort by grouping field first.

gridDataStoreObj = new Ext.data.GroupingStore(
{
    remoteGroup:true,
    remoteSort: true,
    proxy: new Ext.data.HttpProxy({url: 'index.php' }),
    method:'POST',
    groupField:'brandName',
    ...     
    sortInfo:{field: 'id', direction: "ASC"},
}); 

On the server:

select * from table order by brandName, id

This should sort groups themselves.

Categories
discuss

How can you flip website upside down in IE ? (for the April 1st)

We are making April 1st prank in our office, and wanted to flip our corporate website upside down for several hours tomorrow 🙂

My patch works everywhere but not in IE… Can anyone help ?

<script type="text/javascript">
   document.body.style.MozTransform = 'rotate(180deg)';
   document.body.style['-webkit-transform'] = 'rotate(180deg)';
</script>

Answer

A slightly simpler version for IE (no matrix stuff):

body {
  filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2);
}
Categories
discuss

How to set a timeout for loading a external javascript file which is down

Im using javascript to include some content served up from a php file on another server. However, this other service can sometimes get flaky and either take a long time to load or will not load at all.

Is there a way in JS to try to get the external data for x number of seconds before failing and stopping to include js.

Answer

If you mean

<script src="javascript.php"></script>

then the short answer is no which is why JSONP is not useful in these cases.

The longer answer is that you might be able to use setTimeout and test a variable you KNOW should be in the javascript and give an error if the var/function is not there.

If you do

<script>
var start = new Date();
var tId;
function testFunction() {
  var end = new Date();
  if ( (end.getTime()-start.getTime()) > 10000) {
    alert('gave up')
  }
  else if (someFunction) { // someFuntion in the external JS
    someFunction()
  }
  else tId=setTimeout(testFunction,1000)
}
</script>

<script src="javascript.php"></script>
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..