Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>MshiApp</title>
- {% load staticfiles %}
- <link rel="stylesheet" type="text/css" href="{% static 'js/chosen/chosen.css' %}" />
- <link rel="stylesheet" type="text/css" href="{% static 'css/index.css' %}" />
- <script src="{% static 'js/jquery.js' %}"></script>
- <script src="{% static 'js/chosen/chosen.jquery.min.js' %}"></script>
- <link href="{% static 'js/select2/css/select2.min.css' %}" rel="stylesheet" />
- <script src="{% static 'js/select2/js/select2.min.js' %}"></script>
- <script src="{% static 'js/app.js' %}"></script>
- </head>
- <body>
- <div id="top">
- <div class="button" id="back">
- <img src="{% static 'img/back.png' %}" />
- </div>
- <div class="title">Mshia</div>
- </div>
- <div id="middle">
- <div class="content">
- <div id="home" class="tab">
- <div class="caption">
- <h3 class="legend">მოგშივდა?</h3>
- <h2>გააკეთე არჩევანი</h2>
- </div>
- <div class="searchBar">
- <select data-placeholder="შეიყვანეთ ინგრედიენტები (ქართული შრიფტით)" id="searchBox" multiple="multiple" class="chosen-select"></select>
- </div>
- <button id="search">მოძებნე რეცეპტი</button>
- </div>
- <div id="results" class="tab" style="right: -100%;">
- <div class="inner"></div>
- </div>
- <div id="full" class="tab" style="right: -100%;">
- <div class="inner"></div>
- </div>
- </div>
- </div>
- <div id="bottom">
- <!-- TOP.GE COUNTER CODE -->
- <script language="JavaScript" type="text/javascript" src="//counter.top.ge/cgi-bin/cod?100+104996"></script>
- <noscript>
- <a target="_top" href="http://counter.top.ge/cgi-bin/showtop?104996">
- <img src="//counter.top.ge/cgi-bin/count?ID:104996+JS:false" border="0" alt="TOP.GE" /></a>
- </noscript>
- <!-- / END OF TOP.GE COUNTER CODE -->
- </div>
- <script>app.init();</script>
- <script>
- var results = $('#results .inner'), full = $('#full .inner');
- var tab = 1;
- var s = document.createElement('span');
- window.cache = [];
- function getResults() {
- results.html('');
- window.cache = [];S
- $.ajax({
- url: '/mshiapp/get/?query=' + searchBox.val().join(','),
- success: function(data) {
- for (var i = 0, l = data.length; i < l; i++) {
- var v = data[i];
- var c = v[2];
- s.innerHTML = c;
- v[0] = v[0].replace('( ვიდეო)', '');
- v[2] = c = (s.textContent || s.innerText).replace(/\n+/g, '');
- window.cache.push(v);
- if (c.length > 100) {
- c = c.substring(0, 97) + '...';
- }
- results.append('<div class="result"><div class="image"><img src="' + v[3] + '" /></div>'
- + '<div class="data"><div class="title">' + v[0] + '</div><div class="description">' + c
- + '<button class="read-more" onclick="readMore(' + i + ');">სრულად ნახვა</button></div></div><div style="clear: both;"></div></div>');
- }
- tab = 2;
- }
- });
- $('#home').animate({
- right: '100%'
- }, 200, function() {
- $('#results').animate({
- right: '0%'
- }, 200);
- });
- }
- function readMore(i) {
- $('#results').animate({
- right: '100%'
- }, 200, function() {
- $('#full').animate({
- right: '0%'
- }, 200);
- var v = window.cache[i];
- console.log('v', v);
- var rules = v[1].split(/\n{3,}/g);
- var ruleList = '';
- if (rules.length > 0) {
- ruleList = '<div class="rules">ინგრედიენტები:<ul>';
- for (var j = 0, l = rules.length; j < l; j++) {
- ruleList += '<li>' + rules[j] + '</li>';
- }
- ruleList += '</ul></div>';
- }
- console.log(rules);
- full.html('<div class="result"><div class="image"><img src="' + v[3] + '" /></div>'
- + '<div class="data"><div class="title">' + v[0] + '</div><div class="description">' + ruleList + '<span>მომზადების წესი:</span><br>' + v[2]
- + '</div></div><div style="clear: both;"></div></div>');
- });
- tab = 3;
- }
- $('#back').on('click', function() {
- if (tab > 1) {
- if (tab === 2) {
- $('#results').animate({
- right: '-100%'
- }, 200, function() {
- $('#home').animate({
- right: '0%'
- }, 200);
- });
- } else if (tab === 3) {
- $('#full').animate({
- right: '-100%'
- }, 200, function() {
- $('#results').animate({
- right: '0%'
- }, 200);
- });
- }
- tab--;
- }
- });
- var searchBox = $('#searchBox');
- searchBox.select2({
- width: '100%',
- ajax: {
- url: '/mshiapp/ingredients/',
- dataType: 'json',
- delay: 250,
- data: function (params) {
- return {
- query: params.term
- };
- },
- processResults: function (data, params) {
- for (i in data) {
- data[i] = { id: data[i][0], text: data[i][0] };
- }
- return {
- results: data
- };
- },
- cache: true
- }
- });
- var prevVal, i = 0
- $('input.select2-search__field').first().attr('onkeyup', 'onSearchFieldKeyUp.call(this, event);')
- .attr('onkeydown', 'onSearchFieldKeyDown.call(this, event);');
- var canSubmit = false;
- window.onSearchFieldKeyDown = function(e) {
- var v = searchBox.val();
- canSubmit = e.keyCode === 13 && v && v.length > 0 && !this.value;
- };
- window.onSearchFieldKeyUp = function(e) {
- if (e.keyCode === 13 && canSubmit) {
- getResults();
- }
- };
- $('#search').on('click', function() {
- if (searchBox.val()) {
- getResults();
- }
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment