Skip to content

Instantly share code, notes, and snippets.

@tiposaurio
Forked from joystick/action.js
Created January 30, 2017 13:17
Show Gist options
  • Select an option

  • Save tiposaurio/0731fc603dd0b4961533b09365936a0d to your computer and use it in GitHub Desktop.

Select an option

Save tiposaurio/0731fc603dd0b4961533b09365936a0d to your computer and use it in GitHub Desktop.
var results = [];
$('#save').click(function(e) {
e.preventDefault();
var url = "http://md5.jsontest.com/?text=" + $('#basic').val();
$.getJSON(url,
function(data) {
addToList(data.md5);
});
});
function addToList(data) {
if(results.length >= 3) {
results.shift();
}
results.push(data);
console.log(results);
}
<!DOCTYPE html>
<html>
<head>
<script src="http://documentcloud.github.io/underscore/underscore-min.js"></script>
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.css" />
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.3/handlebars.js"></script>
</head>
<body>
<div data-role="page" id="home">
<div data-role="header">
<h1>Home</h1>
<a href="#settings" data-icon="gear" class="ui-btn-right">Settings</a>
</div>
<div data-role="content" id="bouquet-list">
</div>
<div id="main-footer" data-role="footer" data-position="fixed">
<h4>Presto Remote</h4>
</div>
</div>
<div data-role="page" id="settings">
<div data-role="header">
<h1>Settings</h1>
<a href="#home" data-icon="back" >Home</a>
</div>
<div data-role="content">
<form>
<div data-role="fieldcontain">
<label for="controlServer">Control server</label>
<input type="text" id="controlServer" name="controlServer">
</div>
<a href="#home" data-role="button" data-inline="true">Cancel</a>
<a href="#" data-role="button" data-inline="true" data-theme="b">Save</a>
</form>
</div>
<div id="main-footer" data-role="footer" data-position="fixed">
<h4>Presto Remote</h4>
</div>
</div>
<script id="bouquet-template"
type="x-handlebars-template">
<div data-role="page"
id="{{name}}">
<div data-role="header">
<h1>{{name}}</h1>
<a href="#home"
data-icon="back" >Home</a>
</div>
<div data-role="content" id="channel-list">
<ul data-role="listview"
data-inset="true">
{{#channels}}
<li data-icon="false">
<a href="#">
<img src="{{image_url}}" alt="{{name}}">
{{name}}</a>
</li>
{{/channels}}
</ul>
</div>
<div data-role="footer"
data-position="fixed">
<h4>Presto Remote</h4>
</div>
</div>
</script>
<script id="bouquets-template"
type="text/x-handlebars-template">
<ul data-role="listview"
data-inset="true">
{{#bouquets}}
<li>
<a href="#{{name}}">{{name}}</a>
</li>
{{/bouquets}}
</ul>
</script>
</body>
</html>
$(function () {
var source = $('#bouquets-template').html();
var template = Handlebars.compile(source);
var data = {bouquets: [
{name: 'NTV', channels: [
{name: 'Россия 24',
logo_url: "http://www.lyngsat-logo.com/logo/tv/rr/rossiya_24.jpg",
actions: [
{device: 'matrix', command: 'in1'},
{device: 'matrix', command: 'out5'},
{device: 'humax', command: '1001'}
]},
{name: 'Первый',
logo_url: "http://www.lyngsat-logo.com/logo/tv/pp/perviy_kanal_sng.jpg"},
{name: 'Второй'},
{name: 'Третий'},
{name: 'Четвертый'},
{name: 'Пятый'}
]},
{name: 'NOVA', channels: [
{name: 'novacinema 1'},
{name: 'novacinema 2'}
]},
{name: 'SKY', channels: [
{name: 'Supercalcio'},
{name: 'LA7'}
]},
{name: 'DUNE', channels: [
{name: 'Ren TV'},
{name: 'Nikelodeon'}
]},
{name: 'CYTA', channels: [
{name: 'ANT1'},
{name: 'MEGA'},
{name: 'SIGMA'},
{name: 'ERT'},
{name: 'LTV'}
]}
]};
$('#bouquet-list').append(template(data));
$('#bouquet-list ul')
.listview()
.listview('refresh');
_.each(data.bouquets, function(bouquet) {
var source = $("#bouquet-template").html();
var template = Handlebars.compile(source);
// console.log(template(bouquet));
// console.log(bouquet);
// console.log(bouquet.channels);
var page = $(template(bouquet));
// console.log(page);
page.appendTo($.mobile.pageContainer);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment