Commits

Anonymous committed 525c18d

initial import

Comments (0)

Files changed (2)

+* {
+  margin:0px;
+  padding:0px;
+  border: 0px;
+}
+
+a, a:visited, a:hover {
+  color:#EF4208;
+  text-decoration:none;
+}
+
+h3 {
+  font-family:helvetica,arial;
+  font-size:14px;
+}
+
+.film h3 {
+  font-size:16px;
+  line-height:16px;
+}
+
+.film {
+  margin: 0 1em 1em 0;
+}
+
+.film .poster {
+  margin-right:1em;
+}
+ul.pager {
+  overflow:hidden;
+}
+.pager li {
+  float:left;
+  margin-left:8px;
+}
+
+#username {
+  font-size:20px;
+}
+
+li {
+  list-style: none;
+}
+
+
+input,select,textarea,button {
+  border:1px solid #ccc;
+/*  padding:2px;*/
+}
+
+textarea {
+  width:100%;
+}
+
+
+body {
+  color:#808080;
+  font-family: sans-serif;
+}
+
+
+a:hover {
+  text-decoration:underline;
+}
+
+ul.menu a {
+  font-weight:bold;
+  font-size:16px;
+  color:#aaa;
+  margin-right:20px;
+}
+
+ul.menu li.expanded a{
+  color:black;
+}
+
+#content {
+  clear:both;
+  line-height:1.5em;
+}
+
+#content .node h2.title {
+  display:none;
+}
+
+
+ul.menu {
+  margin-top:16px;
+  height:20px;
+}
+
+ul.menu li,ul.menu li {
+  list-style:none;
+  display:block;
+/*  height:20px;*/
+}
+
+ul.menu li,ul.menu li {
+  float:left;
+}
+
+.external {
+  width: 100%;
+  margin: 0 auto;
+}
+#main {
+  background-color: #f8f8f8;
+  position:relative;
+  border-left:1px solid #ccc;
+}
+#main {
+  border-bottom:1px solid #ccc;
+  padding: 1px 1em;
+}
+#footer {
+  width:100%;
+  margin: 0 auto;
+  clear:both;
+  position:relative;
+  top:-20px;
+  z-index:999;
+  text-align:right;
+}
+
+
+.node .admin {
+  float:right;
+  color:red;
+}
+
+#content {
+  margin:1em 0 0;
+}
+
+#content h2 {
+  margin-bottom:1em;
+  margin-top:1em;
+  color:#ccc;
+  font-size:18px;
+}
+
+#content ul {
+  margin-left:1em;
+}
+
+.clear {
+  clear:both;
+}
+
+.error {
+  color:red;
+  font-weight:bold;
+}
+
+#profilemenu {
+  float:left;
+  width:200px;
+}
+
+  .container {
+    border:1px solid #ddd;
+    margin-bottom:4px;
+    font-family:arial,helvetica,clean,sans-serif;
+    font-size:13px;
+    line-height:130%;
+  }
+
+  .container .toolbar {
+    font-size:10px;
+    line-height:10px;
+    clear:both;
+    text-align:right;
+  }
+  #content {
+    overflow:hidden;
+    padding-bottom:2em;
+  }
+  #users {
+    float:left;
+    width:200px;
+  }
+  #content #results {
+    margin-left:216px;
+  }
+  #content .film {
+    overflow:hidden;
+    width:250px;
+    float:left;
+    height:102px;
+  }
+  .film .poster {
+    float:left;
+  }
+
+.film p.info {
+  font-size:12px;
+  line-height:1em;
+  margin-top:4px;
+}
+
+.film .rating {
+  font-size:24px;
+  color:#EF4208;
+  font-weight:bold;
+  margin:4px 4px 0px 0px;
+}
+
+#users li {
+  padding-left:30px;
+}
+
+#users li.loading {
+  background-image:url(/media/images/loading.gif);
+  background-repeat:no-repeat;
+  background-position:0% 50%;
+}
+<!DOCTYPE html 
+     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+    dir="{% if LANGUAGE_BIDI %}rtl{% else %}ltr{% endif %}"
+    xml:lang="{% firstof LANGUAGE_CODE 'en' %}"
+    lang="{% firstof LANGUAGE_CODE 'en' %}">
+  <head>
+    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
+    <title>Filmaster API sample - common movie recommendations</title>
+    <link rel="stylesheet" type="text/css" href="css/style.css" />
+    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
+    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js"></script>
+  </head>
+
+<script type="text/javascript">
+SERVICE_BASE = 'http://api.filmaster.pl'
+Array.prototype.update_films = function(films) {
+  for(var i=0; i<films.length; i++) {
+    var k = 'permalink_'+films[i].permalink
+    if(!this[k]) {
+      this[k] = films[i];
+      this.length++;
+    }
+  }
+}
+
+Array.prototype.intersection = function(films) {
+  var result = []
+  result.size = 0;
+  for(var k in films) {
+    if(k.indexOf('permalink_')!=0) continue;
+    if(k in this) {
+      result[k] = films[k]
+      result.length++;
+    }
+  }
+  return result;
+}
+
+Array.prototype.eachFilm = function(cb) {
+  for(var k in this) {
+    if(k.indexOf('permalink_')!=0) continue;
+    cb(this[k]);
+  }
+}
+
+recommendations = []
+
+function selected_users() {
+  return $('input.user').filter(function(i,v){return v.checked}).
+                         map(function(i,v){return v.id.substring(5)});
+}
+
+function jsonp_uri(uri) {
+  return SERVICE_BASE + uri + (uri.indexOf('?')>=0 ? '&' :'?')+'callback=?';
+}
+
+function show_common_recommendations() {
+  var users = selected_users()
+  if(users.length) {
+    var common = recommendations[users[0]]
+    for(var i=1; i<users.length; i++) {
+      common = common.intersection(recommendations[users[i]])
+    }
+    $('#results li.film').each(function() {
+      if(!common[this.id]) $(this).remove()
+    })
+        
+    common.eachFilm(function(film) {
+      var f = $('#permalink_'+film.permalink).get(0)
+      if(!f)
+        $('#results').append(create_film(film))
+    })
+  }
+}
+
+function fetch_recommendations(user, uri) {
+  var inp = $('#user_'+user.username)
+  var li = inp.parent('li').addClass('loading')
+  
+  $.getJSON(jsonp_uri(uri), null, function(data, status) {
+    li.removeClass('loading')
+    if(!recommendations[user.username]) 
+      recommendations[user.username] = []
+    if(recommendations[user.username].length < 100) {
+      recommendations[user.username].update_films(data.objects)
+      show_common_recommendations()
+
+      if(data.paginator && data.paginator.next_uri && inp[0].checked)
+        fetch_recommendations(user, data.paginator.next_uri);
+    }
+  });
+}
+
+function create_film(film) {
+  var item = $("<li class='film'>")
+  item.attr('id', 'permalink_'+film.permalink);
+  $("<img class='poster'>").
+    attr("src", 'http://filmaster.pl'+(film.image || 'img/default_poster.png')).appendTo(item)
+  $("<h3>").append(
+    $("<a>").
+       attr('href', 'http://filmaster.pl/film/'+film.permalink).
+       text(film.title_localized)
+  ).appendTo(item);
+  $("<p style='float:left' class='rating'>").text(Math.floor(film.guess_rating*10)/10).
+    appendTo(item);
+  $("<p class='info'>").text(
+    film.title + ', ' + film.release_year + ', ' + film.directors[0].name + ' ' + film.directors[0].surname
+  ).appendTo(item)
+  return item
+}
+
+function add_user(user) {
+    var u = $("<li>")
+    var inp = $("<input type='checkbox' class='user'>").attr('id', 'user_'+user.username).appendTo(u);
+    $("<label>").attr('for','user_'+user.username).text(user.username).appendTo(u);
+    $('#users').append(u);
+    inp.change(function() {
+      if(this.checked)
+        fetch_recommendations(user, user.recommendations_uri + '?include=guess_rating');
+      else 
+        show_common_recommendations();
+    });
+}
+
+function fetch_collection(uri, cb) {
+   uri = jsonp_uri(uri);
+   $.getJSON(uri, null, function(data, status) {
+       cb(data.objects);
+       if(data.paginator && data.paginator.next_uri)
+           fetch_collection(data.paginator.next_uri, cb);
+   });
+}
+
+function fetch_user() {
+  var username = $(this).val();
+  var user_uri = jsonp_uri('/1.0/user/' + username + '/');
+  $.getJSON(user_uri, null, function(data, status) {
+    $('#users').empty();
+    $('#results').empty();
+    add_user(data);
+    $('#users').append($('<li>').html('<i>and friends he follows:</i>'));
+    $('#results').append($('<li>').html('<i>mark users to see their common movie recommendations...</i>'));
+    fetch_collection('/1.0/user/' + username + '/following/?include=user', function(data) {
+      $(data).each(function() {
+        add_user(this.user)
+      });
+    });
+  });
+}
+
+function init() {
+  $('#username').change(fetch_user);
+/*  
+  add_user(profile);  
+  $(friends).each(function(){add_user(this);});
+  $('#users').sortable({update:function(ev, ui) {
+    $('#results li.film').remove();
+    show_common_recommendations();
+  }} )
+  $('#results').sortable()*/  
+}
+$(document).ready(init);
+</script>
+</head>
+
+<body>
+<div><a href="">Reload page</a> <a href="https://bitbucket.org/mrk/filmaster-api-sample" style="float:right">Source code</a>
+</div>
+<h1>Filmaster API sample - common movie recommendations</h1>
+
+<div id="content">
+<div>
+  Enter filmaster username: <input type="text" id="username" />
+</div>
+<ul id="users">
+</ul>
+<ul id="results">
+</ul>
+</div>
+</body>
+</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.