Permalink
Browse files

First thumbnailer version. And added compass support.

  • Loading branch information...
1 parent 09848aa commit 386de1a89004c38c1b53b01fc23e395437912c3d @Pickachu Pickachu committed Mar 21, 2012
View
@@ -19,7 +19,7 @@ gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
- gem 'compass'
+ gem 'compass-rails'
# gem 'coffee-rails', '~> 3.2.1'
View
168 TAGS

Large diffs are not rendered by default.

Oops, something went wrong.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,66 @@
+var gadget = (function declare_photos () {
+ var that = function initialize_photo(parent, options) {
+ options = options || {};
+ options.parent = parent || '#gadgets';
+ options.data = options.data || {};
+ return $.extend(options, inherit(gadget));
+ }, id = 0,
+ gadget = {
+ show: function () {
+ !this.element && control.create.call(this);
+ this.element.fadeIn();
+ },
+ dispatch: function (name, event) {
+ handlers[name] && handlers[name].call(this, event);
+ }
+ }, control = {
+ create: function () {
+ this.data = $.extend({
+ id: id++,
+ source: 'http://' + kuva.service.url + '/assets/jla.gif',
+ title: 'Sumonando'
+ }, this.data);
+ $(this.parent).jqoteapp('#gadget', this.data);
+ this.element = $('#gadget-' + this.data.id);
+ this.image = image(this.element.find('img'));
+ }
+ },
+ handlers = {
+ loadstart: function (event) {
+ this.show();
+ this.element.addClass('loading');
+ console.log(this.element);
+ },
+ loadend: function (event) {
+ console.log(event);
+ if (event.loaded == event.total) {
+ var domo = this, loading = new Image();
+
+ this.image.source('http://' + kuva.service.url + '/assets/la.gif');
+ loading.src = event.target.result;
+ loading.onload = function () {
+ var height = Math.round(loading.height * 200 / loading.width);
+ console.log(height);
+
+ domo.element.addClass('thumbnailing')
+ .removeClass('loading')
+ .css({width: 200, height: height});
+
+ thumbnailer.thumbnail(loading, 200, function (data) {
+ domo.image.source(data);
+ domo.element.addClass('loaded').removeClass('thumbnailing');
+ }, 3);
+ };
+
+ } else {
+
+ }
+ }
+ }, view = {
+ show: function () {
+
+ }
+ }
+
+ return that;
+})();
@@ -1,21 +1,35 @@
var image = (function () {
- var that = function () {
- return inherit(image);
+ var that = function (element) {
+ element.element = (element && element[0] || element) || new Image();
+ return $.extend(element, inherit(image), inherit(resizable));
};
- var image = inherit({
+ var image = {
+ hide: function () {
+ this[0].style.display = 'none';
+ return this;
+ },
+ show: function () {
+ this[0].style.display = 'block';
+ return this;
+ },
+ source: function (source, callback) {
+ this[0].setAttribute('src', source);
+ callback && this.loaded(callback);
+ },
loaded: function (callback) {
+ // TODO More compatible onload callback
this.onload = callback;
}
- });
+ };
if (Modernizr.canvas) {
- var resizable = inherit({
+ var resizable = {
resize: function (width, height) {
}
- });
+ };
} else {
}
@@ -1,76 +1,57 @@
+var kuva = {
+ service: {
+ url: document.location.host
+ }
+}
+
var photos = (function declare_photos () {
var that = function initialize_photo(options) {
-
- }, reader = null;
-
- // Display outputs of this page
- var view = {
- reader: {
- progress: function() {
- console.log(".");
- },
- abort: function(event) {
- console.log(event);
- // console.log(reader.file.name + " cancelado!");
- },
- loadstart: function(e) {
- console.log("start");
- },
- load: function (event) {
- var file = event.target.file;
- if(file.type.match("image.*"))
- view.photo({
- src: event.target.result,
- name: file.name
- });
-
- console.log(file.name + " loaded!!");
- },
- loadend: function() {
- setTimeout(function () {
- reader.next();
- }, 500);
- }
- },
- uploader: {},
- photo: function (options) {
- $("#photos").jqoteapp("#image-template",{
- src: options.src,
- name: options.name
- }, '*');
- }
+
+ }, reader = lib.reader(), gadgets = [];
+
+ // Setup listeners
+ reader.onprogress = function(event) {
+ gadgets[this.index()].dispatch('progress', event);
};
- // Receives user input
- var control = {
- initialize: function () {
- reader = lib.reader();
-
- for (handler in view.reader) {
- reader['on' + handler] = view.reader[handler];
- }
+ reader.onabort = function(event) {
+ gadgets[this.index()].dispatch('abort', event);
+ };
- $('#files').bind('change', control.changed);
- $('#abort').bind('click', control.aborted);
+ reader.onloadstart = function(event) {
+ gadgets[this.index()].dispatch('loadstart', event);
+ };
- uploader('#files', {uploader: '/photos'});
- },
- changed: function () {
- reader.read(this.files);
- uploader().upload();
- },
- aborted: function () {
- reader.abort();
- }
+ reader.onloadend = function(event) {
+ gadgets[this.index()].dispatch('loadend', event);
+ setTimeout(function () {
+ reader.next();
+ }, 500);
};
+ function change (event) {
+ var i = this.files.length, instance = null;
+ while (i--) {
+ instance = gadget();
+ instance.show();
+ gadgets.push(instance);
+ }
+ reader.read(this.files);
+ }
+ // Setup commands
+ function abort () {
+ reader.abort();
+ }
+
function initialize() {
- control.initialize();
+ $('#files').bind('change', change);
+ $('#abort').bind('click', abort);
$.jqotetag('*');
- }
+ uploader('#files', {thumbnailer: reader});
+ }
$(initialize);
-
+
return that;
})();
@@ -1,16 +1,16 @@
lib = {};
var reader = (function() {
var that = function () {
-
- };
+
+ }
if (Modernizr.filereader) {
var reader = (function () {
var that = function () {
return instance;
- },
+ },
instance = new FileReader(),
- index = 0;
+ index = -1;
instance.files = [];
@@ -19,38 +19,36 @@ var reader = (function() {
this.files.push(files[i]);
}
return this;
- };
-
- instance.next = function () {
- this.file = this.files[index++];
- return this.readAsDataURL(this.file);
- };
-
+ }
+
instance.read = function (files) {
- if (files) {
- instance.add(files);
- if (!runned() || ended()) instance.next();
- }
- };
-
- function ended () {
- return instance.files.length == index;
+ if (files) instance.add(files);
+ if (!ended()) next.call(instance);
}
+ instance.next = instance.read;
- function runned() {
- return index != 0;
+ function next () {
+ this.file = this.files[++index];
+ return this.readAsDataURL(this.file);
}
-
+ function ended () {
+ return (instance.files.length - 1) == index;
+ }
+
+ instance.index = function () {
+ return index;
+ };
+
return that;
- })();
-
+ })();
+
} else {
// var file = inherit({
-
+
// });
}
-
+
this.reader = reader;
return reader;
}).call(lib);
Oops, something went wrong.

0 comments on commit 386de1a

Please sign in to comment.