Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agility and JQueryMobile #72

Closed
gregory-h opened this issue Feb 28, 2012 · 2 comments
Closed

Agility and JQueryMobile #72

gregory-h opened this issue Feb 28, 2012 · 2 comments

Comments

@gregory-h
Copy link

I would like to consider Agility for my JQM project but can't get a basic example of JQM + Agility working and can't find anyone discussing the combination.

JQM is 'page' oriented and has its own event driven page activation model and api that must be invoked to post-process controls after appending elements to things like listviews. Perhaps that is the rub, but for anyone listening the following is a simple test page that should put the todo example into a JQM context. The console logs appear reasonable but the UI fails to display any content beyond 'Welcome'.

Suggestions appreciated.

<title>Agility.js JQM test</title> <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script> <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script> <script src="/js/agility.min.js" type="text/javascript" charset="utf-8"></script>
<div id="pwelcome" data-role="page">
    <h3>Welcome</h3>
    <ul id="pwelcome-content" data-role="listview" data-inset="true"> 
    </ul>   
</div>

<script>

    $('#pwelcome').live('pageshow',function(event) { 

console.log('pwelcome pageshow');

        var item = $$({}, '<li><span data-bind="content"/> <button>x</button></li>', '& span { cursor:pointer; }', {
          'click span': function(){
            var input = prompt('Edit to-do item:', this.model.get('content'));
            if (!input) return;
            this.model.set({content:input});
          },
          'click button': function(){
            this.destroy();
          }
        });

        //
        // List of items
        //
        var list = $$({}, '<li><button id="new">New item</button><ul></ul></li>', {
          'click #new': function(){
            var newItem = $$(item, {content:'Click to edit'});
            this.append(newItem, 'ul'); // add to container, appending at <ul>
          }
        });

console.log('list is ' + JSON.stringify(list) );

        $('#pwelcome').append(list);
        $('#pwelcome-content').trigger('create');
        $('#pwelcome-content').listview('refresh');         

    });

</script>   
@gregory-h
Copy link
Author

<!DOCTYPE html> 
<html> 
<head> 
    <title>Agility.js JQM test</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">   
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>  
    <script src="/js/agility.min.js" type="text/javascript" charset="utf-8"></script>   
</head> 
<body> 

<script>

    var item = $$({}, '<li><a id="content" data-bind="content"></a><a id="close"></a></li>', '& a { cursor:pointer; }', {
      'click #content': function(){
        var input = prompt('Edit to-do item:', this.model.get('content'));
        if (!input) return;
        this.model.set({content:input});
      },
      'click #close': function(){
        this.destroy();
      },
      'change' : function(e) {
        console.log('changed.. invoke JQM refresh here if necessary');        
      }   
    });

    var list = $$({}, '<div id="pwelcome" data-role="page">\
        <button id="new">New item</button><p>\
        <ul id="pwelcome-content" data-role="listview" data-filter="true" data-inset="true" data-split-icon="delete" ><p/><p/><p/></p>\
        </ul></div>', {
          'click #new': function(){
            var newItem = $$(item, {content:'Click to edit'});
            this.append(newItem, 'ul'); // add to container, appending at <ul>
          },
          'create' : function() {
            $('#pwelcome-content').trigger('create')
          },              
          'append' : function(e) {
            $('#pwelcome-content').listview('refresh');               
          }
    });

    $$.document.append(list);           

</script>   

</body>
</html>

@gregory-h
Copy link
Author

Agility plays very nicely with JQM :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant