Skip to content

Instantly share code, notes, and snippets.

View vgheri's full-sized avatar

Valerio Gheri vgheri

View GitHub Profile
@vgheri
vgheri / gist:2399192
Created April 16, 2012 14:42
KnockoutJS data-bind for DropDownLists with MVC 3
public ActionResult Index()
{
var numberOfDropDownMenus = 5;
for (var i = 0; i < numberOfDropDownMenus; i++)
{
var selectList = new SelectList(this.GetDummyItems(i), "Id", "Name", -1);
ViewData["Options_" + i] = selectList;
}
ViewData["DropDownMenus"] = numberOfDropDownMenus;
return View();
@vgheri
vgheri / iLikeIt.js
Created June 1, 2012 12:30
iLikeIt! jQuery plugin
//iLikeIt v0.1.0 | (c) 2012 Valerio Gheri | http://www.opensource.org/licenses/mit-license
/*var iLikeIt = */(function ($) {
/*
* Get a text representation of the vote cast by the user
*/
function getStarShortTextDescription(starId) {
var description;
switch (starId) {
case "1":
description = "Awful";
@vgheri
vgheri / gist:2869810
Created June 4, 2012 17:48
displayRating
function displayRating(selectedId, mouseIn) {
var activeImage = $(".active img");
if (activeImage.data("vote") === null || activeImage.data("vote") === undefined) {
var divs = $(".star-container div").slice(0, parseInt(selectedId)).each(function (item) {
$(this).find("img").attr("src", '/Content/images/full_star.png');
});
$(".star-text").text(getStarShortTextDescription(selectedId));
}
}
$.fn.iLikeIt = function (options) {
var div = createVotingDiv();
// element is the carousel
var element = $(this);
element.append(div);
element.carousel({
interval: false,
pause: "hover"
@vgheri
vgheri / gist:2869817
Created June 4, 2012 17:50
register vote
function registerVote(star, postUrl) {
var votedImage = $(".active img");
// If the user didn't vote yet, then we can register the vote
if (votedImage.data("vote") === null || votedImage.data("vote") === undefined) {
$(".carousel-vote-title").text("Submitting your vote...");
$.ajax({
type: 'POST',
url: postUrl,
data: '{"imageId":"' + votedImage.attr("id") + '", "rating":"' + star.attr("id") + '"}',
contentType: "application/json; charset=utf-8",
@vgheri
vgheri / gist:2869821
Created June 4, 2012 17:50
View detail
<script type="text/javascript">
$(function () {
var options = {
postUrl : "/Home/RegisterVote"
}
$("#myCarousel").iLikeIt(options);
});
</script>
@if (false) {
<script src="../../Scripts/jquery-1.7.2-vsdoc.js" type="text/javascript"></script>
<script src="../../JS/iLikeIt.js" type="text/javascript"></script>
}
<div class="container">
<h1>iLikeIt!</h1>
<br />
<h3>iLikeIt! is a simple, proof of concept, image voting system</h3>
@vgheri
vgheri / gist:3163213
Created July 23, 2012 11:46
Chat page HTML code
<div id="myContainer" class="container-fluid">
<div class="row-fluid">
<!-- This is the contact box -->
<div id="users-list" class="span2">
<h4>Users</h4>
<ul data-bind="foreach: contacts">
<li class="user-box"><span class="user-box-name" data-bind="text: username"></span></li>
</ul>
</div>
<!-- This is the chat box -->
@vgheri
vgheri / gist:3163223
Created July 23, 2012 11:49
ChatR namespace and ViewModels
/*
* Author: Valerio Gheri
* Date: 22/07/2012
* Description: ChatR namespace js file and viewmodels declaration
*/
// Namespace
var chatR = {};
// Models
@vgheri
vgheri / ChatHub.cs
Created July 23, 2012 12:51
ChatHub
namespace ChatR.Hubs
{
public class ChatHub : Hub, IDisconnect
{
private InMemoryRepository _repository;
public ChatHub()
{
_repository = InMemoryRepository.GetInstance();
}