-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage-media.php
186 lines (134 loc) · 4.62 KB
/
page-media.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php Themewrangler::setup_page();get_header(); ?>
<?php
get_template_part('templates/page', 'header');
?>
<div class="row">
<div class="desktop-12">
<?php get_search_form( ); ?>
<div id="posts" class="row"></div>
<script id="posts-list" type="text/template">
<<<<<<< Updated upstream
{{#count}}<div class="desktop-12">{{count}} posts found.<br><br></div>{{/count}}
=======
{{#count}}<div class="desktop-12">{{count}} posts found. </div>{{/count}}
>>>>>>> Stashed changes
{{#posts}}
<div class="item desktop-4">
{{#thumbnail}}
<img src="{{medium}}" alt="{{title}}" class="img-responsive">
{{/thumbnail}}
{{^thumbnail}}
{{/thumbnail}}
<h3><a href="{{url}}">{{title}}</a></h3>
{{{excerpt}}}
<span><a href="{{url}}">read more</a></span>
</div>
{{/posts}}
{{^posts}}
<<<<<<< Updated upstream
<div class="desktop-12">Sorry, no posts match that search.<br><br></div>
=======
<div class="desktop-12">Sorry, no posts.</div>
>>>>>>> Stashed changes
{{/posts}}
</script>
<script>
$(function(){
loadUrl = '/?json=1';
$.ajax({
url: loadUrl,
dataType : "json",
type: 'GET',
beforeSend: function() {
$('#posts').html('<div class="desktop-12">loading</div>');
},
complete: function(data) {
},
success: function(data) {
var template = $('#posts-list').html();
var html = Mustache.to_html(template, data);
$('#posts').html(html);
}
});
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var searchUrl = getParameterByName('search');
console.log(searchUrl);
if(window.location.href.indexOf(searchUrl) > -1) {
loadUrl = '/search/'+searchUrl+'?json=1';
$.ajax({
url: loadUrl,
dataType : "json",
type: 'GET',
beforeSend: function() {
$('#posts').html('<div class="desktop-12">loading</div>');
},
complete: function(data) {
},
success: function(data) {
var template = $('#posts-list').html();
var html = Mustache.to_html(template, data);
$('#posts').html(html);
}
});
}
});
$('#searchform').submit(function( e ){
// Stop the form from submitting
e.preventDefault();
// Get the search term
var search = $('#s').val();
var cleansearch = search.replace(/ /g, '+');
var term = '/search/'+cleansearch+'?json=1';
var mediasearch = '/archive?search='+cleansearch;
// var term = '/search/'+search;
// Make sure the user searched for something
if ( term ){
// $.getJSON(term, function(data){
// var template = $('#results-list').html();
// var html = Mustache.to_html(template, data);
// $('#results').html(html);
// });
// $.getJSON(term, function(data){
// var template = $('#posts-list').html();
// var html = Mustache.to_html(template, data);
// $('#posts').html(html);
// });
$.ajax({
url: term,
dataType : "json",
type: 'GET',
beforeSend: function() {
// TODO: show your spinner
$('#posts').html('<div class="desktop-12">loading</div>');
},
complete: function(data) {
// TODO: hide your spinner
//$('#posts').html('loaded');
//console.log(data);
// var template = $('#posts-list').html();
// var html = Mustache.to_html(template, data);
// $('#posts').html(html);
},
success: function(data) {
// This only works if we're getting results from the search page... not JSON.
//$('#results').html( $(data).find('#results') );
//$('#results').html(data);
// This is it.
var template = $('#posts-list').html();
var html = Mustache.to_html(template, data);
$('#posts').html(html);
History.pushState(null,null,mediasearch)
// Need to add some animation, etc.
}
});
}
});
</script>
</div>
</div>
<?php get_footer(); ?>