Dynamic filter bar using tag links in tumblr - dynamic

I have 10 links to 10 TagPages, when clicked they take you to a page with all the posts with that tag.
That’s easy enough.
I’d like to know if its possible to stack more than one tagged post in a page. For example when all the “red” tagged posts are showing you can click and load in the “blue” tagged posts without leaving the page.
The 10 links then behave like a filtering system. You can then show any combination of tagged posts in one page… click once and load them in, click again to hide the posts.
I hope that all makes sense.
Any help would be great. Thanks.

You can load in posts by tag with Tumblr's API: http://www.tumblr.com/docs/en/api/v2#posts
The call for each of your tags would look something like this (square brackets marking areas you'll need to change):
URL = http://api.tumblr.com/v2/blog/[base-hostname]/posts?api_key=[key]&tag=[tagname]&jsonp=?
$.ajax(URL, {
type: 'GET',
dataType: 'json',
success: function(data) {
// do something with your data
}
});
Updated with a more specific example:
You'd need to create a function for each click of your tag navigation. So let's say you built out your navigation in simple HTML, you'd want to create a function for each of those clicks.
HMTL:
<nav class="tag-nav>
<ul>
<li>Portrait</li>
<li>Landscape</li>
</ul>
</nav>
JS:
$('.tag-nav a').on('click', function (e) {
e.preventDefault();
// grab classname from the link that was just clicked
var tagName = $(this).attr('class');
// go get our tagged posts
getTaggedPosts(tagName);
});
var getTaggedPosts = function (tag) {
// this is where your AJAX call will go
// bonus points if you check to see if you've already made the AJAX call
// and stored the posts somewhere else on the page
};

Related

Bigcommerce Stencil access more subcategory levels on category page

Is there any way to access more subcategory levels on the category page? Currently, in the context of the category on a category page, there exists a subcategories attribute which lists the immediate children of the current category. Is there any way to have the system return the subcategories of each of those subcategories as well?
I was hoping this could be done via front-matter or some setting in the control panel?
There isn't a way with the existing front-matter or store settings. It would need to be added by BigCommerce as a new feature.
Been there! And as answered be Alyss there's no way to do that straight from the server.
That being said you can always get it done through an AJAX call to the subcategory url and take just what you need from there to finish populating your category page with subcategory products.
First in the category template file I added an empty element with the data I needed to make the call:
<div class="nested container">
<main data-ajax-url="{{url}}" class="product-listing-container"></main>
</div>
Then I added this method to the theme/category.js file and called it inside the loaded method called on template load.
getSubcategoryProducts() {
$('[data-ajax-url]').each((index, el) => {
const $this = $(el);
const thisCatURL = $this.data('ajax-url');
let $thisCatProducts;
$.ajax({
url: thisCatURL,
type: 'GET',
dataType: 'html',
async: true,
}).done((data) => {
$thisCatProducts = $(data).find('#product-listing-container').html();
$this.html(thisCatProducts);
});
});
}
I'm sure there are better ways to do it, probably through the Stencil Utils API but I'm still trying to get a grasp of it as there's close to zero documentation on that.
Good coding!

using modal for each item in a list in yii framework

There is a list of patient data using a "TbGridView" widget,
Now, I want to use modal widget for each one of the patient here, so, that
the patient id is passed to the modal for each patient with patient id.
I had tried this, but, I am being unable to pass each patient id to the modal form.
Any response related to this would be very helpful.
Thank you.
Actually there is no direct way of doing that I mean that you cant render dynamic data by passing an id. Modal is static.
You can use ajax call for that to retrieve data from database and render that data in your modal. Follow these steps
1. In your gridview use rowHtmlOptionsExpression to set id for specific row.
2. create an action in your controller to handle ajax call.
3. use jquery click event on TbGridView elements like
$('#mygrid table tbody tr td:not(:first-child)').on('click', function() {
var Url =<?php echo '"' . CController::createUrl('/user/default/viewMessageAjax') . '"'; ?>;
var id = $(this).parent().attr('id');
console.log($(this));
$.ajax({
url: Url,
data: {id: id},
success: function(data) {
$('.modal-body').html(data);
$('#myModal').modal('show');
}
});
})
jQuery('#mygrid >table>tbody>tr:first-child').live('click', function() {
return false;
})
above code is just an example, you can change it according to ur needs.

Rendering results from an API after using a search function with Backbone.js

I am new to Backbone.js and I am trying to create an application that can check if you completed the videos games you control.
I am using an API to retrieve any information about videogames.
I want to be able to search for a game, for example "Zelda". It should then list every Zelda game.
I get stuck because I don't know how to get the search function to work properly with the API and I don't know how to render it properly. I have written a template for the games that should render.
I have no clue what to do know, or if I'm even on the right track. I am not asking for someone to code it completely, I am asking for a step in the right direction.
Let me know if you need more code.
library_view.js
var LibraryView = Backbone.View.extend({
el:$("#games"),
url: url = "http://www.giantbomb.com/api/search/?api_key=[KEY]",
events:{
"keypress input":"findGames"
},
findGames:function(e){
if(e.which == 13){
query = $(".searchfield").val()
field_list = "name,platforms"
resources = "game"
url = url +"&query="+ query +"field_list"+ field_list +"resources"+ resources
}
},
index.html
<input type="search" placeholder="Find a game" class="searchfield">
It looks like you are mashing together a View and a Model.
A view, for instance, shouldn't have URL inside it, it doesn't know what to do with it.
The correct path would be something roughly like so:
var SearchModel = Backbone.Model.extend();
var LibraryView = Backbone.View.extend({
el: $("#games"),
events:{
"keypress input":"findGames"
},
findGames: function(e){
// get query, field_list, resources
var searchModel = new SearchModel()
searchModel.fetch({
url: "http://www.giantbomb.com/api/search/?api_key=[KEY]"+"&query="+ query +"field_list"+ field_list +"resources"+ resources
});
// do something with searchModel
}
});
After the fetch, searchModel will hold the data Backbone Model style.
Let's say the returned value from the AJAX call is:
{
"answer": 42
}
Then:
searchModel.get("answer") // = 42
The SearchModel is just an abstraction here as you don't really need it (you can just ajax it). But I put it to help you understand what Model represents, it basically represents only data... It doesn't know what View is.

Tumblr blog: how to add a list of all posts sorted by dates

I'm customizing a Tumblr blog and I cannot find a good way to access all the posts by date.
Tumblr allows you to display a particular post from a day using their Day Pages, but I want to find all posts and their dates, and then display them as a list sub-divided by months and years (really, it's like Wordpress's default sidebar). See example image here: http://i.stack.imgur.com/28gGH.png
I've been looking through Tumblr's Custom Theme Documentation but have not found a way to generate this information. Perhaps they offer it through their API? I haven't found anything yet.
I appreciate any direction here. Thanks.
I found the best way to do it is by pulling it from your blog's own RSS feed. Add this code after jquery has been included:
<script>
$(function() {
var url = '/rss';
var $list = $('#recent-posts');
$.ajax({
url: url,
type: 'GET',
dataType: 'xml',
success: function(data) {
var $items = $(data).find('item');
$items.each( function() {
var $item = $(this);
var link = $item.children('link').text();
var title = $item.children('title').text();
if (link && title) {
$list.append($('<li>' + title + '</li>'));
}
});
}
});
});
</script>
It will go out and make a list of ALL blog posts, if you want to limit it so a certain number of posts you can check the index value passed into the $items.each() functions: http://api.jquery.com/jquery.each/
Also make sure to include the list in your sidebar:
<!-- RECENT POSTS -->
<ul id="recent-posts"></ul>
<!-- RECENT POSTS -->
Note: the list will probably not appear in preview mode, only once you save your changes and go to the live blog, will it be able to pull from /rss

set jqGrid page before url is called

I am looking for a way to set the page of a jqGrid to x...
My use case is someone is using my grid...
They click on a patient to edit that patient (I am not using jqGrids modal edit screen... to many modal windows already)...
When the save what they did to that patient, I want to redirect the browser back to the screen where they clicked on that patient, and back to the SAME PAGE...
The thing to keep in mind.
I am using asp.net MVC4. I call the first page via an action method. The url variable of my grid is another action in the same controller. That action is what I send my page and row variables down to. I am sure that this can be done, However, I have no idea of how to achieve it. So far I have tried to set the page variable and rows variable in my document.ready before I call the jqGrid...
tbl.jqGrid({
loadBeforeSend: function () {
page: pageFromTemp;
rows: rowFromTemp
}
});
basically I have tried different ways to do it. The above is just one of them.
I have tried to reload the grid in the document.ready. But that doesn't make any sense. Why reload the grid when you haven't given it any of the parameters it needs...
I have tried to set the variable in the beforeRequest event. I have a function that I try and set it in...
beforeRequest: function () {
if ((rowFromTemp != "") && (pageFromTemp != "")) {
$(this).trigger('reloadGrid', [{ page: pageFromTemp, rowNum: rowFromTemp, url: '/Encounters/GetAjaxPagedGridData/' }]);
//$.extend($(this).setGridParam({ page: pageFromTemp })),
//$.extend($(this).setGridParam({ rowNum: rowFromTemp })),
//$.extend($(this).setGridParam({ url: '/Encounters/GetAjaxPagedGridData/' }))
//$.trigger('reloadGrid', [{ page: pageFromTemp, rowNum: rowFromTemp, url: '/Encounters/GetAjaxPagedGridData/'}]);
}
},
But that doesn't work either. I am obviously missing something. What am I doing wrong...
Got it to change to the right page using loadComplete and $("frTable").trigger({})
But now I am getting a flashing Loading screen which indicates to me that it is still loading the data...
If I set a breakpoint in my code, I can confirm that it is loading the data. I am not doing something right here.
Load the grid in document ready, have it's datatype set to local, have it's url unassigned, and have it hidden. When you want to have it load, trigger the load after setting the parameters and then show it to the user.