├── .gitignore ├── LICENSE.md ├── README.md ├── app.js ├── calc-complexity.js ├── content └── kollektor.sqlite.default ├── export-to-folder.js ├── find-orphants.js ├── models ├── image.js ├── index.js └── tag.js ├── package.json ├── public ├── css │ ├── ajax-loader.gif │ ├── gallery.css │ ├── reset.css │ └── scraper.css ├── img │ └── screenshot.jpg ├── js │ ├── bookmarklet.js │ ├── gallery.js │ ├── jquery-appear-mod.js │ ├── jquery.js │ ├── palette.js │ ├── plugin.colors.js │ ├── scraper.js │ └── tags.js └── test.html ├── routes ├── api.db.js ├── api.js ├── api.utils.js ├── bookmarklet.js ├── images.js ├── index.js ├── tags.js └── test.js └── views ├── gallery.jade ├── index.jade └── tags.jade /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | public/images 3 | content/images/* 4 | content/*.sqlite 5 | stuff/ 6 | node_modules/ 7 | *.command -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Marcin Ignac 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NoGUI™ Node.js app for collecting images / inspiration / mood boards. 2 | 3 | ![Alt text](/public/img/screenshot.jpg "Kollektor") 4 | 5 | Brought to you by Marcin Ignac http://marcinignac.com 6 | 7 | ### Setup 8 | 9 | Download the git repo 10 | 11 | git clone git@github.com:vorg/kollektor.git 12 | 13 | Install native binaries of [graphicsmagick](http://www.graphicsmagick.org) 14 | 15 | //OSX with homebrew 16 | brew install graphicsmagick 17 | 18 | Install node dependencies 19 | 20 | cd kollector 21 | npm install 22 | 23 | Start the app 24 | 25 | node app.js 26 | 27 | ### Uploading images 28 | 29 | Visit your (empty) image collection by opening 30 | 31 | http://localhost:3000/ 32 | 33 | 34 | Drag some image files from your desktop to the browser window (a yellow overlay should appear on drag over). 35 | 36 | ### Editing images 37 | 38 | To edit image metadata mouse over the thumbnail and press and hold the url / title / tags. After editing press ENTER to save your changes. 39 | 40 | Tags are space separated. 41 | 42 | Delete/Refresh links are part of the tag list so you have to click one of them if there is no other tags. Refresh doesn't do anything yet. 43 | 44 | ### Scraping images from other websites 45 | 46 | To add images from other websites go to bookmarklet url, copy the code and add new bookmark to you bookmarks bar. 47 | 48 | http://localhost:3000/bookmarklet 49 | 50 | Visit any website and launch the bookmarket. You should get list of thumbnails and 2 input fields. First is the title, seconds is space separated list of tags. Click any thumbnail, update title and tags and press 'add' button. Press 'ESC' to close thumbnail list. 51 | 52 | ### Extra 53 | 54 | To see all your tags with recent images (aka pinterest boards) go to 55 | 56 | http://localhost:3000/tags/ 57 | 58 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var routes = require('./routes'); 3 | var fs = require('fs'); 4 | var persist = require('persist'); 5 | var multipart = require('connect-multiparty'); 6 | var multipartMiddleware = multipart(); 7 | 8 | //Settings 9 | 10 | var SERVER_PORT = 3000; 11 | 12 | var DB_CONFIG = { 13 | 'driver': 'sqlite3', 14 | 'filename': 'content/kollektor.sqlite', 15 | 'defautFilename': 'content/kollektor.sqlite.default' 16 | }; 17 | 18 | // DB Configuration 19 | 20 | persist.setDefaultConnectOptions(DB_CONFIG); 21 | 22 | if (!fs.existsSync(__dirname + '/content/images')) { 23 | fs.mkdir(__dirname + '/content/images'); 24 | } 25 | 26 | //check if DB exists and create new one if it doesn't 27 | if (!fs.existsSync(DB_CONFIG.filename)) { 28 | fs.createReadStream(__dirname + '/' + DB_CONFIG.defautFilename).pipe(fs.createWriteStream(__dirname + '/' + DB_CONFIG.filename)); 29 | } 30 | 31 | // App Configuration 32 | 33 | var app = module.exports = express(); 34 | 35 | app.set('views', __dirname + '/views'); 36 | app.set('view engine', 'jade'); 37 | app.set('view options', { layout: false, pretty: true }); 38 | app.use(express.static(__dirname + '/public')); 39 | 40 | app.get('/', routes.index); 41 | app.get('/tag/*', routes.index); 42 | app.get('/complexity/*', routes.index); 43 | app.get('/s/*', routes.index); 44 | app.get('/bookmarklet', routes.bookmarklet); 45 | app.get('/api/get/*', routes.api.get); 46 | app.get('/api/post', routes.api.post); 47 | app.get('/api/update', routes.api.update); 48 | app.post('/api/upload', multipartMiddleware, routes.api.upload); 49 | app.get('/api/delete', routes.api.delete); 50 | app.get('/api/tags', routes.api.tags); 51 | app.get('/api/latest', routes.api.latest); 52 | app.get('/tags', routes.tags); 53 | app.get('/images/*', routes.images); 54 | app.get('/js/config.js', function(req, res) { 55 | res.send('var inspiration_server = "http://localhost:'+SERVER_PORT+'"; var inspiration_tags = ""'); 56 | }) 57 | 58 | app.listen(SERVER_PORT, function(){ 59 | console.log("Express server listening on port %d in %s mode", SERVER_PORT, app.settings.env); 60 | }); 61 | -------------------------------------------------------------------------------- /calc-complexity.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var persist = require("persist"); 3 | var type = persist.type; 4 | var models = require('./models'); 5 | var path = require('path'); 6 | var gm = require('gm'); 7 | var im = require('imagemagick'); 8 | var exec = require('sync-exec'); 9 | var db = require('./routes/api.db'); 10 | 11 | var DB_CONFIG = { 12 | 'driver': 'sqlite3', 13 | 'filename': __dirname + '/content/kollektor.sqlite', 14 | 'defautFilename': 'content/kollektor.sqlite.default' 15 | }; 16 | persist.setDefaultConnectOptions(DB_CONFIG); 17 | 18 | var imagesDir = __dirname + '/content/images'; 19 | var dbFile = __dirname + '/content/kollektor.sqlite'; 20 | 21 | var files = fs.readdirSync(imagesDir); 22 | console.log('files', files.length); 23 | console.log(files.slice(0, 10)); 24 | 25 | persist.connect(function(err, connection) { 26 | console.log('connected'); 27 | var cached = {}; 28 | var orphants = 0; 29 | var zombies = 0; 30 | models.Image.using(connection).orderBy('id', 'desc').include("tags").all(function(err, imagesData) { 31 | console.log('imagesData', imagesData.length*2, 'orphants:', (files.length - imagesData.length*2)/2 + '?'); 32 | imagesData.forEach(function(img){ 33 | cached[img.cachedUrl] = img; 34 | cached[img.thumbUrl] = img; 35 | }) 36 | 37 | 38 | function processNext() { 39 | if (files.length == 0) { 40 | return; 41 | } 42 | var file = files.shift(); 43 | 44 | while (!cached[file]) { 45 | file = files.shift(); 46 | } 47 | 48 | if (files.length == 0) { 49 | return; 50 | } 51 | 52 | var fileThumb = base + '_thumb' + ext; 53 | var filePath = imagesDir + '/' + file; 54 | var fileThumbPath = imagesDir + '/' + file; 55 | var ext = path.extname(file); 56 | var base = path.basename(file, ext); 57 | var stats = fs.statSync(filePath); 58 | var hasThumb = false; 59 | var tags = ['sys-orphant'] 60 | if (files[0] == fileThumb) { 61 | files.shift(); 62 | hasThumb = true; 63 | } 64 | else { 65 | fileThumb = file; 66 | fileThumbPath = filePath; 67 | tags.push('sys-no-thumb'); 68 | } 69 | 70 | var img = cached[file]; 71 | var tags = img.tags.map(function(t) { return t.name;}); 72 | var needsRecalc = !img.complexity; 73 | if (needsRecalc) { 74 | var complexity = exec("convert " + fileThumbPath + " -delete 1--1 -scale 128x128 -grayscale rec709luma -morphology EdgeOut Octagon -threshold 25% -format '%[fx:mean]' histogram:info:").stdout; 75 | complexity = complexity.split('\n')[0]; 76 | if (isNaN(complexity)) { 77 | console.log('invalid', complexity) 78 | } 79 | complexity = isNaN(complexity) ? 0 : Number(complexity); 80 | console.log(files.length, file, complexity); 81 | var imageData = { 82 | id: img.id, 83 | title: img.title, 84 | referer: img.referer, 85 | originalUrl : img.originalUrl, 86 | cachedUrl : img.cachedUrl, 87 | thumbUrl : img.thumbUrl, 88 | ratio : img.ratio, 89 | complexity: complexity, 90 | tags: tags 91 | } 92 | 93 | models.Image.update(connection, Number(img.id), { complexity: complexity }, function(err) { 94 | setTimeout(processNext, 1); 95 | }); 96 | // 97 | } 98 | else { 99 | setTimeout(processNext, 1); 100 | } 101 | 102 | 103 | //if (ext == '.gif') { 104 | //var info = exec("identify -format '%W x %H\n' " + filePath); 105 | //if (info.stdout) { 106 | // var size = info.stdout.split('\n')[0].split(' x '); 107 | // var ratio = size[0]/size[1]; 108 | // console.log(files.length, file, size); 109 | 110 | // var imageData = { 111 | // title: base, 112 | // referer: "", 113 | // originalUrl : "", 114 | // cachedUrl : file, 115 | // thumbUrl : fileThumb, 116 | // ratio : ratio, 117 | // tags: tags 118 | // } 119 | 120 | // //db.addImage(connection, imageData, function() { 121 | // setTimeout(processNext, 1); 122 | // //}) 123 | //} 124 | //else { 125 | // //console.log(files.length, file, 'invalid file'); 126 | // //fs.unlink(filePath); 127 | //} 128 | } 129 | 130 | processNext(); 131 | }); 132 | }); -------------------------------------------------------------------------------- /content/kollektor.sqlite.default: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vorg/kollektor/4f19df13903c433fd82102a8bc3ecfe84d742695/content/kollektor.sqlite.default -------------------------------------------------------------------------------- /export-to-folder.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs') 2 | var persist = require('persist') 3 | var models = require('./models') 4 | var path = require('path') 5 | var exec = require('sync-exec') 6 | 7 | var DB_CONFIG = { 8 | 'driver': 'sqlite3', 9 | 'filename': __dirname + '/content/kollektor.sqlite' 10 | } 11 | persist.setDefaultConnectOptions(DB_CONFIG) 12 | 13 | var imagesDir = __dirname + '/content/images' 14 | 15 | var files = fs.readdirSync(imagesDir) 16 | var numFiles = files.length 17 | console.log('files', files.length) 18 | console.log(files.slice(0, 10)) 19 | 20 | var targetPath = '/Users/vorg/Dropbox/Kollektor' 21 | 22 | if (!fs.existsSync(targetPath)) { 23 | fs.mkdirSync(targetPath) 24 | } 25 | 26 | persist.connect(function (err, connection) { 27 | if (err) { 28 | console.log(err) 29 | return 30 | } 31 | console.log('connected') 32 | var timeout = 1000 33 | 34 | function processNext () { 35 | if (files.length === 0) { 36 | return 37 | } 38 | var file = files.shift() 39 | console.log(`processing ${file} - ${numFiles - files.length}/${numFiles}`) 40 | 41 | var extName = path.extname(file) 42 | var baseFileName = path.basename(file, extName) 43 | if (baseFileName.lastIndexOf('_thumb') === baseFileName.length - '_thumb'.length) { 44 | console.log(' skipping thumbnail') 45 | setTimeout(processNext, 1) 46 | return 47 | } 48 | var fullFilePath = imagesDir + '/' + file 49 | var fullThumbPath = imagesDir + '/' + baseFileName + '_thumb' + extName 50 | 51 | console.log('', fullFilePath) 52 | console.log('', fullThumbPath) 53 | 54 | var stat = fs.statSync(fullFilePath) 55 | var month = stat.ctime.getFullYear() + '-' + ('0' + stat.ctime.getMonth()).slice(-2) 56 | var targetMonthPath = targetPath + '/' + month 57 | var targetFilePath = targetMonthPath + '/' + file 58 | // var targetThumbPath = targetMonthPath + '/' + baseFileName + '_thumb' + extName 59 | var targetDataPath = targetMonthPath + '/' + file + '.json' 60 | 61 | if (!fs.existsSync(targetMonthPath)) { 62 | fs.mkdirSync(targetMonthPath) 63 | } 64 | 65 | exec(`cp ${fullFilePath} ${targetFilePath}`) 66 | // exec(`cp ${fullThumbPath} ${targetThumbPath}`) 67 | 68 | function saveData (data) { 69 | var dataStr = JSON.stringify(data, null, 2) 70 | fs.writeFileSync(targetDataPath, dataStr) 71 | } 72 | 73 | models.Image.where({ cachedUrl: file }).all(connection, function (err, imageData) { 74 | if (err) console.log(err) 75 | imageData = imageData ? imageData[0] : null 76 | if (!imageData) { 77 | setTimeout(processNext, timeout) 78 | return 79 | } 80 | var data = { 81 | // Here we use created as we know files were added by collector so the time 82 | // is increasing as we add new files. However if we now add support for 83 | // just dragging files into a folder, then we probably should use the date from json 84 | // or the date when the json was created. This will bring another problem when uploading files: 85 | // how to detect if file was uploaded and we are about to create json file immediately with user suplied data 86 | // or somebody just put a new file into a folder and we have create json file ourselves with default data. 87 | added: stat.ctime.toISOString(), 88 | title: imageData.title || '', 89 | referer: imageData.referer || '', 90 | original: imageData.originalUrl || '', 91 | cached: imageData.cachedUrl || '', 92 | // thumb: imageData.thumbUrl || '', 93 | ratio: imageData.ratio || '', 94 | tags: [] 95 | } 96 | if (imageData.tags) { 97 | imageData.tags.all(function (err, tagsData) { 98 | if (err) console.log(err) 99 | var tags = tagsData.map(function (tag) { 100 | return tag.name 101 | }) 102 | data.tags = tags 103 | saveData(data) 104 | setTimeout(processNext, timeout) 105 | }) 106 | } else { 107 | saveData(data) 108 | setTimeout(processNext, timeout) 109 | } 110 | }) 111 | 112 | // processNext() 113 | } 114 | 115 | processNext() 116 | 117 | /* 118 | models.Image.using(connection).orderBy('id', 'desc').all(function (err, imagesData) { 119 | if (err) { 120 | console.log(err) 121 | return 122 | } 123 | console.log('imagesData', imagesData.length, 'orphants:', (files.length - imagesData.length * 2) / 2 + '?') 124 | imagesData.forEach(function (img) { 125 | cached[img.cachedUrl] = true 126 | cached[img.thumbUrl] = true 127 | }) 128 | 129 | function processNext () { 130 | 131 | while (cached[file]) { 132 | file = files.shift() 133 | } 134 | 135 | if (files.length === 0) { 136 | return 137 | } 138 | 139 | var filePath = imagesDir + '/' + file 140 | var ext = path.extname(file) 141 | var base = path.basename(file, ext) 142 | var fileThumb = base + '_thumb' + ext 143 | var hasThumb = false 144 | var tags = ['sys-orphant'] 145 | if (files[0] === fileThumb) { 146 | files.shift() 147 | hasThumb = true 148 | } else { 149 | fileThumb = file 150 | tags.push('sys-no-thumb') 151 | } 152 | 153 | // if (ext == '.gif') { 154 | var info = exec("identify -format '%W x %H\n' " + filePath) 155 | if (info.stdout) { 156 | var size = info.stdout.split('\n')[0].split(' x ') 157 | var ratio = size[0] / size[1] 158 | console.log(files.length, file, size, hasThumb) 159 | 160 | var imageData = { 161 | title: base, 162 | referer: '', 163 | originalUrl: '', 164 | cachedUrl: file, 165 | thumbUrl: fileThumb, 166 | ratio: ratio, 167 | tags: tags 168 | } 169 | 170 | db.addImage(connection, imageData, function (err, ok) { 171 | if (err) { 172 | console.log(err) 173 | } 174 | // console.log(err, ok) 175 | setTimeout(processNext, 1) 176 | }) 177 | } else { 178 | console.log(files.length, file, 'invalid file') 179 | // fs.unlink(filePath) 180 | } 181 | } 182 | 183 | processNext() 184 | }) 185 | */ 186 | }) 187 | -------------------------------------------------------------------------------- /find-orphants.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var persist = require("persist"); 3 | var type = persist.type; 4 | var models = require('./models'); 5 | var path = require('path'); 6 | var gm = require('gm'); 7 | var im = require('imagemagick'); 8 | var exec = require('sync-exec'); 9 | var db = require('./routes/api.db'); 10 | 11 | var DB_CONFIG = { 12 | 'driver': 'sqlite3', 13 | 'filename': __dirname + '/content/kollektor.sqlite', 14 | 'defautFilename': 'content/kollektor.sqlite.default' 15 | }; 16 | persist.setDefaultConnectOptions(DB_CONFIG); 17 | 18 | var imagesDir = __dirname + '/content/images'; 19 | var dbFile = __dirname + '/content/kollektor.sqlite'; 20 | 21 | var files = fs.readdirSync(imagesDir); 22 | console.log('files', files.length); 23 | console.log(files.slice(0, 10)); 24 | 25 | persist.connect(function(err, connection) { 26 | console.log('connected'); 27 | var cached = {}; 28 | var orphants = 0; 29 | var zombies = 0; 30 | models.Image.using(connection).orderBy('id', 'desc').all(function(err, imagesData) { 31 | console.log('imagesData', imagesData.length, 'orphants:', (files.length - imagesData.length*2)/2 + '?'); 32 | imagesData.forEach(function(img){ 33 | cached[img.cachedUrl] = true; 34 | cached[img.thumbUrl] = true; 35 | }) 36 | 37 | 38 | function processNext() { 39 | if (files.length == 0) { 40 | return; 41 | } 42 | var file = files.shift(); 43 | 44 | while (cached[file]) { 45 | file = files.shift(); 46 | } 47 | 48 | if (files.length == 0) { 49 | return; 50 | } 51 | 52 | var filePath = imagesDir + '/' + file; 53 | var ext = path.extname(file); 54 | var base = path.basename(file, ext); 55 | var stats = fs.statSync(filePath); 56 | var fileThumb = base + '_thumb' + ext; 57 | var fileThumbPath = imagesDir + '/' + file; 58 | var hasThumb = false; 59 | var tags = ['sys-orphant'] 60 | if (files[0] == fileThumb) { 61 | files.shift(); 62 | hasThumb = true; 63 | } 64 | else { 65 | fileThumb = file; 66 | fileThumbPath = filePath; 67 | tags.push('sys-no-thumb'); 68 | } 69 | 70 | 71 | //if (ext == '.gif') { 72 | var info = exec("identify -format '%W x %H\n' " + filePath); 73 | if (info.stdout) { 74 | var size = info.stdout.split('\n')[0].split(' x '); 75 | var ratio = size[0]/size[1]; 76 | console.log(files.length, file, size, hasThumb); 77 | 78 | var imageData = { 79 | title: base, 80 | referer: "", 81 | originalUrl : "", 82 | cachedUrl : file, 83 | thumbUrl : fileThumb, 84 | ratio : ratio, 85 | tags: tags 86 | } 87 | 88 | db.addImage(connection, imageData, function(err, ok) { 89 | // console.log(err, ok) 90 | setTimeout(processNext, 1); 91 | }) 92 | } 93 | else { 94 | console.log(files.length, file, 'invalid file'); 95 | //fs.unlink(filePath); 96 | } 97 | } 98 | 99 | processNext(); 100 | }); 101 | }); -------------------------------------------------------------------------------- /models/image.js: -------------------------------------------------------------------------------- 1 | var persist = require("persist"); 2 | var type = persist.type; 3 | 4 | var Tag = require("./tag"); 5 | 6 | module.exports = persist.define("Image", { 7 | "title": type.STRING, 8 | "referer": type.STRING, 9 | "originalUrl": type.STRING, 10 | "cachedUrl": type.STRING, 11 | "thumbUrl": type.STRING, 12 | "ratio": type.REAL, 13 | "complexity": type.REAL, 14 | }).hasMany(Tag, { through:'images_tags' }); 15 | -------------------------------------------------------------------------------- /models/index.js: -------------------------------------------------------------------------------- 1 | exports.Image = require('./image'); 2 | exports.Tag = require('./tag'); -------------------------------------------------------------------------------- /models/tag.js: -------------------------------------------------------------------------------- 1 | var persist = require("persist"); 2 | var type = persist.type; 3 | 4 | module.exports = persist.define("Tag", { 5 | "name": type.STRING 6 | }); 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "application-name", 3 | "version": "0.0.1", 4 | "private": true, 5 | "dependencies": { 6 | "body-parser": "^1.11.0", 7 | "connect-multiparty": "^1.2.5", 8 | "express": "^4.11.2", 9 | "gm": "^1.9.2", 10 | "imagemagick": "^0.1.3", 11 | "jade": "^1.9.2", 12 | "mime-magic": "^5.14.0", 13 | "persist": "^0.2.7", 14 | "sqlite3": "^3.0.4" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /public/css/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vorg/kollektor/4f19df13903c433fd82102a8bc3ecfe84d742695/public/css/ajax-loader.gif -------------------------------------------------------------------------------- /public/css/gallery.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: helvetica, verdana, arial; 4 | background: white; 5 | xbackground: black; 6 | } 7 | 8 | body * { 9 | margin: 0; 10 | padding: 0; 11 | } 12 | 13 | a { 14 | text-decoration: none; 15 | color: #FF4400; 16 | } 17 | 18 | a:hover { 19 | text-decoration: underline; 20 | } 21 | 22 | a.titleLink { 23 | color: #999; 24 | display: block; 25 | } 26 | 27 | a.refererLink { 28 | color: rgb(170, 170, 170); 29 | display: block; 30 | } 31 | 32 | div.linksWrapper.contentEditable, 33 | a.contentEditable h2, 34 | a.contentEditable h5 { 35 | background: #FFFFDD; 36 | } 37 | 38 | h1 { 39 | padding: 0.5em; 40 | font-size: 200%; 41 | text-transform: uppercase; 42 | } 43 | 44 | h1 a { 45 | color: #000; 46 | } 47 | 48 | h1 span { 49 | font-weight: 100; 50 | } 51 | 52 | .centered { 53 | text-align: center; 54 | } 55 | 56 | .column { 57 | width: 300px; 58 | margin: 10px 0 0 10px; 59 | float: left; 60 | } 61 | 62 | .imageWrapper { 63 | width: 300px; 64 | position: relative; 65 | xbackground: yellow; 66 | 67 | x-webkit-transition: all 1s ease-in-out; 68 | x-moz-transition: all 1s ease-in-out; 69 | x-o-transition: all 1s ease-in-out; 70 | x-ms-transition: all 1s ease-in-out; 71 | } 72 | 73 | .imageWrapper .titleLink { 74 | } 75 | 76 | .imageWrapper { 77 | margin-bottom: 10px; 78 | } 79 | 80 | .imageWrapper img { 81 | -webkit-transition: all 0.5s ease-in-out; 82 | -moz-transition: all 0.5s ease-in-out; 83 | -o-transition: all 0.5s ease-in-out; 84 | -ms-transition: all 0.5s ease-in-out; 85 | } 86 | 87 | .imageWrapper .overlay { 88 | position: absolute; 89 | top: 0px; 90 | left: 0px; 91 | padding: 5px; 92 | display: none; 93 | } 94 | 95 | .imageWrapper:hover .overlay { 96 | display: block; 97 | } 98 | 99 | .imageWrapper h2 { 100 | width: 280px; 101 | max-width: 280px; 102 | padding: 5px; 103 | background: rgba(255, 255, 255, 1); 104 | color: black; 105 | xbackground: black; 106 | xcolor: white; 107 | text-overflow: ellipsis; 108 | overflow: hidden; 109 | font-size: 125%; 110 | font-weight: 100; 111 | } 112 | 113 | .imageWrapper h5 { 114 | width: 280px; 115 | max-width: 280px; 116 | padding: 5px 5px 0px 5px; 117 | background: rgba(255, 255, 255, 1); 118 | xbackground: black; 119 | xcolor: white; 120 | text-overflow: ellipsis; 121 | overflow: hidden; 122 | font-size: 75%; 123 | font-weight: 100; 124 | } 125 | 126 | 127 | .imageWrapper .linksWrapper { 128 | width: 280px; 129 | background: rgba(255, 255, 255, 1); 130 | xbackground: black; 131 | padding: 0 5px 5px 5px; 132 | } 133 | 134 | .imageWrapper .optionsWrapper { 135 | background: rgba(255, 255, 255, 1); 136 | font-size: 90%; 137 | } 138 | 139 | .optionsLink { 140 | color: #AAA; 141 | font-weight: 100; 142 | xcolor: rgb(64, 218, 158); 143 | } 144 | 145 | .imageWrapper img { 146 | cursor: pointer; 147 | } 148 | 149 | .tagLatestMain { 150 | } 151 | 152 | .tagLatestThumb { 153 | width: 74.25px; 154 | height: 75px; 155 | overflow: hidden; 156 | float: left; 157 | margin-left: 1px; 158 | } 159 | 160 | .tagLatestThumb:first-child { 161 | margin-left: 0; 162 | } 163 | 164 | .set { 165 | overflow: auto; 166 | } 167 | 168 | #dropzone { 169 | position: absolute; 170 | left: 0; 171 | top: 0; 172 | width: 100%; 173 | height: 100%; 174 | z-index: 50; 175 | text-align: center; 176 | background: rgba(255, 255, 0, 0.85); 177 | display: none; 178 | } 179 | 180 | #dropzone.active { 181 | display: block; 182 | } 183 | 184 | #dropzone.hover { 185 | display: block; 186 | } 187 | 188 | #dropzone p { 189 | margin: 25% auto; 190 | font-size: 300%; 191 | } 192 | 193 | #search { 194 | font-size: 200%; 195 | position: fixed; 196 | top: 30%; 197 | min-width: 500px; 198 | margin: 0 auto; 199 | padding: 1em; 200 | min-height: 1.2em; 201 | background: rgba(0,0,0,0.8); 202 | color: white; 203 | border-radius: 0.5em; 204 | } 205 | 206 | @media only screen and (max-device-width: 800px) { 207 | .imageWrapper { 208 | overflow: visible; 209 | height: auto !important; 210 | } 211 | 212 | .imageWrapper .overlay { 213 | display: block; 214 | position: inherit; 215 | padding: 5px; 216 | } 217 | } 218 | 219 | @media print { 220 | .imageWrapper { 221 | overflow: visible; 222 | height: auto !important; 223 | } 224 | 225 | .imageWrapper .overlay { 226 | display: block; 227 | position: inherit; 228 | padding: 5px; 229 | } 230 | } -------------------------------------------------------------------------------- /public/css/reset.css: -------------------------------------------------------------------------------- 1 | /* http://meyerweb.com/eric/tools/css/reset/ 2 | v2.0 | 20110126 3 | License: none (public domain) 4 | */ 5 | 6 | html, body, div, span, applet, object, iframe, 7 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 8 | a, abbr, acronym, address, big, cite, code, 9 | del, dfn, em, img, ins, kbd, q, s, samp, 10 | small, strike, strong, sub, sup, tt, var, 11 | b, u, i, center, 12 | dl, dt, dd, ol, ul, li, 13 | fieldset, form, label, legend, 14 | table, caption, tbody, tfoot, thead, tr, th, td, 15 | article, aside, canvas, details, embed, 16 | figure, figcaption, footer, header, hgroup, 17 | menu, nav, output, ruby, section, summary, 18 | time, mark, audio, video { 19 | margin: 0; 20 | padding: 0; 21 | border: 0; 22 | font-size: 100%; 23 | font: inherit; 24 | vertical-align: baseline; 25 | } 26 | /* HTML5 display-role reset for older browsers */ 27 | article, aside, details, figcaption, figure, 28 | footer, header, hgroup, menu, nav, section { 29 | display: block; 30 | } 31 | body { 32 | line-height: 1; 33 | } 34 | ol, ul { 35 | list-style: none; 36 | } 37 | blockquote, q { 38 | quotes: none; 39 | } 40 | blockquote:before, blockquote:after, 41 | q:before, q:after { 42 | content: ''; 43 | content: none; 44 | } 45 | table { 46 | border-collapse: collapse; 47 | border-spacing: 0; 48 | } 49 | -------------------------------------------------------------------------------- /public/css/scraper.css: -------------------------------------------------------------------------------- 1 | #inspiration3141592653589793 { 2 | position: fixed; 3 | top: 0; 4 | left: 0; 5 | width: 100%; 6 | background: #FFF; 7 | padding: 0 0 1px 0; 8 | border-bottom:2px solid black; 9 | z-index: 9999999; /*higher than The Verge*/ 10 | z-index: 2147483647; /*max int in css, go to hell youtube*/ 11 | } 12 | 13 | #inspiration3141592653589793 .thumb { 14 | border: 1px solid #FFF; 15 | margin: 1px 0 0 1px; 16 | width: 80px; 17 | height: 80px; 18 | float: left; 19 | position: relative; 20 | overflow: hidden; 21 | } 22 | 23 | #inspiration3141592653589793 .thumb:hover { 24 | cursor: pointer; 25 | } 26 | 27 | #inspiration3141592653589793 .thumb img { 28 | position: absolute; 29 | } -------------------------------------------------------------------------------- /public/img/screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vorg/kollektor/4f19df13903c433fd82102a8bc3ecfe84d742695/public/img/screenshot.jpg -------------------------------------------------------------------------------- /public/js/bookmarklet.js: -------------------------------------------------------------------------------- 1 | javascript:( 2 | function() { 3 | var body = document.getElementsByTagName("body")[0]; 4 | var head = document.getElementsByTagName("head")[0]; 5 | function appendScript() { 6 | var scriptJQuery = document.createElement("script"); 7 | head.appendChild(scriptJQuery); 8 | scriptJQuery.src = "JQUERY_JS"; 9 | var script = document.createElement("script"); 10 | head.appendChild(script); 11 | script.src = "SCRAPER_JS"; 12 | var link = document.createElement("link"); 13 | link.rel = "stylesheet"; 14 | link.type = "text/css"; 15 | link.href = "SCRAPER_CSS"; 16 | head.appendChild(link); 17 | } 18 | if (body) { 19 | appendScript(); 20 | } 21 | else { 22 | var oldDocumentOnReady = document.onready; 23 | document.onready = function(e) { 24 | body = document.getElementsByTagName("body")[0]; 25 | setTimeout(appendScript, 300); 26 | document.onready = oldDocumentOnReady; 27 | if (document.onready) document.onready(e); 28 | } 29 | } 30 | } 31 | )() 32 | 33 | -------------------------------------------------------------------------------- /public/js/gallery.js: -------------------------------------------------------------------------------- 1 | var startImageIndex = 0; 2 | var maxImagesLimit = 50; 3 | var thumbWidth = 300; 4 | var columnMargin = 10; 5 | var columnWidth = thumbWidth + columnMargin; 6 | var columns = []; 7 | var imagesData; 8 | 9 | var images = []; 10 | 11 | String.prototype.format = function() { 12 | var args = arguments; 13 | return this.replace(/{(\d+)}/g, function(match, number) { 14 | return typeof args[number] != 'undefined' 15 | ? args[number] 16 | : match 17 | ; 18 | }); 19 | }; 20 | 21 | function buildColumns() { 22 | var w = document.body.clientWidth; 23 | var numColumns = Math.floor(w/columnWidth); 24 | for(var i=0; i'); 29 | $(document.body).append(column.div); 30 | columns.push(column); 31 | } 32 | } 33 | 34 | function findColumn() { 35 | var min = 99999999; 36 | var mini = 0; 37 | for(var i=0; i'); 130 | 131 | var link = $(''); 132 | var image = new Image(); 133 | link.append(image); 134 | wrapper.append(link); 135 | 136 | var overlay = $('
'); 137 | wrapper.append(overlay); 138 | 139 | function extractHost(url) { 140 | if (!url || url == "") return "Unknown"; 141 | var slashPosition = url.indexOf("/", url.indexOf("//") + 3); 142 | if (slashPosition == -1) slashPosition = url.length; 143 | return url.substr(0, slashPosition); 144 | } 145 | 146 | //URL 147 | 148 | var refererTag = '
{1}
'; 149 | var refererUrl = imgInfo.referer ? imgInfo.referer : "Unknown" 150 | var referer = $(refererTag.format(refererUrl, extractHost(imgInfo.referer))); 151 | overlay.append(referer); 152 | 153 | makeContentEditable( 154 | referer, 155 | function() { 156 | var refererUrl = referer.attr("href"); 157 | referer.data("oldreferer", refererUrl) 158 | referer.find("h5").html(refererUrl); 159 | selectElement(referer.find("h5")); 160 | }, 161 | function(success) { 162 | if (success) { 163 | var newReferer = referer.find("h5").text(); 164 | console.log("Saving new referer...", newReferer, "for image", imgInfo.id); 165 | updateImageData({ 166 | id: imgInfo.id, 167 | referer: newReferer 168 | }) 169 | referer.attr("href", newReferer); 170 | title.attr("href", newReferer); 171 | referer.find("h5").html(extractHost(newReferer)); 172 | } 173 | else { 174 | referer.find("h2").text(extractHost(referer.data("oldtitle"))); 175 | } 176 | referer.data("oldtitle", ""); 177 | } 178 | ); 179 | 180 | //TITLE 181 | 182 | var titleTag = '

{1}

'; 183 | var title = $(titleTag.format(imgInfo.referer, imgInfo.title)); 184 | overlay.append(title); 185 | 186 | makeContentEditable( 187 | title, 188 | function() { 189 | title.data("oldtitle", title.find("h2").text()) 190 | selectElement(title.find("h2")); 191 | }, 192 | function(success) { 193 | if (success) { 194 | var newTitle = title.find("h2").text(); 195 | console.log("Saving new title...", newTitle, "for image", imgInfo.id); 196 | updateImageData({ 197 | id: imgInfo.id, 198 | title: newTitle 199 | }) 200 | 201 | } 202 | else { 203 | title.find("h2").text(title.data("oldtitle")); 204 | } 205 | title.data("oldtitle", ""); 206 | } 207 | ); 208 | 209 | //TAG LINKS 210 | 211 | function refreshImage() { 212 | 213 | } 214 | 215 | function deleteImage() { 216 | if (!confirm("Are you sure to delete " + imgInfo.title)) { 217 | return false; 218 | } 219 | $.get(inspiration_server + "/api/delete?imageId=" + imgInfo.id, function(result) { 220 | if (!result.err) { 221 | wrapper.slideUp(); 222 | } 223 | }); 224 | return false; 225 | } 226 | 227 | var linksWrapper = $(''); 228 | 229 | function tagsToLinks(tags) { 230 | var numLinks = 0; 231 | linksWrapper.html(""); 232 | $(tags) 233 | //.filter(function(tag) { return this.indexOf('p-') !== 0; }) 234 | .each(function() { 235 | var tag = this; 236 | if (numLinks++ > 0) linksWrapper.append(", "); 237 | var tagLink = $(''+tag+''); 238 | tagLink.click(function(e) { 239 | if (e.shiftKey) { 240 | e.preventDefault(); 241 | if (document.location.href.indexOf("/tag/") > 0) { 242 | document.location.href = document.location.href + "+" + tag; 243 | } 244 | else { 245 | document.location.href = tagLink.attr("href"); 246 | } 247 | } 248 | }) 249 | linksWrapper.append(tagLink); 250 | }) 251 | 252 | var refreshLink = $('refresh'); 253 | refreshLink.click(refreshImage); 254 | 255 | var deleteLink = $('delete'); 256 | deleteLink.click(deleteImage); 257 | //var complexityLink = $('' + imgInfo.complexity +''); 258 | //var idLink = $('#' + imgInfo.id +''); 259 | 260 | //linksWrapper.append(", ", refreshLink, ", ", deleteLink, ',', complexityLink, ',', idLink); 261 | linksWrapper.append(", ", refreshLink, ", ", deleteLink); 262 | } 263 | 264 | tagsToLinks(imgInfo.tags); 265 | overlay.append(linksWrapper); 266 | 267 | //OPTIONS 268 | 269 | //var optionsWrapper = $('
') 270 | //overlay.append(optionsWrapper); 271 | // 272 | //var deleteLink = $(''); 273 | //optionsWrapper.append(deleteLink); 274 | // 275 | //var refreshLink = $(''); 276 | //optionsWrapper.append(refreshLink); 277 | 278 | function cleanTagText(text) { 279 | return text.replace(/^\s+/, '').replace(/,/g, ' ').replace(/\s+/g, ' ').replace(/\s+$/, ''); 280 | } 281 | 282 | makeContentEditable( 283 | linksWrapper, 284 | function() { 285 | linksWrapper.find(".optionsLink").remove(); 286 | linksWrapper.data("oldtags", linksWrapper.text()); 287 | linksWrapper.html(cleanTagText(linksWrapper.text())); 288 | selectElement(linksWrapper); 289 | }, 290 | function(success) { 291 | var tags; 292 | if (success) { 293 | tags = cleanTagText(linksWrapper.text()).split(' '); 294 | console.log("Saving new tags...", tags, "for image", imgInfo.id); 295 | updateImageData({ 296 | id: imgInfo.id, 297 | tags: tags.join(",") 298 | }) 299 | } 300 | else { 301 | tags = cleanTagText(linksWrapper.data("oldtags")).split(' '); 302 | } 303 | tagsToLinks(tags); 304 | 305 | linksWrapper.data("oldtags", ""); 306 | } 307 | ); 308 | 309 | //IMAGE 310 | 311 | $(image).attr("data-src", "/images/" + imgInfo.thumbUrl); 312 | $(image).attr("src", "/images/" + imgInfo.thumbUrl); 313 | if (prepend) { 314 | wrapper.hide(); 315 | $(image).attr("src", "/images/" + imgInfo.thumbUrl); 316 | setTimeout(function() { 317 | wrapper.slideDown(); 318 | }, 1000) 319 | } 320 | 321 | var width = thumbWidth; 322 | var height = width / imgInfo.ratio; 323 | wrapper.css("height", height); 324 | var column = findColumn(); 325 | 326 | if (prepend) 327 | column.div.prepend(wrapper); 328 | else 329 | column.div.append(wrapper); 330 | column.height += height; 331 | 332 | image.width = width; 333 | image.height = width / imgInfo.ratio; 334 | 335 | //PLUGINS 336 | 337 | // image.onload = function() { 338 | // console.log('Image loaded ' + inspirationPlugins.length) 339 | // inspirationPlugins.forEach(function(plugin, i) { 340 | // if (!window.once) window.once = 0; 341 | // if (window.once++ < 5) { 342 | // window.once = true; 343 | // if (!imgInfo.plugindata || !(plugin.name in imgInfo.plugindata)) { 344 | // console.log('Running', plugin.name, 'on', imgInfo); 345 | // plugin.run(imgInfo, image, linksWrapper); 346 | // } 347 | // } 348 | // }) 349 | // } 350 | 351 | image.onload = function() { 352 | images.push({ 353 | imgInfo: imgInfo, 354 | image: image, 355 | linksWrapper: linksWrapper 356 | }) 357 | } 358 | } 359 | 360 | function runPlugin(name) { 361 | console.log('runPlugin', name); 362 | inspirationPlugins.forEach(function(plugin, i) { 363 | if (plugin.name != name) return; 364 | 365 | var todo = images.slice(0); 366 | 367 | function next() { 368 | var img = todo.shift(); 369 | if (!img) { return; } 370 | 371 | var imgInfo = img.imgInfo; 372 | var image = img.image; 373 | var linksWrapper = img.linksWrapper; 374 | if (!imgInfo.plugindata || !(plugin.name in imgInfo.plugindata)) { 375 | console.log('Running', plugin.name, 'on', imgInfo); 376 | plugin.run(imgInfo, image, linksWrapper, next); 377 | } 378 | else { 379 | next(); 380 | } 381 | } 382 | 383 | next(); 384 | }) 385 | } 386 | 387 | function buildDropZone() { 388 | var xhr = new XMLHttpRequest(); 389 | if (!xhr.upload) { 390 | console.log("XMLHttpRequest2 file upload not available!"); 391 | return; 392 | } 393 | 394 | function processFile(file) { 395 | 396 | console.log("Uploading", file.name, file.type, file.size); 397 | 398 | var xhr = new XMLHttpRequest(); 399 | if (xhr.upload && (file.type == "image/jpeg" || file.type == "image/gif" || file.type == "image/png")) { 400 | xhr.open("POST", inspiration_server + "/api/upload"); 401 | var formData = new FormData(); 402 | formData.append("file", file); 403 | xhr.send(formData); 404 | xhr.onreadystatechange = function() { 405 | if (xhr.readyState == 4){ 406 | var imageData = JSON.parse(xhr.response); 407 | addImage(imageData, true); 408 | } 409 | }; 410 | } 411 | } 412 | 413 | function processLink(link) { 414 | console.log("Uploading", link); 415 | var xhr = new XMLHttpRequest(); 416 | xhr.open("GET", inspiration_server + "/api/post?img="+encodeURIComponent(link)); 417 | xhr.send(); 418 | xhr.onreadystatechange = function() { 419 | if (xhr.readyState == 4){ 420 | var imageData = JSON.parse(xhr.response); 421 | console.log(imageData); 422 | addImage(imageData, true); 423 | } 424 | }; 425 | } 426 | 427 | var dropzone = $('

Drop Images Here

'); 428 | $("body").append(dropzone); 429 | 430 | document.body.addEventListener('dragover', function(e) { 431 | dropzone.show(); 432 | e.stopPropagation(); 433 | e.preventDefault(); 434 | return false; 435 | }); 436 | 437 | dropzone.get(0).addEventListener('dragleave', function(e) { 438 | dropzone.hide(); 439 | e.stopPropagation(); 440 | e.preventDefault(); 441 | return false; 442 | }); 443 | 444 | document.body.addEventListener('drop', function(e) { 445 | e.stopPropagation(); 446 | e.preventDefault(); 447 | dropzone.hide(); 448 | 449 | var files = e.target.files || e.dataTransfer.files; 450 | for(var i=0, f; f = files[i]; i++) { 451 | processFile(f); 452 | } 453 | 454 | var link = e.dataTransfer.getData("text/uri-list"); 455 | if (link) { 456 | processLink(link); 457 | } 458 | return false; 459 | }) 460 | } 461 | 462 | function startSearch() { 463 | var searchTerm = ''; 464 | var searchField = document.createElement('div'); 465 | document.body.appendChild(searchField); 466 | searchField.id = 'search'; 467 | searchField.style.display = 'none'; 468 | searchField.style.left = (window.innerWidth - 500)/2 + 'px'; 469 | window.addEventListener('keydown', function(e) { 470 | if (e.keyCode == 27) { 471 | document.body.blur(); 472 | searchTerm = ''; 473 | searchField.textContent = searchTerm; 474 | e.preventDefault(); 475 | searchField.style.display = 'none'; 476 | } 477 | }); 478 | window.addEventListener('keypress', function(e) { 479 | if (e.metaKey || e.ctrlKey) return; 480 | if (document.activeElement != document.body) return; 481 | if (e.keyCode == 8) { 482 | searchTerm = searchTerm.substr(0, searchTerm.length-1); 483 | searchField.textContent = searchTerm; 484 | } 485 | else if (e.keyCode == 13) { 486 | console.log('searchTerm', searchTerm); 487 | if (searchTerm[0] == '#') { 488 | document.location.href = '/tag/' + searchTerm.substr(1); 489 | } 490 | else if (searchTerm[0] == '/') { 491 | var pluginName = searchTerm.substr(1); 492 | runPlugin(pluginName); 493 | console.log('runPlugin', name); 494 | document.body.blur(); 495 | searchTerm = ''; 496 | searchField.textContent = searchTerm; 497 | e.preventDefault(); 498 | searchField.style.display = 'none'; 499 | } 500 | else if (searchTerm.length > 0) { 501 | document.location.href = '/s/' + searchTerm; 502 | } 503 | } 504 | else { 505 | var c = String.fromCharCode(e.charCode != null ? e.charCode : e.keyCode); 506 | searchTerm += c; 507 | searchField.textContent = searchTerm; 508 | searchField.style.display = 'block'; 509 | e.preventDefault(); 510 | } 511 | }); 512 | } 513 | 514 | $(document).ready(function() { 515 | buildDropZone(); 516 | buildColumns(); 517 | startSearch(); 518 | 519 | var path = document.location.pathname || ""; 520 | 521 | $.get(inspiration_server + "/api/get" + path, function(data) { 522 | if (data && data.length > 0) { 523 | console.log("got! " + data.length); 524 | } 525 | else { 526 | document.querySelector('#dropzone').setAttribute('class','active'); 527 | return; 528 | } 529 | imagesData = data; 530 | if (inspiration_tags) { 531 | $("h1").append(" / " + inspiration_tags + ""); 532 | } 533 | 534 | inspiration_tags = inspiration_tags.split("+"); 535 | 536 | if (inspiration_tags.length == 1 && inspiration_tags[0] == "") { 537 | inspiration_tags = []; 538 | } 539 | 540 | var index = 0; 541 | 542 | function loadMore() { 543 | var i =0; 544 | while(i < maxImagesLimit) { 545 | if (index > imagesData.length - 1) break; 546 | //if (i < startImageIndex) continue; 547 | var tags = imagesData[index].tags; 548 | var filteredOut = false; 549 | for(var j=0; j $(document).height() - 500) { 567 | loadMore(); 568 | } 569 | }); 570 | }, "json") 571 | 572 | console.log("waiting..."); 573 | }); 574 | -------------------------------------------------------------------------------- /public/js/jquery-appear-mod.js: -------------------------------------------------------------------------------- 1 | /* 2 | * jQuery.appear 3 | * http://code.google.com/p/jquery-appear/ 4 | * 5 | * Copyright (c) 2009 Michael Hixson 6 | * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php) 7 | * 8 | * Added disappear event by marcin ignac 9 | * 10 | */ 11 | (function($) { 12 | 13 | $.fn.appear = function(fn, options) { 14 | 15 | var settings = $.extend({ 16 | 17 | //arbitrary data to pass to fn 18 | data: undefined, 19 | 20 | //call fn only on the first appear? 21 | one: true 22 | 23 | }, options); 24 | 25 | return this.each(function() { 26 | 27 | var t = $(this); 28 | 29 | //whether the element is currently visible 30 | //t.appeared = false; 31 | 32 | if (!fn) { 33 | //trigger the custom event 34 | t.trigger('appear', settings.data); 35 | return; 36 | } 37 | 38 | var w = $(window); 39 | 40 | //fires the appear event when appropriate 41 | var check = function() { 42 | 43 | //is the element hidden? 44 | if (!t.is(':visible')) { 45 | 46 | //it became hidden 47 | t.appeared = false; 48 | return; 49 | } 50 | 51 | //is the element inside the visible window? 52 | var a = w.scrollLeft(); 53 | var b = w.scrollTop(); 54 | var o = t.offset(); 55 | var x = o.left; 56 | var y = o.top; 57 | 58 | if (y + t.height() >= b && 59 | y <= b + w.height() && 60 | x + t.width() >= a && 61 | x <= a + w.width()) { 62 | 63 | //trigger the custom event 64 | if (!t.appeared) t.trigger('appear', settings.data); 65 | } else { 66 | if (t.appeared) { 67 | t.trigger('disappear', settings.data); 68 | } 69 | 70 | //it scrolled out of view 71 | t.appeared = false; 72 | } 73 | }; 74 | 75 | //create a modified fn with some additional logic 76 | var modifiedFn = function() { 77 | 78 | //mark the element as visible 79 | t.appeared = true; 80 | 81 | //is this supposed to happen only once? 82 | if (settings.one) { 83 | 84 | //remove the check 85 | w.unbind('scroll', check); 86 | var i = $.inArray(check, $.fn.appear.checks); 87 | if (i >= 0) $.fn.appear.checks.splice(i, 1); 88 | } 89 | 90 | //trigger the original fn 91 | fn.apply(this, arguments); 92 | }; 93 | 94 | //bind the modified fn to the element 95 | if (settings.one) t.one('appear', settings.data, modifiedFn); 96 | else t.bind('appear', settings.data, modifiedFn); 97 | 98 | //check whenever the window scrolls 99 | w.scroll(check); 100 | 101 | //check whenever the dom changes 102 | $.fn.appear.checks.push(check); 103 | 104 | //check now 105 | (check)(); 106 | }); 107 | }; 108 | 109 | //keep a queue of appearance checks 110 | $.extend($.fn.appear, { 111 | 112 | checks: [], 113 | timeout: null, 114 | 115 | //process the queue 116 | checkAll: function() { 117 | var length = $.fn.appear.checks.length; 118 | if (length > 0) while (length--) ($.fn.appear.checks[length])(); 119 | }, 120 | 121 | //check the queue asynchronously 122 | run: function() { 123 | if ($.fn.appear.timeout) clearTimeout($.fn.appear.timeout); 124 | $.fn.appear.timeout = setTimeout($.fn.appear.checkAll, 20); 125 | } 126 | }); 127 | 128 | //run checks when these methods are called 129 | $.each(['append', 'prepend', 'after', 'before', 'attr', 130 | 'removeAttr', 'addClass', 'removeClass', 'toggleClass', 131 | 'remove', 'css', 'show', 'hide'], function(i, n) { 132 | var old = $.fn[n]; 133 | if (old) { 134 | $.fn[n] = function() { 135 | var r = old.apply(this, arguments); 136 | $.fn.appear.run(); 137 | return r; 138 | } 139 | } 140 | }); 141 | 142 | })(jQuery); -------------------------------------------------------------------------------- /public/js/jquery.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * jQuery JavaScript Library v1.5.1 3 | * http://jquery.com/ 4 | * 5 | * Copyright 2011, John Resig 6 | * Dual licensed under the MIT or GPL Version 2 licenses. 7 | * http://jquery.org/license 8 | * 9 | * Includes Sizzle.js 10 | * http://sizzlejs.com/ 11 | * Copyright 2011, The Dojo Foundation 12 | * Released under the MIT, BSD, and GPL Licenses. 13 | * 14 | * Date: Wed Feb 23 13:55:29 2011 -0500 15 | */ 16 | (function(a,b){function cg(a){return d.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cd(a){if(!bZ[a]){var b=d("<"+a+">").appendTo("body"),c=b.css("display");b.remove();if(c==="none"||c==="")c="block";bZ[a]=c}return bZ[a]}function cc(a,b){var c={};d.each(cb.concat.apply([],cb.slice(0,b)),function(){c[this]=a});return c}function bY(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function bX(){try{return new a.XMLHttpRequest}catch(b){}}function bW(){d(a).unload(function(){for(var a in bU)bU[a](0,1)})}function bQ(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var e=a.dataTypes,f={},g,h,i=e.length,j,k=e[0],l,m,n,o,p;for(g=1;g=0===c})}function N(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function F(a,b){return(a&&a!=="*"?a+".":"")+b.replace(r,"`").replace(s,"&")}function E(a){var b,c,e,f,g,h,i,j,k,l,m,n,o,q=[],r=[],s=d._data(this,"events");if(a.liveFired!==this&&s&&s.live&&!a.target.disabled&&(!a.button||a.type!=="click")){a.namespace&&(n=new RegExp("(^|\\.)"+a.namespace.split(".").join("\\.(?:.*\\.)?")+"(\\.|$)")),a.liveFired=this;var t=s.live.slice(0);for(i=0;ic)break;a.currentTarget=f.elem,a.data=f.handleObj.data,a.handleObj=f.handleObj,o=f.handleObj.origHandler.apply(f.elem,arguments);if(o===!1||a.isPropagationStopped()){c=f.level,o===!1&&(b=!1);if(a.isImmediatePropagationStopped())break}}return b}}function C(a,c,e){var f=d.extend({},e[0]);f.type=a,f.originalEvent={},f.liveFired=b,d.event.handle.call(c,f),f.isDefaultPrevented()&&e[0].preventDefault()}function w(){return!0}function v(){return!1}function g(a){for(var b in a)if(b!=="toJSON")return!1;return!0}function f(a,c,f){if(f===b&&a.nodeType===1){f=a.getAttribute("data-"+c);if(typeof f==="string"){try{f=f==="true"?!0:f==="false"?!1:f==="null"?null:d.isNaN(f)?e.test(f)?d.parseJSON(f):f:parseFloat(f)}catch(g){}d.data(a,c,f)}else f=b}return f}var c=a.document,d=function(){function I(){if(!d.isReady){try{c.documentElement.doScroll("left")}catch(a){setTimeout(I,1);return}d.ready()}}var d=function(a,b){return new d.fn.init(a,b,g)},e=a.jQuery,f=a.$,g,h=/^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,i=/\S/,j=/^\s+/,k=/\s+$/,l=/\d/,m=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,n=/^[\],:{}\s]*$/,o=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,q=/(?:^|:|,)(?:\s*\[)+/g,r=/(webkit)[ \/]([\w.]+)/,s=/(opera)(?:.*version)?[ \/]([\w.]+)/,t=/(msie) ([\w.]+)/,u=/(mozilla)(?:.*? rv:([\w.]+))?/,v=navigator.userAgent,w,x=!1,y,z="then done fail isResolved isRejected promise".split(" "),A,B=Object.prototype.toString,C=Object.prototype.hasOwnProperty,D=Array.prototype.push,E=Array.prototype.slice,F=String.prototype.trim,G=Array.prototype.indexOf,H={};d.fn=d.prototype={constructor:d,init:function(a,e,f){var g,i,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!e&&c.body){this.context=c,this[0]=c.body,this.selector="body",this.length=1;return this}if(typeof a==="string"){g=h.exec(a);if(!g||!g[1]&&e)return!e||e.jquery?(e||f).find(a):this.constructor(e).find(a);if(g[1]){e=e instanceof d?e[0]:e,k=e?e.ownerDocument||e:c,j=m.exec(a),j?d.isPlainObject(e)?(a=[c.createElement(j[1])],d.fn.attr.call(a,e,!0)):a=[k.createElement(j[1])]:(j=d.buildFragment([g[1]],[k]),a=(j.cacheable?d.clone(j.fragment):j.fragment).childNodes);return d.merge(this,a)}i=c.getElementById(g[2]);if(i&&i.parentNode){if(i.id!==g[2])return f.find(a);this.length=1,this[0]=i}this.context=c,this.selector=a;return this}if(d.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return d.makeArray(a,this)},selector:"",jquery:"1.5.1",length:0,size:function(){return this.length},toArray:function(){return E.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var e=this.constructor();d.isArray(a)?D.apply(e,a):d.merge(e,a),e.prevObject=this,e.context=this.context,b==="find"?e.selector=this.selector+(this.selector?" ":"")+c:b&&(e.selector=this.selector+"."+b+"("+c+")");return e},each:function(a,b){return d.each(this,a,b)},ready:function(a){d.bindReady(),y.done(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(E.apply(this,arguments),"slice",E.call(arguments).join(","))},map:function(a){return this.pushStack(d.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:D,sort:[].sort,splice:[].splice},d.fn.init.prototype=d.fn,d.extend=d.fn.extend=function(){var a,c,e,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i==="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!=="object"&&!d.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j0)return;y.resolveWith(c,[d]),d.fn.trigger&&d(c).trigger("ready").unbind("ready")}},bindReady:function(){if(!x){x=!0;if(c.readyState==="complete")return setTimeout(d.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",A,!1),a.addEventListener("load",d.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",A),a.attachEvent("onload",d.ready);var b=!1;try{b=a.frameElement==null}catch(e){}c.documentElement.doScroll&&b&&I()}}},isFunction:function(a){return d.type(a)==="function"},isArray:Array.isArray||function(a){return d.type(a)==="array"},isWindow:function(a){return a&&typeof a==="object"&&"setInterval"in a},isNaN:function(a){return a==null||!l.test(a)||isNaN(a)},type:function(a){return a==null?String(a):H[B.call(a)]||"object"},isPlainObject:function(a){if(!a||d.type(a)!=="object"||a.nodeType||d.isWindow(a))return!1;if(a.constructor&&!C.call(a,"constructor")&&!C.call(a.constructor.prototype,"isPrototypeOf"))return!1;var c;for(c in a){}return c===b||C.call(a,c)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw a},parseJSON:function(b){if(typeof b!=="string"||!b)return null;b=d.trim(b);if(n.test(b.replace(o,"@").replace(p,"]").replace(q,"")))return a.JSON&&a.JSON.parse?a.JSON.parse(b):(new Function("return "+b))();d.error("Invalid JSON: "+b)},parseXML:function(b,c,e){a.DOMParser?(e=new DOMParser,c=e.parseFromString(b,"text/xml")):(c=new ActiveXObject("Microsoft.XMLDOM"),c.async="false",c.loadXML(b)),e=c.documentElement,(!e||!e.nodeName||e.nodeName==="parsererror")&&d.error("Invalid XML: "+b);return c},noop:function(){},globalEval:function(a){if(a&&i.test(a)){var b=c.head||c.getElementsByTagName("head")[0]||c.documentElement,e=c.createElement("script");d.support.scriptEval()?e.appendChild(c.createTextNode(a)):e.text=a,b.insertBefore(e,b.firstChild),b.removeChild(e)}},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,e){var f,g=0,h=a.length,i=h===b||d.isFunction(a);if(e){if(i){for(f in a)if(c.apply(a[f],e)===!1)break}else for(;g1){var f=E.call(arguments,0),g=b,h=function(a){return function(b){f[a]=arguments.length>1?E.call(arguments,0):b,--g||c.resolveWith(e,f)}};while(b--)a=f[b],a&&d.isFunction(a.promise)?a.promise().then(h(b),c.reject):--g;g||c.resolveWith(e,f)}else c!==a&&c.resolve(a);return e},uaMatch:function(a){a=a.toLowerCase();var b=r.exec(a)||s.exec(a)||t.exec(a)||a.indexOf("compatible")<0&&u.exec(a)||[];return{browser:b[1]||"",version:b[2]||"0"}},sub:function(){function a(b,c){return new a.fn.init(b,c)}d.extend(!0,a,this),a.superclass=this,a.fn=a.prototype=this(),a.fn.constructor=a,a.subclass=this.subclass,a.fn.init=function b(b,c){c&&c instanceof d&&!(c instanceof a)&&(c=a(c));return d.fn.init.call(this,b,c,e)},a.fn.init.prototype=a.fn;var e=a(c);return a},browser:{}}),y=d._Deferred(),d.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(a,b){H["[object "+b+"]"]=b.toLowerCase()}),w=d.uaMatch(v),w.browser&&(d.browser[w.browser]=!0,d.browser.version=w.version),d.browser.webkit&&(d.browser.safari=!0),G&&(d.inArray=function(a,b){return G.call(b,a)}),i.test(" ")&&(j=/^[\s\xA0]+/,k=/[\s\xA0]+$/),g=d(c),c.addEventListener?A=function(){c.removeEventListener("DOMContentLoaded",A,!1),d.ready()}:c.attachEvent&&(A=function(){c.readyState==="complete"&&(c.detachEvent("onreadystatechange",A),d.ready())});return d}();(function(){d.support={};var b=c.createElement("div");b.style.display="none",b.innerHTML="
a";var e=b.getElementsByTagName("*"),f=b.getElementsByTagName("a")[0],g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=b.getElementsByTagName("input")[0];if(e&&e.length&&f){d.support={leadingWhitespace:b.firstChild.nodeType===3,tbody:!b.getElementsByTagName("tbody").length,htmlSerialize:!!b.getElementsByTagName("link").length,style:/red/.test(f.getAttribute("style")),hrefNormalized:f.getAttribute("href")==="/a",opacity:/^0.55$/.test(f.style.opacity),cssFloat:!!f.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,deleteExpando:!0,optDisabled:!1,checkClone:!1,noCloneEvent:!0,noCloneChecked:!0,boxModel:null,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableHiddenOffsets:!0},i.checked=!0,d.support.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,d.support.optDisabled=!h.disabled;var j=null;d.support.scriptEval=function(){if(j===null){var b=c.documentElement,e=c.createElement("script"),f="script"+d.now();try{e.appendChild(c.createTextNode("window."+f+"=1;"))}catch(g){}b.insertBefore(e,b.firstChild),a[f]?(j=!0,delete a[f]):j=!1,b.removeChild(e),b=e=f=null}return j};try{delete b.test}catch(k){d.support.deleteExpando=!1}!b.addEventListener&&b.attachEvent&&b.fireEvent&&(b.attachEvent("onclick",function l(){d.support.noCloneEvent=!1,b.detachEvent("onclick",l)}),b.cloneNode(!0).fireEvent("onclick")),b=c.createElement("div"),b.innerHTML="";var m=c.createDocumentFragment();m.appendChild(b.firstChild),d.support.checkClone=m.cloneNode(!0).cloneNode(!0).lastChild.checked,d(function(){var a=c.createElement("div"),b=c.getElementsByTagName("body")[0];if(b){a.style.width=a.style.paddingLeft="1px",b.appendChild(a),d.boxModel=d.support.boxModel=a.offsetWidth===2,"zoom"in a.style&&(a.style.display="inline",a.style.zoom=1,d.support.inlineBlockNeedsLayout=a.offsetWidth===2,a.style.display="",a.innerHTML="
",d.support.shrinkWrapBlocks=a.offsetWidth!==2),a.innerHTML="
t
";var e=a.getElementsByTagName("td");d.support.reliableHiddenOffsets=e[0].offsetHeight===0,e[0].style.display="",e[1].style.display="none",d.support.reliableHiddenOffsets=d.support.reliableHiddenOffsets&&e[0].offsetHeight===0,a.innerHTML="",b.removeChild(a).style.display="none",a=e=null}});var n=function(a){var b=c.createElement("div");a="on"+a;if(!b.attachEvent)return!0;var d=a in b;d||(b.setAttribute(a,"return;"),d=typeof b[a]==="function"),b=null;return d};d.support.submitBubbles=n("submit"),d.support.changeBubbles=n("change"),b=e=f=null}})();var e=/^(?:\{.*\}|\[.*\])$/;d.extend({cache:{},uuid:0,expando:"jQuery"+(d.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?d.cache[a[d.expando]]:a[d.expando];return!!a&&!g(a)},data:function(a,c,e,f){if(d.acceptData(a)){var g=d.expando,h=typeof c==="string",i,j=a.nodeType,k=j?d.cache:a,l=j?a[d.expando]:a[d.expando]&&d.expando;if((!l||f&&l&&!k[l][g])&&h&&e===b)return;l||(j?a[d.expando]=l=++d.uuid:l=d.expando),k[l]||(k[l]={},j||(k[l].toJSON=d.noop));if(typeof c==="object"||typeof c==="function")f?k[l][g]=d.extend(k[l][g],c):k[l]=d.extend(k[l],c);i=k[l],f&&(i[g]||(i[g]={}),i=i[g]),e!==b&&(i[c]=e);if(c==="events"&&!i[c])return i[g]&&i[g].events;return h?i[c]:i}},removeData:function(b,c,e){if(d.acceptData(b)){var f=d.expando,h=b.nodeType,i=h?d.cache:b,j=h?b[d.expando]:d.expando;if(!i[j])return;if(c){var k=e?i[j][f]:i[j];if(k){delete k[c];if(!g(k))return}}if(e){delete i[j][f];if(!g(i[j]))return}var l=i[j][f];d.support.deleteExpando||i!=a?delete i[j]:i[j]=null,l?(i[j]={},h||(i[j].toJSON=d.noop),i[j][f]=l):h&&(d.support.deleteExpando?delete b[d.expando]:b.removeAttribute?b.removeAttribute(d.expando):b[d.expando]=null)}},_data:function(a,b,c){return d.data(a,b,c,!0)},acceptData:function(a){if(a.nodeName){var b=d.noData[a.nodeName.toLowerCase()];if(b)return b!==!0&&a.getAttribute("classid")===b}return!0}}),d.fn.extend({data:function(a,c){var e=null;if(typeof a==="undefined"){if(this.length){e=d.data(this[0]);if(this[0].nodeType===1){var g=this[0].attributes,h;for(var i=0,j=g.length;i-1)return!0;return!1},val:function(a){if(!arguments.length){var c=this[0];if(c){if(d.nodeName(c,"option")){var e=c.attributes.value;return!e||e.specified?c.value:c.text}if(d.nodeName(c,"select")){var f=c.selectedIndex,g=[],h=c.options,i=c.type==="select-one";if(f<0)return null;for(var k=i?f:0,l=i?f+1:h.length;k=0;else if(d.nodeName(this,"select")){var f=d.makeArray(e);d("option",this).each(function(){this.selected=d.inArray(d(this).val(),f)>=0}),f.length||(this.selectedIndex=-1)}else this.value=e}})}}),d.extend({attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,e,f){if(!a||a.nodeType===3||a.nodeType===8||a.nodeType===2)return b;if(f&&c in d.attrFn)return d(a)[c](e);var g=a.nodeType!==1||!d.isXMLDoc(a),h=e!==b;c=g&&d.props[c]||c;if(a.nodeType===1){var i=k.test(c);if(c==="selected"&&!d.support.optSelected){var j=a.parentNode;j&&(j.selectedIndex,j.parentNode&&j.parentNode.selectedIndex)}if((c in a||a[c]!==b)&&g&&!i){h&&(c==="type"&&l.test(a.nodeName)&&a.parentNode&&d.error("type property can't be changed"),e===null?a.nodeType===1&&a.removeAttribute(c):a[c]=e);if(d.nodeName(a,"form")&&a.getAttributeNode(c))return a.getAttributeNode(c).nodeValue;if(c==="tabIndex"){var o=a.getAttributeNode("tabIndex");return o&&o.specified?o.value:m.test(a.nodeName)||n.test(a.nodeName)&&a.href?0:b}return a[c]}if(!d.support.style&&g&&c==="style"){h&&(a.style.cssText=""+e);return a.style.cssText}h&&a.setAttribute(c,""+e);if(!a.attributes[c]&&(a.hasAttribute&&!a.hasAttribute(c)))return b;var p=!d.support.hrefNormalized&&g&&i?a.getAttribute(c,2):a.getAttribute(c);return p===null?b:p}h&&(a[c]=e);return a[c]}});var p=/\.(.*)$/,q=/^(?:textarea|input|select)$/i,r=/\./g,s=/ /g,t=/[^\w\s.|`]/g,u=function(a){return a.replace(t,"\\$&")};d.event={add:function(c,e,f,g){if(c.nodeType!==3&&c.nodeType!==8){try{d.isWindow(c)&&(c!==a&&!c.frameElement)&&(c=a)}catch(h){}if(f===!1)f=v;else if(!f)return;var i,j;f.handler&&(i=f,f=i.handler),f.guid||(f.guid=d.guid++);var k=d._data(c);if(!k)return;var l=k.events,m=k.handle;l||(k.events=l={}),m||(k.handle=m=function(){return typeof d!=="undefined"&&!d.event.triggered?d.event.handle.apply(m.elem,arguments):b}),m.elem=c,e=e.split(" ");var n,o=0,p;while(n=e[o++]){j=i?d.extend({},i):{handler:f,data:g},n.indexOf(".")>-1?(p=n.split("."),n=p.shift(),j.namespace=p.slice(0).sort().join(".")):(p=[],j.namespace=""),j.type=n,j.guid||(j.guid=f.guid);var q=l[n],r=d.event.special[n]||{};if(!q){q=l[n]=[];if(!r.setup||r.setup.call(c,g,p,m)===!1)c.addEventListener?c.addEventListener(n,m,!1):c.attachEvent&&c.attachEvent("on"+n,m)}r.add&&(r.add.call(c,j),j.handler.guid||(j.handler.guid=f.guid)),q.push(j),d.event.global[n]=!0}c=null}},global:{},remove:function(a,c,e,f){if(a.nodeType!==3&&a.nodeType!==8){e===!1&&(e=v);var g,h,i,j,k=0,l,m,n,o,p,q,r,s=d.hasData(a)&&d._data(a),t=s&&s.events;if(!s||!t)return;c&&c.type&&(e=c.handler,c=c.type);if(!c||typeof c==="string"&&c.charAt(0)==="."){c=c||"";for(h in t)d.event.remove(a,h+c);return}c=c.split(" ");while(h=c[k++]){r=h,q=null,l=h.indexOf(".")<0,m=[],l||(m=h.split("."),h=m.shift(),n=new RegExp("(^|\\.)"+d.map(m.slice(0).sort(),u).join("\\.(?:.*\\.)?")+"(\\.|$)")),p=t[h];if(!p)continue;if(!e){for(j=0;j=0&&(a.type=f=f.slice(0,-1),a.exclusive=!0),e||(a.stopPropagation(),d.event.global[f]&&d.each(d.cache,function(){var b=d.expando,e=this[b];e&&e.events&&e.events[f]&&d.event.trigger(a,c,e.handle.elem)}));if(!e||e.nodeType===3||e.nodeType===8)return b;a.result=b,a.target=e,c=d.makeArray(c),c.unshift(a)}a.currentTarget=e;var h=d._data(e,"handle");h&&h.apply(e,c);var i=e.parentNode||e.ownerDocument;try{e&&e.nodeName&&d.noData[e.nodeName.toLowerCase()]||e["on"+f]&&e["on"+f].apply(e,c)===!1&&(a.result=!1,a.preventDefault())}catch(j){}if(!a.isPropagationStopped()&&i)d.event.trigger(a,c,i,!0);else if(!a.isDefaultPrevented()){var k,l=a.target,m=f.replace(p,""),n=d.nodeName(l,"a")&&m==="click",o=d.event.special[m]||{};if((!o._default||o._default.call(e,a)===!1)&&!n&&!(l&&l.nodeName&&d.noData[l.nodeName.toLowerCase()])){try{l[m]&&(k=l["on"+m],k&&(l["on"+m]=null),d.event.triggered=!0,l[m]())}catch(q){}k&&(l["on"+m]=k),d.event.triggered=!1}}},handle:function(c){var e,f,g,h,i,j=[],k=d.makeArray(arguments);c=k[0]=d.event.fix(c||a.event),c.currentTarget=this,e=c.type.indexOf(".")<0&&!c.exclusive,e||(g=c.type.split("."),c.type=g.shift(),j=g.slice(0).sort(),h=new RegExp("(^|\\.)"+j.join("\\.(?:.*\\.)?")+"(\\.|$)")),c.namespace=c.namespace||j.join("."),i=d._data(this,"events"),f=(i||{})[c.type];if(i&&f){f=f.slice(0);for(var l=0,m=f.length;l-1?d.map(a.options,function(a){return a.selected}).join("-"):"":a.nodeName.toLowerCase()==="select"&&(c=a.selectedIndex);return c},B=function B(a){var c=a.target,e,f;if(q.test(c.nodeName)&&!c.readOnly){e=d._data(c,"_change_data"),f=A(c),(a.type!=="focusout"||c.type!=="radio")&&d._data(c,"_change_data",f);if(e===b||f===e)return;if(e!=null||f)a.type="change",a.liveFired=b,d.event.trigger(a,arguments[1],c)}};d.event.special.change={filters:{focusout:B,beforedeactivate:B,click:function(a){var b=a.target,c=b.type;(c==="radio"||c==="checkbox"||b.nodeName.toLowerCase()==="select")&&B.call(this,a)},keydown:function(a){var b=a.target,c=b.type;(a.keyCode===13&&b.nodeName.toLowerCase()!=="textarea"||a.keyCode===32&&(c==="checkbox"||c==="radio")||c==="select-multiple")&&B.call(this,a)},beforeactivate:function(a){var b=a.target;d._data(b,"_change_data",A(b))}},setup:function(a,b){if(this.type==="file")return!1;for(var c in z)d.event.add(this,c+".specialChange",z[c]);return q.test(this.nodeName)},teardown:function(a){d.event.remove(this,".specialChange");return q.test(this.nodeName)}},z=d.event.special.change.filters,z.focus=z.beforeactivate}c.addEventListener&&d.each({focus:"focusin",blur:"focusout"},function(a,b){function c(a){a=d.event.fix(a),a.type=b;return d.event.handle.call(this,a)}d.event.special[b]={setup:function(){this.addEventListener(a,c,!0)},teardown:function(){this.removeEventListener(a,c,!0)}}}),d.each(["bind","one"],function(a,c){d.fn[c]=function(a,e,f){if(typeof a==="object"){for(var g in a)this[c](g,e,a[g],f);return this}if(d.isFunction(e)||e===!1)f=e,e=b;var h=c==="one"?d.proxy(f,function(a){d(this).unbind(a,h);return f.apply(this,arguments)}):f;if(a==="unload"&&c!=="one")this.one(a,e,f);else for(var i=0,j=this.length;i0?this.bind(b,a,c):this.trigger(b)},d.attrFn&&(d.attrFn[b]=!0)}),function(){function u(a,b,c,d,e,f){for(var g=0,h=d.length;g0){j=i;break}}i=i[a]}d[g]=j}}}function t(a,b,c,d,e,f){for(var g=0,h=d.length;g+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,e=0,f=Object.prototype.toString,g=!1,h=!0,i=/\\/g,j=/\W/;[0,0].sort(function(){h=!1;return 0});var k=function(b,d,e,g){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!=="string")return e;var i,j,n,o,q,r,s,t,u=!0,w=k.isXML(d),x=[],y=b;do{a.exec(""),i=a.exec(y);if(i){y=i[3],x.push(i[1]);if(i[2]){o=i[3];break}}}while(i);if(x.length>1&&m.exec(b))if(x.length===2&&l.relative[x[0]])j=v(x[0]+x[1],d);else{j=l.relative[x[0]]?[d]:k(x.shift(),d);while(x.length)b=x.shift(),l.relative[b]&&(b+=x.shift()),j=v(b,j)}else{!g&&x.length>1&&d.nodeType===9&&!w&&l.match.ID.test(x[0])&&!l.match.ID.test(x[x.length-1])&&(q=k.find(x.shift(),d,w),d=q.expr?k.filter(q.expr,q.set)[0]:q.set[0]);if(d){q=g?{expr:x.pop(),set:p(g)}:k.find(x.pop(),x.length===1&&(x[0]==="~"||x[0]==="+")&&d.parentNode?d.parentNode:d,w),j=q.expr?k.filter(q.expr,q.set):q.set,x.length>0?n=p(j):u=!1;while(x.length)r=x.pop(),s=r,l.relative[r]?s=x.pop():r="",s==null&&(s=d),l.relative[r](n,s,w)}else n=x=[]}n||(n=j),n||k.error(r||b);if(f.call(n)==="[object Array]")if(u)if(d&&d.nodeType===1)for(t=0;n[t]!=null;t++)n[t]&&(n[t]===!0||n[t].nodeType===1&&k.contains(d,n[t]))&&e.push(j[t]);else for(t=0;n[t]!=null;t++)n[t]&&n[t].nodeType===1&&e.push(j[t]);else e.push.apply(e,n);else p(n,e);o&&(k(o,h,e,g),k.uniqueSort(e));return e};k.uniqueSort=function(a){if(r){g=h,a.sort(r);if(g)for(var b=1;b0},k.find=function(a,b,c){var d;if(!a)return[];for(var e=0,f=l.order.length;e":function(a,b){var c,d=typeof b==="string",e=0,f=a.length;if(d&&!j.test(b)){b=b.toLowerCase();for(;e=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(i,"")},TAG:function(a,b){return a[1].replace(i,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||k.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&k.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(i,"");!f&&l.attrMap[g]&&(a[1]=l.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(i,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=k(b[3],null,null,c);else{var g=k.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(l.match.POS.test(b[0])||l.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!k(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){return"text"===a.getAttribute("type")},radio:function(a){return"radio"===a.type},checkbox:function(a){return"checkbox"===a.type},file:function(a){return"file"===a.type},password:function(a){return"password"===a.type},submit:function(a){return"submit"===a.type},image:function(a){return"image"===a.type},reset:function(a){return"reset"===a.type},button:function(a){return"button"===a.type||a.nodeName.toLowerCase()==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return bc[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=l.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||k.getText([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=l.attrHandle[c]?l.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=l.setFilters[e];if(f)return f(a,c,b,d)}}},m=l.match.POS,n=function(a,b){return"\\"+(b-0+1)};for(var o in l.match)l.match[o]=new RegExp(l.match[o].source+/(?![^\[]*\])(?![^\(]*\))/.source),l.leftMatch[o]=new RegExp(/(^(?:.|\r|\n)*?)/.source+l.match[o].source.replace(/\\(\d+)/g,n));var p=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(q){p=function(a,b){var c=0,d=b||[];if(f.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length==="number")for(var e=a.length;c",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(l.find.ID=function(a,c,d){if(typeof c.getElementById!=="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!=="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},l.filter.ID=function(a,b){var c=typeof a.getAttributeNode!=="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(l.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="",a.firstChild&&typeof a.firstChild.getAttribute!=="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(l.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=k,b=c.createElement("div"),d="__sizzle__";b.innerHTML="

";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){k=function(b,e,f,g){e=e||c;if(!g&&!k.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return p(e.getElementsByTagName(b),f);if(h[2]&&l.find.CLASS&&e.getElementsByClassName)return p(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return p([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return p([],f);if(i.id===h[3])return p([i],f)}try{return p(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var m=e,n=e.getAttribute("id"),o=n||d,q=e.parentNode,r=/^\s*[+~]/.test(b);n?o=o.replace(/'/g,"\\$&"):e.setAttribute("id",o),r&&q&&(e=e.parentNode);try{if(!r||q)return p(e.querySelectorAll("[id='"+o+"'] "+b),f)}catch(s){}finally{n||m.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)k[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector,d=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(e){d=!0}b&&(k.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!k.isXML(a))try{if(d||!l.match.PSEUDO.test(c)&&!/!=/.test(c))return b.call(a,c)}catch(e){}return k(c,null,null,[a]).length>0})}(),function(){var a=c.createElement("div");a.innerHTML="
";if(a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;l.order.splice(1,0,"CLASS"),l.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!=="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?k.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?k.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:k.contains=function(){return!1},k.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var v=function(a,b){var c,d=[],e="",f=b.nodeType?[b]:b;while(c=l.match.PSEUDO.exec(a))e+=c[0],a=a.replace(l.match.PSEUDO,"");a=l.relative[a]?a+"*":a;for(var g=0,h=f.length;g0)for(var g=c;g0},closest:function(a,b){var c=[],e,f,g=this[0];if(d.isArray(a)){var h,i,j={},k=1;if(g&&a.length){for(e=0,f=a.length;e-1:d(g).is(h))&&c.push({selector:i,elem:g,level:k});g=g.parentNode,k++}}return c}var l=L.test(a)?d(a,b||this.context):null;for(e=0,f=this.length;e-1:d.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b)break}}c=c.length>1?d.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a||typeof a==="string")return d.inArray(this[0],a?d(a):this.parent().children());return d.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a==="string"?d(a,b):d.makeArray(a),e=d.merge(this.get(),c);return this.pushStack(N(c[0])||N(e[0])?e:d.unique(e))},andSelf:function(){return this.add(this.prevObject)}}),d.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return d.dir(a,"parentNode")},parentsUntil:function(a,b,c){return d.dir(a,"parentNode",c)},next:function(a){return d.nth(a,2,"nextSibling")},prev:function(a){return d.nth(a,2,"previousSibling")},nextAll:function(a){return d.dir(a,"nextSibling")},prevAll:function(a){return d.dir(a,"previousSibling")},nextUntil:function(a,b,c){return d.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return d.dir(a,"previousSibling",c)},siblings:function(a){return d.sibling(a.parentNode.firstChild,a)},children:function(a){return d.sibling(a.firstChild)},contents:function(a){return d.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:d.makeArray(a.childNodes)}},function(a,b){d.fn[a]=function(c,e){var f=d.map(this,b,c),g=K.call(arguments);G.test(a)||(e=c),e&&typeof e==="string"&&(f=d.filter(e,f)),f=this.length>1&&!M[a]?d.unique(f):f,(this.length>1||I.test(e))&&H.test(a)&&(f=f.reverse());return this.pushStack(f,a,g.join(","))}}),d.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?d.find.matchesSelector(b[0],a)?[b[0]]:[]:d.find.matches(a,b)},dir:function(a,c,e){var f=[],g=a[c];while(g&&g.nodeType!==9&&(e===b||g.nodeType!==1||!d(g).is(e)))g.nodeType===1&&f.push(g),g=g[c];return f},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var P=/ jQuery\d+="(?:\d+|null)"/g,Q=/^\s+/,R=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,S=/<([\w:]+)/,T=/",""],legend:[1,"
","
"],thead:[1,"","
"],tr:[2,"","
"],td:[3,"","
"],col:[2,"","
"],area:[1,"",""],_default:[0,"",""]};X.optgroup=X.option,X.tbody=X.tfoot=X.colgroup=X.caption=X.thead,X.th=X.td,d.support.htmlSerialize||(X._default=[1,"div
","
"]),d.fn.extend({text:function(a){if(d.isFunction(a))return this.each(function(b){var c=d(this);c.text(a.call(this,b,c.text()))});if(typeof a!=="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return d.text(this)},wrapAll:function(a){if(d.isFunction(a))return this.each(function(b){d(this).wrapAll(a.call(this,b))});if(this[0]){var b=d(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(d.isFunction(a))return this.each(function(b){d(this).wrapInner(a.call(this,b))});return this.each(function(){var b=d(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){d(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){d.nodeName(this,"body")||d(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=d(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,d(arguments[0]).toArray());return a}},remove:function(a,b){for(var c=0,e;(e=this[c])!=null;c++)if(!a||d.filter(a,[e]).length)!b&&e.nodeType===1&&(d.cleanData(e.getElementsByTagName("*")),d.cleanData([e])),e.parentNode&&e.parentNode.removeChild(e);return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&d.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return d.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(P,""):null;if(typeof a!=="string"||V.test(a)||!d.support.leadingWhitespace&&Q.test(a)||X[(S.exec(a)||["",""])[1].toLowerCase()])d.isFunction(a)?this.each(function(b){var c=d(this);c.html(a.call(this,b,c.html()))}):this.empty().append(a);else{a=a.replace(R,"<$1>");try{for(var c=0,e=this.length;c1&&l0?this.clone(!0):this).get();d(f[h])[b](j),e=e.concat(j)}return this.pushStack(e,a,f.selector)}}),d.extend({clone:function(a,b,c){var e=a.cloneNode(!0),f,g,h;if((!d.support.noCloneEvent||!d.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!d.isXMLDoc(a)){$(a,e),f=_(a),g=_(e);for(h=0;f[h];++h)$(f[h],g[h])}if(b){Z(a,e);if(c){f=_(a),g=_(e);for(h=0;f[h];++h)Z(f[h],g[h])}}return e},clean:function(a,b,e,f){b=b||c,typeof b.createElement==="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var g=[];for(var h=0,i;(i=a[h])!=null;h++){typeof i==="number"&&(i+="");if(!i)continue;if(typeof i!=="string"||U.test(i)){if(typeof i==="string"){i=i.replace(R,"<$1>");var j=(S.exec(i)||["",""])[1].toLowerCase(),k=X[j]||X._default,l=k[0],m=b.createElement("div");m.innerHTML=k[1]+i+k[2];while(l--)m=m.lastChild;if(!d.support.tbody){var n=T.test(i),o=j==="table"&&!n?m.firstChild&&m.firstChild.childNodes:k[1]===""&&!n?m.childNodes:[];for(var p=o.length-1;p>=0;--p)d.nodeName(o[p],"tbody")&&!o[p].childNodes.length&&o[p].parentNode.removeChild(o[p])}!d.support.leadingWhitespace&&Q.test(i)&&m.insertBefore(b.createTextNode(Q.exec(i)[0]),m.firstChild),i=m.childNodes}}else i=b.createTextNode(i);i.nodeType?g.push(i):g=d.merge(g,i)}if(e)for(h=0;g[h];h++)!f||!d.nodeName(g[h],"script")||g[h].type&&g[h].type.toLowerCase()!=="text/javascript"?(g[h].nodeType===1&&g.splice.apply(g,[h+1,0].concat(d.makeArray(g[h].getElementsByTagName("script")))),e.appendChild(g[h])):f.push(g[h].parentNode?g[h].parentNode.removeChild(g[h]):g[h]);return g},cleanData:function(a){var b,c,e=d.cache,f=d.expando,g=d.event.special,h=d.support.deleteExpando;for(var i=0,j;(j=a[i])!=null;i++){if(j.nodeName&&d.noData[j.nodeName.toLowerCase()])continue;c=j[d.expando];if(c){b=e[c]&&e[c][f];if(b&&b.events){for(var k in b.events)g[k]?d.event.remove(j,k):d.removeEvent(j,k,b.handle);b.handle&&(b.handle.elem=null)}h?delete j[d.expando]:j.removeAttribute&&j.removeAttribute(d.expando),delete e[c]}}}});var bb=/alpha\([^)]*\)/i,bc=/opacity=([^)]*)/,bd=/-([a-z])/ig,be=/([A-Z])/g,bf=/^-?\d+(?:px)?$/i,bg=/^-?\d/,bh={position:"absolute",visibility:"hidden",display:"block"},bi=["Left","Right"],bj=["Top","Bottom"],bk,bl,bm,bn=function(a,b){return b.toUpperCase()};d.fn.css=function(a,c){if(arguments.length===2&&c===b)return this;return d.access(this,a,c,!0,function(a,c,e){return e!==b?d.style(a,c,e):d.css(a,c)})},d.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=bk(a,"opacity","opacity");return c===""?"1":c}return a.style.opacity}}},cssNumber:{zIndex:!0,fontWeight:!0,opacity:!0,zoom:!0,lineHeight:!0},cssProps:{"float":d.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,c,e,f){if(a&&a.nodeType!==3&&a.nodeType!==8&&a.style){var g,h=d.camelCase(c),i=a.style,j=d.cssHooks[h];c=d.cssProps[h]||h;if(e===b){if(j&&"get"in j&&(g=j.get(a,!1,f))!==b)return g;return i[c]}if(typeof e==="number"&&isNaN(e)||e==null)return;typeof e==="number"&&!d.cssNumber[h]&&(e+="px");if(!j||!("set"in j)||(e=j.set(a,e))!==b)try{i[c]=e}catch(k){}}},css:function(a,c,e){var f,g=d.camelCase(c),h=d.cssHooks[g];c=d.cssProps[g]||g;if(h&&"get"in h&&(f=h.get(a,!0,e))!==b)return f;if(bk)return bk(a,c,g)},swap:function(a,b,c){var d={};for(var e in b)d[e]=a.style[e],a.style[e]=b[e];c.call(a);for(e in b)a.style[e]=d[e]},camelCase:function(a){return a.replace(bd,bn)}}),d.curCSS=d.css,d.each(["height","width"],function(a,b){d.cssHooks[b]={get:function(a,c,e){var f;if(c){a.offsetWidth!==0?f=bo(a,b,e):d.swap(a,bh,function(){f=bo(a,b,e)});if(f<=0){f=bk(a,b,b),f==="0px"&&bm&&(f=bm(a,b,b));if(f!=null)return f===""||f==="auto"?"0px":f}if(f<0||f==null){f=a.style[b];return f===""||f==="auto"?"0px":f}return typeof f==="string"?f:f+"px"}},set:function(a,b){if(!bf.test(b))return b;b=parseFloat(b);if(b>=0)return b+"px"}}}),d.support.opacity||(d.cssHooks.opacity={get:function(a,b){return bc.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style;c.zoom=1;var e=d.isNaN(b)?"":"alpha(opacity="+b*100+")",f=c.filter||"";c.filter=bb.test(f)?f.replace(bb,e):c.filter+" "+e}}),c.defaultView&&c.defaultView.getComputedStyle&&(bl=function(a,c,e){var f,g,h;e=e.replace(be,"-$1").toLowerCase();if(!(g=a.ownerDocument.defaultView))return b;if(h=g.getComputedStyle(a,null))f=h.getPropertyValue(e),f===""&&!d.contains(a.ownerDocument.documentElement,a)&&(f=d.style(a,e));return f}),c.documentElement.currentStyle&&(bm=function(a,b){var c,d=a.currentStyle&&a.currentStyle[b],e=a.runtimeStyle&&a.runtimeStyle[b],f=a.style;!bf.test(d)&&bg.test(d)&&(c=f.left,e&&(a.runtimeStyle.left=a.currentStyle.left),f.left=b==="fontSize"?"1em":d||0,d=f.pixelLeft+"px",f.left=c,e&&(a.runtimeStyle.left=e));return d===""?"auto":d}),bk=bl||bm,d.expr&&d.expr.filters&&(d.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!d.support.reliableHiddenOffsets&&(a.style.display||d.css(a,"display"))==="none"},d.expr.filters.visible=function(a){return!d.expr.filters.hidden(a)});var bp=/%20/g,bq=/\[\]$/,br=/\r?\n/g,bs=/#.*$/,bt=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bu=/^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bv=/(?:^file|^widget|\-extension):$/,bw=/^(?:GET|HEAD)$/,bx=/^\/\//,by=/\?/,bz=/)<[^<]*)*<\/script>/gi,bA=/^(?:select|textarea)/i,bB=/\s+/,bC=/([?&])_=[^&]*/,bD=/(^|\-)([a-z])/g,bE=function(a,b,c){return b+c.toUpperCase()},bF=/^([\w\+\.\-]+:)\/\/([^\/?#:]*)(?::(\d+))?/,bG=d.fn.load,bH={},bI={},bJ,bK;try{bJ=c.location.href}catch(bL){bJ=c.createElement("a"),bJ.href="",bJ=bJ.href}bK=bF.exec(bJ.toLowerCase()),d.fn.extend({load:function(a,c,e){if(typeof a!=="string"&&bG)return bG.apply(this,arguments);if(!this.length)return this;var f=a.indexOf(" ");if(f>=0){var g=a.slice(f,a.length);a=a.slice(0,f)}var h="GET";c&&(d.isFunction(c)?(e=c,c=b):typeof c==="object"&&(c=d.param(c,d.ajaxSettings.traditional),h="POST"));var i=this;d.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?d("
").append(c.replace(bz,"")).find(g):c)),e&&i.each(e,[c,b,a])}});return this},serialize:function(){return d.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?d.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bA.test(this.nodeName)||bu.test(this.type))}).map(function(a,b){var c=d(this).val();return c==null?null:d.isArray(c)?d.map(c,function(a,c){return{name:b.name,value:a.replace(br,"\r\n")}}):{name:b.name,value:c.replace(br,"\r\n")}}).get()}}),d.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){d.fn[b]=function(a){return this.bind(b,a)}}),d.each(["get","post"],function(a,c){d[c]=function(a,e,f,g){d.isFunction(e)&&(g=g||f,f=e,e=b);return d.ajax({type:c,url:a,data:e,success:f,dataType:g})}}),d.extend({getScript:function(a,c){return d.get(a,b,c,"script")},getJSON:function(a,b,c){return d.get(a,b,c,"json")},ajaxSetup:function(a,b){b?d.extend(!0,a,d.ajaxSettings,b):(b=a,a=d.extend(!0,d.ajaxSettings,b));for(var c in {context:1,url:1})c in b?a[c]=b[c]:c in d.ajaxSettings&&(a[c]=d.ajaxSettings[c]);return a},ajaxSettings:{url:bJ,isLocal:bv.test(bK[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":"*/*"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":d.parseJSON,"text xml":d.parseXML}},ajaxPrefilter:bM(bH),ajaxTransport:bM(bI),ajax:function(a,c){function v(a,c,l,n){if(r!==2){r=2,p&&clearTimeout(p),o=b,m=n||"",u.readyState=a?4:0;var q,t,v,w=l?bP(e,u,l):b,x,y;if(a>=200&&a<300||a===304){if(e.ifModified){if(x=u.getResponseHeader("Last-Modified"))d.lastModified[k]=x;if(y=u.getResponseHeader("Etag"))d.etag[k]=y}if(a===304)c="notmodified",q=!0;else try{t=bQ(e,w),c="success",q=!0}catch(z){c="parsererror",v=z}}else{v=c;if(!c||a)c="error",a<0&&(a=0)}u.status=a,u.statusText=c,q?h.resolveWith(f,[t,c,u]):h.rejectWith(f,[u,c,v]),u.statusCode(j),j=b,s&&g.trigger("ajax"+(q?"Success":"Error"),[u,e,q?t:v]),i.resolveWith(f,[u,c]),s&&(g.trigger("ajaxComplete",[u,e]),--d.active||d.event.trigger("ajaxStop"))}}typeof a==="object"&&(c=a,a=b),c=c||{};var e=d.ajaxSetup({},c),f=e.context||e,g=f!==e&&(f.nodeType||f instanceof d)?d(f):d.event,h=d.Deferred(),i=d._Deferred(),j=e.statusCode||{},k,l={},m,n,o,p,q,r=0,s,t,u={readyState:0,setRequestHeader:function(a,b){r||(l[a.toLowerCase().replace(bD,bE)]=b);return this},getAllResponseHeaders:function(){return r===2?m:null},getResponseHeader:function(a){var c;if(r===2){if(!n){n={};while(c=bt.exec(m))n[c[1].toLowerCase()]=c[2]}c=n[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){r||(e.mimeType=a);return this},abort:function(a){a=a||"abort",o&&o.abort(a),v(0,a);return this}};h.promise(u),u.success=u.done,u.error=u.fail,u.complete=i.done,u.statusCode=function(a){if(a){var b;if(r<2)for(b in a)j[b]=[j[b],a[b]];else b=a[u.status],u.then(b,b)}return this},e.url=((a||e.url)+"").replace(bs,"").replace(bx,bK[1]+"//"),e.dataTypes=d.trim(e.dataType||"*").toLowerCase().split(bB),e.crossDomain||(q=bF.exec(e.url.toLowerCase()),e.crossDomain=q&&(q[1]!=bK[1]||q[2]!=bK[2]||(q[3]||(q[1]==="http:"?80:443))!=(bK[3]||(bK[1]==="http:"?80:443)))),e.data&&e.processData&&typeof e.data!=="string"&&(e.data=d.param(e.data,e.traditional)),bN(bH,e,c,u);if(r===2)return!1;s=e.global,e.type=e.type.toUpperCase(),e.hasContent=!bw.test(e.type),s&&d.active++===0&&d.event.trigger("ajaxStart");if(!e.hasContent){e.data&&(e.url+=(by.test(e.url)?"&":"?")+e.data),k=e.url;if(e.cache===!1){var w=d.now(),x=e.url.replace(bC,"$1_="+w);e.url=x+(x===e.url?(by.test(e.url)?"&":"?")+"_="+w:"")}}if(e.data&&e.hasContent&&e.contentType!==!1||c.contentType)l["Content-Type"]=e.contentType;e.ifModified&&(k=k||e.url,d.lastModified[k]&&(l["If-Modified-Since"]=d.lastModified[k]),d.etag[k]&&(l["If-None-Match"]=d.etag[k])),l.Accept=e.dataTypes[0]&&e.accepts[e.dataTypes[0]]?e.accepts[e.dataTypes[0]]+(e.dataTypes[0]!=="*"?", */*; q=0.01":""):e.accepts["*"];for(t in e.headers)u.setRequestHeader(t,e.headers[t]);if(e.beforeSend&&(e.beforeSend.call(f,u,e)===!1||r===2)){u.abort();return!1}for(t in {success:1,error:1,complete:1})u[t](e[t]);o=bN(bI,e,c,u);if(o){u.readyState=1,s&&g.trigger("ajaxSend",[u,e]),e.async&&e.timeout>0&&(p=setTimeout(function(){u.abort("timeout")},e.timeout));try{r=1,o.send(l,v)}catch(y){status<2?v(-1,y):d.error(y)}}else v(-1,"No Transport");return u},param:function(a,c){var e=[],f=function(a,b){b=d.isFunction(b)?b():b,e[e.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=d.ajaxSettings.traditional);if(d.isArray(a)||a.jquery&&!d.isPlainObject(a))d.each(a,function(){f(this.name,this.value)});else for(var g in a)bO(g,a[g],c,f);return e.join("&").replace(bp,"+")}}),d.extend({active:0,lastModified:{},etag:{}});var bR=d.now(),bS=/(\=)\?(&|$)|()\?\?()/i;d.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return d.expando+"_"+bR++}}),d.ajaxPrefilter("json jsonp",function(b,c,e){var f=typeof b.data==="string";if(b.dataTypes[0]==="jsonp"||c.jsonpCallback||c.jsonp!=null||b.jsonp!==!1&&(bS.test(b.url)||f&&bS.test(b.data))){var g,h=b.jsonpCallback=d.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2",m=function(){a[h]=i,g&&d.isFunction(i)&&a[h](g[0])};b.jsonp!==!1&&(j=j.replace(bS,l),b.url===j&&(f&&(k=k.replace(bS,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},e.then(m,m),b.converters["script json"]=function(){g||d.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),d.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){d.globalEval(a);return a}}}),d.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),d.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var bT=d.now(),bU,bV;d.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&bX()||bY()}:bX,bV=d.ajaxSettings.xhr(),d.support.ajax=!!bV,d.support.cors=bV&&"withCredentials"in bV,bV=b,d.support.ajax&&d.ajaxTransport(function(a){if(!a.crossDomain||d.support.cors){var c;return{send:function(e,f){var g=a.xhr(),h,i;a.username?g.open(a.type,a.url,a.async,a.username,a.password):g.open(a.type,a.url,a.async);if(a.xhrFields)for(i in a.xhrFields)g[i]=a.xhrFields[i];a.mimeType&&g.overrideMimeType&&g.overrideMimeType(a.mimeType),(!a.crossDomain||a.hasContent)&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(i in e)g.setRequestHeader(i,e[i])}catch(j){}g.send(a.hasContent&&a.data||null),c=function(e,i){var j,k,l,m,n;try{if(c&&(i||g.readyState===4)){c=b,h&&(g.onreadystatechange=d.noop,delete bU[h]);if(i)g.readyState!==4&&g.abort();else{j=g.status,l=g.getAllResponseHeaders(),m={},n=g.responseXML,n&&n.documentElement&&(m.xml=n),m.text=g.responseText;try{k=g.statusText}catch(o){k=""}j||!a.isLocal||a.crossDomain?j===1223&&(j=204):j=m.text?200:404}}}catch(p){i||f(-1,p)}m&&f(j,k,m,l)},a.async&&g.readyState!==4?(bU||(bU={},bW()),h=bT++,g.onreadystatechange=bU[h]=c):c()},abort:function(){c&&c(0,1)}}}});var bZ={},b$=/^(?:toggle|show|hide)$/,b_=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,ca,cb=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];d.fn.extend({show:function(a,b,c){var e,f;if(a||a===0)return this.animate(cc("show",3),a,b,c);for(var g=0,h=this.length;g=0;a--)c[a].elem===this&&(b&&c[a](!0),c.splice(a,1))}),b||this.dequeue();return this}}),d.each({slideDown:cc("show",1),slideUp:cc("hide",1),slideToggle:cc("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){d.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),d.extend({speed:function(a,b,c){var e=a&&typeof a==="object"?d.extend({},a):{complete:c||!c&&b||d.isFunction(a)&&a,duration:a,easing:c&&b||b&&!d.isFunction(b)&&b};e.duration=d.fx.off?0:typeof e.duration==="number"?e.duration:e.duration in d.fx.speeds?d.fx.speeds[e.duration]:d.fx.speeds._default,e.old=e.complete,e.complete=function(){e.queue!==!1&&d(this).dequeue(),d.isFunction(e.old)&&e.old.call(this)};return e},easing:{linear:function(a,b,c,d){return c+d*a},swing:function(a,b,c,d){return(-Math.cos(a*Math.PI)/2+.5)*d+c}},timers:[],fx:function(a,b,c){this.options=b,this.elem=a,this.prop=c,b.orig||(b.orig={})}}),d.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this),(d.fx.step[this.prop]||d.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a,b=d.css(this.elem,this.prop);return isNaN(a=parseFloat(b))?!b||b==="auto"?0:b:a},custom:function(a,b,c){function g(a){return e.step(a)}var e=this,f=d.fx;this.startTime=d.now(),this.start=a,this.end=b,this.unit=c||this.unit||(d.cssNumber[this.prop]?"":"px"),this.now=this.start,this.pos=this.state=0,g.elem=this.elem,g()&&d.timers.push(g)&&!ca&&(ca=setInterval(f.tick,f.interval))},show:function(){this.options.orig[this.prop]=d.style(this.elem,this.prop),this.options.show=!0,this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur()),d(this.elem).show()},hide:function(){this.options.orig[this.prop]=d.style(this.elem,this.prop),this.options.hide=!0,this.custom(this.cur(),0)},step:function(a){var b=d.now(),c=!0;if(a||b>=this.options.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),this.options.curAnim[this.prop]=!0;for(var e in this.options.curAnim)this.options.curAnim[e]!==!0&&(c=!1);if(c){if(this.options.overflow!=null&&!d.support.shrinkWrapBlocks){var f=this.elem,g=this.options;d.each(["","X","Y"],function(a,b){f.style["overflow"+b]=g.overflow[a]})}this.options.hide&&d(this.elem).hide();if(this.options.hide||this.options.show)for(var h in this.options.curAnim)d.style(this.elem,h,this.options.orig[h]);this.options.complete.call(this.elem)}return!1}var i=b-this.startTime;this.state=i/this.options.duration;var j=this.options.specialEasing&&this.options.specialEasing[this.prop],k=this.options.easing||(d.easing.swing?"swing":"linear");this.pos=d.easing[j||k](this.state,i,0,1,this.options.duration),this.now=this.start+(this.end-this.start)*this.pos,this.update();return!0}},d.extend(d.fx,{tick:function(){var a=d.timers;for(var b=0;b
";d.extend(b.style,{position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"}),b.innerHTML=j,a.insertBefore(b,a.firstChild),e=b.firstChild,f=e.firstChild,h=e.nextSibling.firstChild.firstChild,this.doesNotAddBorder=f.offsetTop!==5,this.doesAddBorderForTableAndCells=h.offsetTop===5,f.style.position="fixed",f.style.top="20px",this.supportsFixedPosition=f.offsetTop===20||f.offsetTop===15,f.style.position=f.style.top="",e.style.overflow="hidden",e.style.position="relative",this.subtractsBorderForOverflowNotVisible=f.offsetTop===-5,this.doesNotIncludeMarginInBodyOffset=a.offsetTop!==i,a.removeChild(b),a=b=e=f=g=h=null,d.offset.initialize=d.noop},bodyOffset:function(a){var b=a.offsetTop,c=a.offsetLeft;d.offset.initialize(),d.offset.doesNotIncludeMarginInBodyOffset&&(b+=parseFloat(d.css(a,"marginTop"))||0,c+=parseFloat(d.css(a,"marginLeft"))||0);return{top:b,left:c}},setOffset:function(a,b,c){var e=d.css(a,"position");e==="static"&&(a.style.position="relative");var f=d(a),g=f.offset(),h=d.css(a,"top"),i=d.css(a,"left"),j=e==="absolute"&&d.inArray("auto",[h,i])>-1,k={},l={},m,n;j&&(l=f.position()),m=j?l.top:parseInt(h,10)||0,n=j?l.left:parseInt(i,10)||0,d.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):f.css(k)}},d.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),e=cf.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(d.css(a,"marginTop"))||0,c.left-=parseFloat(d.css(a,"marginLeft"))||0,e.top+=parseFloat(d.css(b[0],"borderTopWidth"))||0,e.left+=parseFloat(d.css(b[0],"borderLeftWidth"))||0;return{top:c.top-e.top,left:c.left-e.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&(!cf.test(a.nodeName)&&d.css(a,"position")==="static"))a=a.offsetParent;return a})}}),d.each(["Left","Top"],function(a,c){var e="scroll"+c;d.fn[e]=function(c){var f=this[0],g;if(!f)return null;if(c!==b)return this.each(function(){g=cg(this),g?g.scrollTo(a?d(g).scrollLeft():c,a?c:d(g).scrollTop()):this[e]=c});g=cg(f);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:d.support.boxModel&&g.document.documentElement[e]||g.document.body[e]:f[e]}}),d.each(["Height","Width"],function(a,c){var e=c.toLowerCase();d.fn["inner"+c]=function(){return this[0]?parseFloat(d.css(this[0],e,"padding")):null},d.fn["outer"+c]=function(a){return this[0]?parseFloat(d.css(this[0],e,a?"margin":"border")):null},d.fn[e]=function(a){var f=this[0];if(!f)return a==null?null:this;if(d.isFunction(a))return this.each(function(b){var c=d(this);c[e](a.call(this,b,c[e]()))});if(d.isWindow(f)){var g=f.document.documentElement["client"+c];return f.document.compatMode==="CSS1Compat"&&g||f.document.body["client"+c]||g}if(f.nodeType===9)return Math.max(f.documentElement["client"+c],f.body["scroll"+c],f.documentElement["scroll"+c],f.body["offset"+c],f.documentElement["offset"+c]);if(a===b){var h=d.css(f,e),i=parseFloat(h);return d.isNaN(i)?h:i}return this.css(e,typeof a==="string"?a:a+"px")}}),a.jQuery=a.$=d})(window); -------------------------------------------------------------------------------- /public/js/plugin.colors.js: -------------------------------------------------------------------------------- 1 | var inspirationPlugins = inspirationPlugins || []; 2 | 3 | (function() { 4 | function Octree(x, y, z, w, h, d) { 5 | this.root = new Octree.Cell(x, y, z, w, h, d, 0); 6 | } 7 | 8 | Octree.MaxLevel = 4; 9 | 10 | //p = {x, y} 11 | Octree.prototype.add = function(p) { 12 | this.root.add(p); 13 | } 14 | 15 | Octree.Cell = function(x, y, z, w, h, d, level) { 16 | this.x = x; 17 | this.y = y; 18 | this.z = z; 19 | this.w = w; 20 | this.h = h; 21 | this.d = d; 22 | this.level = level; 23 | this.points = []; 24 | this.children = []; 25 | } 26 | 27 | Octree.Cell.prototype.add = function(p) { 28 | this.points.push(p); 29 | 30 | if (this.children.length > 0) { 31 | this.addToChildren(p); 32 | } 33 | else { 34 | if (this.points.length > 1 && this.level < Octree.MaxLevel) { 35 | this.split(); 36 | } 37 | } 38 | } 39 | 40 | Octree.Cell.prototype.addToChildren = function(p) { 41 | for(var i=0; i= this.x && p.y >= this.y && p.z >= this.z && p.x <= this.x + this.w && p.y <= this.y + this.h && p.z <= this.z + this.d; 51 | } 52 | 53 | // 1 2 3 4 54 | // 5 6 7 8 55 | Octree.Cell.prototype.split = function() { 56 | var x = this.x; 57 | var y = this.y; 58 | var z = this.z; 59 | var w2 = this.w/2; 60 | var h2 = this.h/2; 61 | var d2 = this.d/2; 62 | 63 | this.children.push(new Octree.Cell(x, y, z, w2, h2, d2, this.level + 1)); 64 | this.children.push(new Octree.Cell(x + w2, y, z, w2, h2, d2, this.level + 1)); 65 | this.children.push(new Octree.Cell(x, y, z + d2, w2, h2, d2, this.level + 1)); 66 | this.children.push(new Octree.Cell(x + w2, y, z + d2, w2, h2, d2, this.level + 1)); 67 | this.children.push(new Octree.Cell(x, y + h2, z, w2, h2, d2, this.level + 1)); 68 | this.children.push(new Octree.Cell(x + w2, y + h2, z, w2, h2, d2, this.level + 1)); 69 | this.children.push(new Octree.Cell(x, y + h2, z + d2, w2, h2, d2, this.level + 1)); 70 | this.children.push(new Octree.Cell(x + w2, y + h2, z + d2, w2, h2, d2, this.level + 1)); 71 | 72 | for(var i=0; i■'); 90 | Palette.fromImage(img.src, function(err, colors) { 91 | 92 | var totalPoints = colors.map(prop('numPoints')).reduce(sum, 0); 93 | var w = img.width; 94 | var h = img.height; 95 | colors.forEach(function(o) { 96 | var colorW = Math.floor(w * o.numPoints / totalPoints); 97 | var div = document.createElement('div'); 98 | div.style.float = 'left'; 99 | div.style.width = colorW + 'px'; 100 | div.style.height = h + 'px'; 101 | div.style.background = o.color.getHex(); 102 | img.parentNode.appendChild(div); 103 | }) 104 | img.parentNode.removeChild(img); 105 | }) 106 | linksWrapper.append(',', colorLink); 107 | 108 | imgInfo.plugindata.colors = colors; 109 | setTimeout(callback, 500); 110 | } 111 | 112 | var colorsPlugin = { 113 | name : 'colors', 114 | run : run 115 | }; 116 | inspirationPlugins.push(colorsPlugin); 117 | })(); 118 | -------------------------------------------------------------------------------- /public/js/scraper.js: -------------------------------------------------------------------------------- 1 | //TODO: 2 | //- autogenerate container id 3 | 4 | $(document).ready(function() { 5 | function log(msg) { 6 | if (window.console) { 7 | console.log(msg); 8 | } 9 | } 10 | 11 | function cleanTagText(text) { 12 | return text.replace(/^\s+/, '').replace(/,/g, ' ').replace(/\s+/g, ' ').replace(/\s+$/, ''); 13 | } 14 | 15 | var inspiration_server = "http://localhost:3000"; 16 | var containerId = "inspiration3141592653589793"; 17 | 18 | log("20120216.1"); 19 | 20 | var thumbSize = 80; 21 | 22 | var cssReset = $(''); 23 | cssReset.text('#' + containerId + ', ' + '#' + containerId + ' * { background: #FFFFFF; margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline; color: black;}'); 24 | var container = $('
'); 25 | 26 | var inputPanel = $('
'); 27 | var imgThumb = $(''); 28 | var imgBox = $(''); 29 | var refererBox = $(''); 30 | var titleBox = $(''); 31 | var tagsBox = $(''); 32 | var okBtn = $(''); 33 | var loaderThumb = $(''); 34 | inputPanel.append(imgThumb); 35 | inputPanel.append(titleBox); 36 | inputPanel.append(refererBox); 37 | inputPanel.append(tagsBox); 38 | inputPanel.append(okBtn); 39 | inputPanel.append(loaderThumb); 40 | 41 | container.append(inputPanel); 42 | 43 | var images = []; 44 | 45 | function addThumb(url, w, h) { 46 | var imgThumb = $('
'); 47 | var imgThumbImage = $(''); 48 | if (w > h) { 49 | imgThumbImage.attr("height", thumbSize); 50 | var dx = (thumbSize - w*thumbSize/h)/2; 51 | imgThumbImage.css("left", dx + "px"); 52 | } 53 | else { 54 | imgThumbImage.attr("width", thumbSize); 55 | } 56 | imgThumbImage.attr("src", url); 57 | imgThumbImage.attr("title", w + " x " + h); 58 | imgThumb.append(imgThumbImage); 59 | container.append(imgThumb); 60 | return imgThumbImage; 61 | } 62 | 63 | $("img").each(function() { 64 | var img = $(this); 65 | var w = img.width(); 66 | var h = img.height(); 67 | var url = img.attr("src"); 68 | 69 | if (w <= 100 || h <= 100) return; 70 | 71 | images.push(addThumb(url, w, h)); 72 | }); 73 | 74 | $("iframe").each(function() { 75 | var iframe = $(this); 76 | iframe.contents().find('img').each(function() { 77 | var img = $(this); 78 | var w = img.width(); 79 | var h = img.height(); 80 | var url = img.attr("src"); 81 | 82 | if (w <= 100 || h <= 100) return; 83 | 84 | images.push(addThumb(url, w, h)); 85 | }) 86 | }); 87 | 88 | console.log(images); 89 | 90 | //VIMEO 91 | $("div[data-thumb]").each(function() { 92 | var url = $(this).attr("data-thumb"); 93 | images.push(addThumb(url, 1, 1)); 94 | }); 95 | 96 | //YOUTUBE 97 | if (document.location.host == "www.youtube.com") { 98 | var videoIDParam = document.location.search.substr(1).split("&") 99 | .map(function(u) { return u.split("="); }) 100 | .filter(function(u) { return u[0] == "v"; }); 101 | var videoID = videoIDParam[0][1]; 102 | images.push(addThumb("http://img.youtube.com/vi/" + videoID + "/0.jpg", 480, 360)); 103 | images.push(addThumb("http://img.youtube.com/vi/" + videoID + "/maxresdefault.jpg", 0, 0)); 104 | } 105 | 106 | 107 | $("body").prepend(cssReset); 108 | $("body").prepend(container); 109 | 110 | function xxs(url, params) { 111 | console.log("xxs", url, params); 112 | url += "?"; 113 | for(var paramName in params) { 114 | url += paramName + "=" + encodeURIComponent(params[paramName]) + "&"; 115 | } 116 | var script = $(''); 117 | $("body").append(script); 118 | } 119 | 120 | window.inspiration_callback_1234567890 = function(error) { 121 | if (error != undefined) { 122 | console.log("Sending Error: " + error); 123 | okBtn.css("color", "red"); 124 | } 125 | else { 126 | console.log("Sending OK"); 127 | okBtn.css("color", "black"); 128 | } 129 | loaderThumb.fadeOut(); 130 | }; 131 | 132 | $(images).each(function() { 133 | var img = this; 134 | img.mousedown(function(e) { 135 | var src = img.attr("src"); 136 | 137 | if (src.indexOf("http") == -1) { 138 | if (src.indexOf("//") == 0) { 139 | src = "http:" + src; 140 | } 141 | else if (src.indexOf("/") == 0) { 142 | src = "http://" + document.location.host + src; 143 | } 144 | else { 145 | //relative urls 146 | var base = ""; 147 | var baseTags = document.getElementsByTagName("base"); 148 | if (baseTags.length > 0) { 149 | base = baseTags[0].href; 150 | src = base + src; 151 | } 152 | else { 153 | var slashIndex = document.location.pathname.lastIndexOf("/"); 154 | var path = document.location.pathname.substr(0, slashIndex + 1); 155 | src = "http://" + document.location.host + path + src; 156 | } 157 | } 158 | } 159 | var title = document.title; 160 | var referer = document.location.href; 161 | 162 | imgBox.val(src); 163 | imgThumb.get(0).src = src; 164 | titleBox.val(title); 165 | refererBox.val(referer); 166 | inputPanel.fadeIn('normal', function() { 167 | tagsBox.focus(); 168 | }); 169 | e.preventDefault(); 170 | return false; 171 | }); 172 | }); 173 | 174 | $("body").bind("keydown", function(e) { 175 | if (e.keyCode == 27) { 176 | container.remove(); 177 | } 178 | }); 179 | 180 | inputPanel.bind('submit', function(e) { 181 | console.log(inspiration_server); 182 | var submitUrl = inspiration_server + "/api/post"; 183 | inputPanel.get(0).method = "POST"; 184 | inputPanel.get(0).action = submitUrl; 185 | e.preventDefault(); // <-- important 186 | console.log("Sending"); 187 | var img = imgBox.val(); 188 | var referer = refererBox.val(); 189 | var title = titleBox.val(); 190 | 191 | var tags = cleanTagText(tagsBox.val()); 192 | 193 | loaderThumb.fadeIn(); 194 | xxs(submitUrl, {img:encodeURIComponent(img), referer:referer, title:title, tags:tags, callback:"inspiration_callback_1234567890"}); 195 | }); 196 | 197 | loaderThumb.hide(); 198 | 199 | }); 200 | -------------------------------------------------------------------------------- /public/js/tags.js: -------------------------------------------------------------------------------- 1 | var thumbWidth = 300; 2 | var columnMargin = 10; 3 | var columnWidth = thumbWidth + columnMargin; 4 | var columns = []; 5 | 6 | String.prototype.format = function() { 7 | var args = arguments; 8 | return this.replace(/{(\d+)}/g, function(match, number) { 9 | return typeof args[number] != 'undefined' 10 | ? args[number] 11 | : match 12 | ; 13 | }); 14 | }; 15 | 16 | function buildColumns() { 17 | var w = document.body.clientWidth; 18 | var numColumns = Math.floor(w/columnWidth); 19 | for(var i=0; i'); 24 | $(document.body).append(column.div); 25 | columns.push(column); 26 | } 27 | } 28 | 29 | function findColumn() { 30 | var min = 99999999; 31 | var mini = 0; 32 | for(var i=0; i"); 44 | var title = $("

{1} [{2}]

".format(inspiration_server, tag.name, tag.count)); 45 | 46 | set.append(title); 47 | 48 | setTimeout(function() { 49 | $.get(inspiration_server + "/api/latest?tag=" + escape(tag.name), function(images) { 50 | $(images).each(function(i) { 51 | var style = ""; 52 | var className = ""; 53 | if (i == 0) { 54 | className = "tagLatestMain"; 55 | style = "width='" + thumbWidth + "px'";// + " " + "height='" + thumbWidth*0.75 + "px'"; 56 | } 57 | else { 58 | className = "tagLatestThumb"; 59 | if (this.ratio < 1) { 60 | style = "width='" + thumbWidth/4 + "px'"; 61 | } 62 | else { 63 | style = "height='" + thumbWidth/4 + "px'"; 64 | } 65 | 66 | } 67 | var img = $("
".format(className, inspiration_server + "/images/" + this.thumb_url, style)); 68 | set.append(img); 69 | }) 70 | }, "json"); 71 | }, i*10); 72 | 73 | 74 | var column = findColumn(); 75 | column.div.append(set); 76 | column.height += 10; 77 | } 78 | 79 | $(document).ready(function() { 80 | buildColumns(); 81 | 82 | console.log("getting from " + inspiration_server); 83 | 84 | $.get(inspiration_server + "/api/tags", function(tags) { 85 | for(var i=0; i 2 | 3 | 4 | 5 | 6 | 7 | 23 | 24 | -------------------------------------------------------------------------------- /routes/api.db.js: -------------------------------------------------------------------------------- 1 | var persist = require("persist"); 2 | var type = persist.type; 3 | var models = require("../models"); 4 | 5 | exports.findTags = function(connection, tagNames, callback) { 6 | var tags = []; 7 | var newTags = []; 8 | 9 | if (!tagNames || tagNames.length == 0) { 10 | callback(tags, newTags); 11 | return; 12 | } 13 | 14 | tagNames.forEach(function(tagName) { 15 | models.Tag.using(connection).where('name = ?', tagName).all(function(err, tag) { 16 | if (tag && tag.length > 0) { 17 | tags.push(tag[0]); 18 | } 19 | else { 20 | tag = new models.Tag({ name : tagName }); 21 | tags.push(tag); 22 | newTags.push(tag); 23 | } 24 | if (tags.length == tagNames.length) { 25 | callback(tags, newTags); 26 | } 27 | }); 28 | }) 29 | } 30 | 31 | function imageExists(connection, originalUrl, callback) { 32 | models.Image.using(connection).where('originalUrl = ?', originalUrl).all(function(err, image) { 33 | callback(image.length > 0); 34 | }) 35 | } 36 | 37 | function addImage(connection, imageData, callback) { 38 | 39 | var data = []; 40 | //console.log("finding", imageData.tags); 41 | 42 | exports.findTags(connection, imageData.tags, function(tags, newTags) { 43 | imageData.tags = tags; 44 | if (newTags.length > 0) { 45 | data.push.apply(data, newTags); 46 | } 47 | 48 | var image = new models.Image(imageData); 49 | data.push(image); 50 | 51 | connection.save(data, function (err) { 52 | callback(err, image.id); 53 | }); 54 | }) 55 | } 56 | 57 | exports.addImage = addImage; 58 | 59 | 60 | exports.saveImage = function(imageData, callback) { 61 | persist.connect(function(err, connection) { 62 | if (err) { 63 | callback(err); 64 | return; 65 | } 66 | else { 67 | addImage(connection, imageData, function(err, imageId) { 68 | callback(err, imageId) 69 | }); 70 | } 71 | connection.close(); 72 | }); 73 | } 74 | 75 | exports.delete = function(imageId, callback) { 76 | persist.connect(function(err, connection) { 77 | if (err) { 78 | callback(err); 79 | return; 80 | } 81 | else { 82 | models.Image.using(connection).where('id = ?', [imageId]).first(function(err, image) { 83 | var cachedImageFile = image.cachedUrl; 84 | var thumbImageFile = image.thumbUrl; 85 | image.tags = []; 86 | image.save(connection, function(err) { 87 | if (err) { 88 | callback(err); 89 | return; 90 | } 91 | else { 92 | image.delete(connection, function(err) { 93 | callback(err, cachedImageFile, thumbImageFile); 94 | }); 95 | } 96 | }); 97 | }); 98 | } 99 | connection.close(); 100 | }); 101 | } 102 | 103 | 104 | -------------------------------------------------------------------------------- /routes/api.js: -------------------------------------------------------------------------------- 1 | var persist = require("persist"); 2 | var type = persist.type; 3 | var models = require('../models'); 4 | var utils = require('./api.utils'); 5 | var db = require('./api.db'); 6 | var path = require('path'); 7 | 8 | exports.get = function(req, res) { 9 | persist.connect(function(err, connection) { 10 | if(err) { 11 | console.log("api.get failed") 12 | throw err; 13 | } 14 | 15 | var options = req.originalUrl.replace("/api/get", "").split("/"); 16 | var tagsFilter = null; 17 | var searchFilter = null; 18 | var complexityFilter = null; 19 | 20 | var i = 0; 21 | while(options.length > 0) { 22 | var option = options.shift(); 23 | if (option == "tag") { 24 | tagsFilter = unescape(options.shift()).split("+"); 25 | } 26 | if (option == "complexity") { 27 | complexityFilter = unescape(options.shift()); 28 | } 29 | if (option == "s") { 30 | searchFilter = unescape('' + options.shift()).replace(/\+/g, ' ').toLowerCase(); 31 | } 32 | } 33 | 34 | //limit(5) - paging 35 | models.Image.using(connection).orderBy('id', 'desc').include("tags").all(function(err, imagesData) { 36 | var images = []; 37 | var totalFilteredOut = 0; 38 | imagesData = imagesData || []; 39 | if (imagesData.length == 0) { 40 | res.send(JSON.stringify(images)); 41 | }; 42 | imagesData.forEach(function(imageData) { 43 | var image = { 44 | id: imageData.id, 45 | title: imageData.title, 46 | referer: imageData.referer, 47 | originalUrl : imageData.originalUrl, 48 | cachedUrl : imageData.cachedUrl, 49 | thumbUrl : imageData.thumbUrl, 50 | ratio : imageData.ratio, 51 | complexity : imageData.complexity, 52 | tags: [] 53 | } 54 | var hasTags = 0; 55 | var filteredOut = false; 56 | imageData.tags.forEach(function(tagData) { 57 | if (tagsFilter && (tagsFilter.indexOf(tagData.name) !== -1)) { 58 | hasTags++; 59 | } 60 | image.tags.push(tagData.name); 61 | }); 62 | 63 | if (tagsFilter && hasTags != tagsFilter.length) { 64 | filteredOut = true; 65 | totalFilteredOut++; 66 | } 67 | else if (complexityFilter && imageData.complexity != complexityFilter) { 68 | filteredOut = true; 69 | totalFilteredOut++; 70 | } 71 | else if (searchFilter && (image.title.toLowerCase().indexOf(searchFilter) == -1 && (image.referer || '').toLowerCase().indexOf(searchFilter) == -1)) { 72 | filteredOut = true; 73 | totalFilteredOut++; 74 | } 75 | else { 76 | images.push(image); 77 | } 78 | 79 | if (images.length + totalFilteredOut == imagesData.length) { 80 | res.send(JSON.stringify(images)); 81 | } 82 | }); 83 | }); 84 | connection.close(); 85 | }); 86 | }; 87 | 88 | exports.post = function(req, res) { 89 | var callback = req.query.callback; 90 | 91 | var imageData = { 92 | title: req.query.title || "Unknown", 93 | referer: req.query.referer || "http://unknown", 94 | originalUrl : decodeURIComponent(req.query.img), 95 | cachedUrl : "", 96 | thumbUrl : "", 97 | ratio : 1, 98 | complexity: 0, 99 | tags: (req.query.tags ? req.query.tags.split(" ") : null) 100 | } 101 | 102 | console.log(req.query); 103 | 104 | console.log("Downloading...", imageData); 105 | 106 | utils.downloadAndCreateThumb(imageData.originalUrl, function(err, cachedUrl, thumbUrl, ratio) { 107 | imageData.cachedUrl = cachedUrl; 108 | imageData.thumbUrl = thumbUrl; 109 | imageData.ratio = ratio; 110 | 111 | console.log("Downloaded...", imageData); 112 | 113 | res.setHeader("Content-Type", "text/javascript"); 114 | var id = -1; 115 | if (err != null) { 116 | res.send(JSON.stringify({error:err})); 117 | } 118 | else { 119 | db.saveImage(imageData, function(err, imageId) { 120 | imageData.id = imageId; 121 | res.send('inspiration_callback_1234567890('+err+')'); 122 | }) 123 | } 124 | }) 125 | } 126 | 127 | exports.update = function(req, res) { 128 | var imageId = req.query.id; 129 | 130 | persist.connect(function(err, connection) { 131 | if(err) { throw err; } 132 | 133 | if (req.query.title) { 134 | models.Image.update(connection, Number(imageId), { title: req.query.title}, function(err) { 135 | if (err) res.send(err); 136 | else res.send("OK"); 137 | }); 138 | } 139 | if (req.query.referer) { 140 | models.Image.update(connection, Number(imageId), { referer: req.query.referer}, function(err) { 141 | if (err) res.send(err); 142 | else res.send("OK"); 143 | }); 144 | } 145 | else if (req.query.tags) { 146 | var updatedTags = req.query.tags.split(","); 147 | console.log("updatedTags", updatedTags); 148 | db.findTags(connection, updatedTags, function(tags, newTags) { 149 | function saveUpdatedImage() { 150 | models.Image.using(connection).where('id = ?', imageId).all(function(err, imagesData) { 151 | console.log("tags.length", tags.length, newTags.length); 152 | imagesData[0].tags = tags; 153 | imagesData[0].save(connection, function(err) { 154 | if (err) res.send(err); 155 | else res.send("OK " + JSON.stringify(newTags)); 156 | }); 157 | }); 158 | } 159 | 160 | if (newTags) { 161 | connection.save(newTags, saveUpdatedImage); 162 | } 163 | else { 164 | saveUpdatedImage(); 165 | } 166 | 167 | }) 168 | } 169 | 170 | connection.close(); 171 | }); 172 | } 173 | 174 | exports.tags = function(req, res) { 175 | persist.connect(function(err, connection) { 176 | if(err) { 177 | console.log("api.tags failed"); 178 | throw err; 179 | } 180 | 181 | var tagsQuery = "SELECT name, COUNT(tag_id) as count FROM images_tags it JOIN tags t ON it.tag_id = t.id GROUP BY tag_id ORDER BY COUNT(tag_id) DESC"; 182 | 183 | connection.runSqlAll(tagsQuery, [], function(err, tags) { 184 | res.send(JSON.stringify(tags)); 185 | }); 186 | 187 | connection.close(); 188 | }); 189 | } 190 | 191 | exports.latest = function(req, res) { 192 | persist.connect(function(err, connection) { 193 | if(err) { 194 | console.log("api.latest failed"); 195 | throw err; 196 | } 197 | 198 | var latestQuery = "SELECT thumb_url, ratio FROM images JOIN images_tags ON images.id = images_tags.image_id JOIN tags ON images_tags.tag_id = tags.id WHERE tags.name = ? ORDER BY images.id DESC LIMIT 5"; 199 | 200 | connection.runSqlAll(latestQuery, [req.query.tag], function(err, images) { 201 | res.send(JSON.stringify(images)); 202 | }); 203 | 204 | connection.close(); 205 | }); 206 | } 207 | 208 | exports.delete = function(req, res) { 209 | db.delete(req.query.imageId, function(err, chachedImageFile, thumbImageFile) { 210 | utils.deleteImageFile(chachedImageFile); 211 | utils.deleteImageFile(thumbImageFile); 212 | res.send(JSON.stringify({ err: err })); 213 | }) 214 | } 215 | 216 | exports.upload = function(req, res) { 217 | var file = req.files.file; 218 | 219 | var imageData = { 220 | title: file.name, 221 | referer: "", 222 | originalUrl : "", 223 | cachedUrl : "", 224 | thumbUrl : "", 225 | ratio : 1, 226 | complexity: 0, 227 | tags: null 228 | } 229 | 230 | utils.copyAndCreateThumb(file, function(err, cachedUrl, thumbUrl, ratio) { 231 | imageData.cachedUrl = cachedUrl; 232 | imageData.thumbUrl = thumbUrl; 233 | imageData.ratio = ratio; 234 | 235 | console.log("Downloaded...", imageData); 236 | 237 | res.setHeader("Content-Type", "text/javascript"); 238 | var id = -1; 239 | if (err != null) { 240 | console.log('ERROR upload:', err); 241 | var body = "({1},{2})".format(err, id); 242 | res.send(body); 243 | } 244 | else { 245 | console.log('image saved almost'); 246 | db.saveImage(imageData, function(err, imageId) { 247 | console.log('image saved', imageId); 248 | imageData.id = imageId; 249 | res.send(JSON.stringify(imageData)); 250 | }) 251 | } 252 | }) 253 | 254 | //setTimeout(function() { 255 | // res.contentType('application/json'); 256 | // res.send({name:file.name, bla:file.path, rnd: Math.random()}); 257 | // res.end(); 258 | //}, Math.floor(Math.random() * 2000)); 259 | } 260 | -------------------------------------------------------------------------------- /routes/api.utils.js: -------------------------------------------------------------------------------- 1 | var util = require("util"); 2 | var http = require("http"); 3 | var url = require("url"); 4 | var fs = require("fs"); 5 | var path = require('path'); 6 | var gm = require("gm"); 7 | var mime = require("mime-magic"); 8 | var url = require("url"); 9 | 10 | var THUMB_WIDTH = 600; 11 | 12 | String.prototype.format = function() { 13 | var args = arguments; 14 | return this.replace(/{(\d+)}/g, function(match, number) { 15 | return typeof args[number] != 'undefined' 16 | ? args[number] 17 | : match 18 | ; 19 | }); 20 | }; 21 | 22 | exports.downloadFile = function(fileUrl, downloadPath, callback) { 23 | var host = url.parse(fileUrl).hostname; 24 | var path = url.parse(fileUrl).path; 25 | //console.log("urls", fileUrl, url.parse(fileUrl)); 26 | var filename = path.split("/").pop(); 27 | var downloadfile = fs.createWriteStream(downloadPath, {'flags': 'a'}); 28 | 29 | //console.log("downloadFile", fileUrl, "to", downloadfile); 30 | 31 | var options = { 32 | host: host, 33 | port: 80, 34 | path: path 35 | }; 36 | 37 | var req = http.request(options, function(res) { 38 | res.on("data", function (chunk) { 39 | downloadfile.write(chunk, encoding='binary'); 40 | }); 41 | 42 | res.on("end", function () { 43 | downloadfile.end(); 44 | console.log("downloaded", downloadPath); 45 | callback(null, downloadPath); 46 | }); 47 | }); 48 | 49 | req.on('error', function(e) { 50 | console.log('problem with request: ' + e.message); 51 | }); 52 | 53 | req.end(); 54 | } 55 | 56 | exports.resizeImage = function(file, thumb, width, height, callback) { 57 | var img = gm(file); 58 | img.size(function(err, value) { 59 | if (err) { 60 | console.log('ERROR resizeImage', err); 61 | exports.copy(file, thumb, function(copyErr) { 62 | var ratio = 1; 63 | callback(copyErr, ratio); 64 | }) 65 | } 66 | else { 67 | var ratio = value.width / value.height; 68 | img.resize(width).write(thumb, function(e, a) { 69 | console.log(e, a); 70 | callback(err, ratio); 71 | }) 72 | } 73 | }) 74 | } 75 | 76 | exports.downloadAndCreateThumb = function(imageFile, callback) { 77 | var contentImagesPath = path.normalize(__dirname + "/../content/images"); 78 | var urlParts = url.parse(imageFile); 79 | var urlPath = urlParts.path; 80 | var queryPos = urlPath.indexOf('?'); 81 | var hashPos = urlPath.indexOf('#'); 82 | var slashSeachEnd = urlPath.length-1; 83 | if (queryPos != -1) slashSeachEnd = Math.min(slashSeachEnd, queryPos); 84 | if (hashPos != -1) slashSeachEnd = Math.min(slashSeachEnd, hashPos); 85 | var lastPathSlash = urlPath.lastIndexOf('/', slashSeachEnd); 86 | var requestedFile = urlPath.substr(lastPathSlash+1); 87 | var validChars = /[^-_.() abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]/g 88 | var validFile = requestedFile.replace(validChars, '_'); 89 | var ext = path.extname(validFile) 90 | var base = path.basename(validFile, ext); 91 | 92 | var tmpDownloadPath = contentImagesPath + "/00_" + (Date.now() + Math.floor(Math.random()*999999)); 93 | 94 | exports.downloadFile(imageFile, tmpDownloadPath, function(err, file) { 95 | mime(file, function (err, type) { 96 | if (err) { 97 | console.log('downloadAndCreateThumb', err); 98 | callback(err, null, null, 0); 99 | fs.unlink(tmpDownloadPath); 100 | return; 101 | } 102 | var typeParts = type.split('/'); 103 | if (typeParts[0] != 'image') { 104 | console.log('downloadAndCreateThumb', 'downloaded file is not an image', type); 105 | callback('downloaded file is not an image', null, null, 0); 106 | fs.unlink(tmpDownloadPath); 107 | return; 108 | } 109 | if (typeParts[1] == 'jpeg') { typeParts[1] = 'jpg'; } 110 | 111 | var ext = '.' + typeParts[1]; 112 | 113 | var timestamp = Date.now(); 114 | var cachedFile = base + "_" + timestamp + "" + ext; 115 | var cachedFilePath = path.join(contentImagesPath, cachedFile); 116 | var thumbFile = base + "_" + timestamp + "_thumb" + ext; 117 | var thumbFilePath = path.join(contentImagesPath, thumbFile); 118 | 119 | fs.rename(tmpDownloadPath, cachedFilePath, function(err) { 120 | if (err) { 121 | console.log('downloadAndCreateThumb', 'rename failed'); 122 | callback('rename failed', null, null, 0); 123 | fs.unlink(tmpDownloadPath); 124 | fs.unlink(cachedFile); 125 | return; 126 | } 127 | console.log('downloaded', imageFile, 'to', validFile); 128 | exports.resizeImage(cachedFilePath, thumbFilePath, THUMB_WIDTH, 0, function(err, ratio) { 129 | console.log("Created thumb", err, cachedFile, thumbFile, ratio); 130 | callback(err, cachedFile, thumbFile, ratio); 131 | }); 132 | }) 133 | }); 134 | }); 135 | } 136 | 137 | exports.copy = function (src, dst, callback) { 138 | var is = fs.createReadStream(src); 139 | var os = fs.createWriteStream(dst); 140 | is.pipe(os); 141 | is.on('end', callback); 142 | }; 143 | 144 | exports.copyAndCreateThumb = function(uploadedImageFile, callback) { 145 | var contentImagesPath = path.normalize(__dirname + "/../content/images"); 146 | 147 | var ext = path.extname(uploadedImageFile.name); 148 | var base = path.basename(uploadedImageFile.name.replace(/\s/g, "-"), ext); 149 | 150 | var timestamp = (new Date()).getTime(); 151 | var cachedFile = base + "_" + timestamp + ext; 152 | var thumbFile = base + "_" + timestamp + "_thumb" + ext; 153 | 154 | var cachedFilePath = contentImagesPath + "/" + cachedFile; 155 | var thumbFilePath = contentImagesPath + "/" + thumbFile; 156 | 157 | exports.copy(uploadedImageFile.path, cachedFilePath, function(e) { 158 | exports.resizeImage(cachedFilePath, thumbFilePath, THUMB_WIDTH, 0, function(err, ratio) { 159 | callback(err, cachedFile, thumbFile, ratio); 160 | }); 161 | }) 162 | } 163 | 164 | exports.deleteImageFile = function(imageFile) { 165 | var contentImagesPath = path.normalize(__dirname + "/../content/images"); 166 | var imageFilePath = contentImagesPath + "/" + imageFile; 167 | if (fs.existsSync(imageFilePath)) { 168 | fs.unlinkSync(imageFilePath); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /routes/bookmarklet.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | 3 | exports.bookmarklet = function(req, res) { 4 | fs.readFile(__dirname + '/../public/js/bookmarklet.js', 'utf-8', function(err, bookmarketCode) { 5 | var serverUrl = "http://" + (req.headers.host + req.url).replace("/bookmarklet", ""); 6 | bookmarketCode = bookmarketCode.replace("SCRAPER_JS", serverUrl + "/js/scraper.js"); 7 | bookmarketCode = bookmarketCode.replace("JQUERY_JS", serverUrl + "/js/jquery.js"); 8 | bookmarketCode = bookmarketCode.replace("SCRAPER_CSS", serverUrl + "/css/scraper.css"); 9 | res.send(bookmarketCode); 10 | }); 11 | }; 12 | -------------------------------------------------------------------------------- /routes/images.js: -------------------------------------------------------------------------------- 1 | var url = require('url'); 2 | var path = require('path'); 3 | 4 | exports.images = function(req, res, next) { 5 | var filename = url.parse(req.path).pathname.split("/").pop(); 6 | var filepath = path.normalize(__dirname + "/../content/images/" + filename); 7 | res.sendFile(filepath); 8 | }; -------------------------------------------------------------------------------- /routes/index.js: -------------------------------------------------------------------------------- 1 | exports.index = function(req, res) { 2 | res.render('index', { }) 3 | }; 4 | 5 | exports.api = require('./api'); 6 | exports.bookmarklet = require('./bookmarklet').bookmarklet; 7 | exports.images = require('./images').images; 8 | exports.tags = require('./tags').tags; -------------------------------------------------------------------------------- /routes/tags.js: -------------------------------------------------------------------------------- 1 | exports.tags = function(req, res) { 2 | res.render('tags', { }) 3 | }; 4 | -------------------------------------------------------------------------------- /routes/test.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | var utils = require('./api.utils'); 3 | 4 | //http.get("http://marcinignac.com/projects/nine-point-five/ninepointfive_alternatives1.jpg", function(res) { 5 | // console.log("Got response: " + res.statusCode); 6 | //}).on('error', function(e) { 7 | // console.log("Got error: " + e.message); 8 | //}); 9 | 10 | var url = "http://marcinignac.com/projects/nine-point-five/ninepointfive_alternatives1.jpg"; 11 | 12 | utils.downloadAndCreateThumb(url, function(err, cachedUrl, thumbUrl, ratio) { 13 | console.log(err); 14 | }); -------------------------------------------------------------------------------- /views/gallery.jade: -------------------------------------------------------------------------------- 1 | html 2 | head 3 | title Kollektor 4 | link(rel='stylesheet', href='/css/gallery.css') 5 | script(src='/js/jquery.js') 6 | script(src='/js/jquery-appear-mod.js') 7 | script(src='/js/config.js') 8 | script(src='/js/gallery.js') 9 | script(src='/js/palette.js') 10 | script(src='/js/plugin.colors.js') 11 | body 12 | -------------------------------------------------------------------------------- /views/index.jade: -------------------------------------------------------------------------------- 1 | include gallery -------------------------------------------------------------------------------- /views/tags.jade: -------------------------------------------------------------------------------- 1 | html 2 | head 3 | title Inspiration 4 | link(rel='stylesheet', href='/css/gallery.css') 5 | script(src='/js/jquery.js') 6 | script(src='/js/jquery-appear-mod.js') 7 | script(src='/js/config.js') 8 | script(src='/js/tags.js') 9 | body --------------------------------------------------------------------------------