Created
October 10, 2013 19:04
-
-
Save facultymatt/6923690 to your computer and use it in GitHub Desktop.
Example image controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ImagesController($scope, $routeParams, $location, Global) { | |
// get global settings | |
$scope.global = Global; | |
// set filepicker key | |
filepicker.setKey('Akpol0G7ZQ7ODgRPSZPJRz'); | |
// define our empty image object | |
$scope.newImage = {}; | |
/** | |
* Add an image to a projects Images array | |
* @note needs to be saved to work | |
* | |
*/ | |
$scope.addImageToDest = function(image, dest) { | |
// we copy the image to avoid binding issues | |
destCopy = angular.copy(image); | |
// reset he image | |
image = null; | |
// add to dest array | |
dest.push(destCopy); | |
return image; | |
}; | |
/** | |
* Remove an image from projects Images Array | |
* @note needs to be saved to work | |
* | |
*/ | |
$scope.deleteImageFromDest = function(image, dest) { | |
console.log(Array.isArray(dest)); | |
console.log(dest); | |
// for an array we need to splice | |
if(typeof dest === 'object' && Array.isArray(dest)) { | |
dest.splice(dest.indexOf(image), 1); | |
} else { | |
dest = {}; | |
} | |
console.log(dest); | |
return dest; | |
}; | |
/** | |
* Pick and image and assign to dest object, cropping to specific w and h | |
* @note the original image is deleted, and the cropped image is returned. | |
* | |
*/ | |
$scope.pickImage = function(dest, options) { | |
// set default options | |
var defaultOptions = { | |
fit: 'crop', | |
quality: 100 | |
} | |
options = angular.extend(options, defaultOptions); | |
console.log(options); | |
if(!dest.src) dest.src = ''; | |
if(!dest.original) dest.original = ''; | |
console.log(dest); | |
filepicker.pick(function(InkBlob){ | |
console.log(InkBlob.url); | |
dest.original = InkBlob.url; | |
filepicker.convert(InkBlob, options, function(new_InkBlob){ | |
console.log(new_InkBlob.url); | |
dest.src = new_InkBlob.url; | |
$scope.$apply(); | |
}); | |
}); | |
return dest; | |
}; | |
/** | |
* Pick and image and assign to dest object, cropping to specific w and h | |
* @note the original image is deleted, and the cropped image is returned. | |
* | |
*/ | |
$scope.pickManyImages = function(destArray, options) { | |
// set default options | |
var defaultOptions = { | |
fit: 'crop', | |
quality: 100 | |
} | |
options = angular.extend(options, defaultOptions); | |
console.log(options); | |
if(!destArray) destArray = []; | |
console.log(destArray); | |
filepicker.pickMultiple(function(InkBlobs){ | |
var blobs = InkBlobs; | |
destArray = JSON.stringify(blobs); | |
console.log(destArray); | |
return destArray; | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment