diff --git a/LICENSE.md b/LICENSE.md index 6fd6878..e4294fa 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2012 - 2016 Adrian Quevedo +Copyright (c) 2012 - 2020 Adrian Quevedo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/README.md b/README.md index 4512dc9..e643bd8 100644 --- a/README.md +++ b/README.md @@ -9,34 +9,44 @@ --- -# Platform Changees +# Instagram Platform Changes -On June 1 2015, Instagram, which is owned by Facebook, [will stop allowing many third parties to access the images in its feeds](http://techcrunch.com/2015/11/17/just-instagram/). +- On June 1 2015, Instagram, which is owned by Facebook, [will stop allowing many third parties to access the images in its feeds](http://techcrunch.com/2015/11/17/just-instagram/). -This means you will no longer be able to fetch photos form other users with spectragram after May 31. +- This means you will no longer be able to fetch photos form other users with spectragram after May 31. -Please follow this instructions to make it work with your own sandboxed feed: -[How to get Instagram API access token and fix your broken feed](https://github.com/adrianengine/jquery-spectragram/wiki/How-to-get-Instagram-API-access-token-and-fix-your-broken-feed) +- ~~Please follow this instructions to make it work with your own sandboxed feed: +[How to get Instagram API access token and fix your broken feed](https://github.com/adrianengine/jquery-spectragram/wiki/How-to-get-Instagram-API-access-token-and-fix-your-broken-feed)~~ **Update:** Not longer valid. -On April 4 2018, some endpoints this plugin use were deprecated: +- On April 4 2018, some endpoints this plugin use were deprecated: [Instagram Platform Changelog](https://www.instagram.com/developer/changelog/) +- Instagram Legacy API Will be disabled. [Facebook announced the API will work until March 31, 2020.](https://developers.facebook.com/blog/post/2020/03/10/final-reminder-Instagram-legacy-api-platform-disabled-mar-31/) **Update** will be deprecated on June 29, 2020. + +- Spectragram.js has been updated to use the new Instagram Basic Display API, please follow the [new Token process](https://github.com/adrianengine/jquery-spectragram/wiki/Register-on-Instagram-Basic-Display-API-and-get-an-Access-Token). + **Please upgrade** in order to make your Instagram feed work again. --- # Features -* Get the most recent or recently tagged media published by your user from Instagram API -* Display the results on list items or any other HTML tag you define -* Define the size of the pictures (small, medium, big) -* Use your own Instagram application AccessToken +* Get the most recent media published by one user from the Instagram Basic Display API. +* Display the results on list items or any other HTML tag you define, +* Define the size of the pictures (small, medium, large). +* Use your own Instagram application AccessToken. + +# Before You Start + +In order to use the plugin you will need: +- A [Facebook Developer Account](https://developers.facebook.com/apps). +- A public [Instagram Account](https://www.instagram.com/?fbclid=IwAR2DQDyKisGKXB678NN4dqMYQJc9KzIrlYrfJrYFOYq2OmYn72DbG3i1PFE) with media, and its user login credentials. -# How to use +## Register an app and get an Access Token -In order to use the plugin you need to register an application at [Instagram Developers](http://instagram.com/developer/), and [recieve an access_token](http://instagram.com/developer/authentication/). +Please [follow the instructions](https://github.com/adrianengine/jquery-spectragram/wiki/Register-on-Instagram-Basic-Display-API-and-get-an-Access-Token) to get an Access Token from the Wiki. -### Simple usage +# Plugin Simple Usage 1. Be sure to have jQuery script included and then include the **spectragram.min.js** script right before the ``` ``` tag. @@ -45,7 +55,7 @@ In order to use the plugin you need to register an application at [Instagram Dev ``` -1. Set your Instagram ```accessToken``` and the query (username or tag): +1. Set your Instagram ```accessToken```: ``` javascript jQuery.fn.spectragram.accessData = { @@ -53,72 +63,33 @@ jQuery.fn.spectragram.accessData = { }; ``` -1. Call **spectagram** function on the container element and pass it your query: +1. Call **spectagram** function on the container element and pass it your custom options: ``` javascript -$('ul').spectragram('getUserFeed', { - size: 'big' +$('ul').spectragram({ + size: 'small' }); ``` -*This example will show 20 or less results for photos tagged "converse" in a list, "medium" sized.* +*This example will show 25 or less photos in a list, "small" sized.* ## Configuration ``` javascript -.spectragram( Method, [Options] ) - -Method: getUserFeed function - -Options: An array to configure the properties of spectragram -``` - -### Methods - -**getUserFeed** - -Get the most recent media published by the owner of the access_token. - -``` javascript -$('.container').spectragram('getUserFeed',{ - complete : myCallbackFunc(), - max: 10, - size: "small", - wrapEachWith: '
' -}); +.spectragram( Options ) ``` ### Options -**accessToken** (required) - -*Type: String* - -This is your Instagram Application AccessToken. *Default: Null* - -**max** - -*Type: Number* - -A number between 1 and 20 of photos to show. *Default: 20* - -**size** - -*Type: String* - -The size of the photos. 'small', 'medium' or 'big'. *Default: 'medium'* - -**wrapEachWith** - -*Type: String* - -The HTML tag to wrap every result. *Default: '\
  • \
  • '* - -**complete** - -*Type: Function* +An object to configure the properties of spectragram: -A callback function to execute after the display of the photos. *Default: 'null'* +| Name | Required | Type | Default | Description | +|------------------ |---------- |------------ |--------------- |----------------------------------------------------------------- | +| **accessToken** | Yes | *String* | `null` | This is your Instagram Application AccessToken. | +| **max** | No | *Number* | `25` | A number between 1 and 25 of photos to show. | +| **size** | No | *String* | `large` | The size of the photos. 'small', 'medium' or 'large'. | +| **wrapEachWith** | No | *String* | `'
  • '` | The HTML tag to wrap every result. | +| **complete** | No | *Function* | `null` | A callback function to execute after the display of the photos. | ### Example @@ -127,7 +98,7 @@ jQuery.fn.spectragram.accessData = { accessToken: 'your-instagram-access-token' }; -$('ul').spectragram('getUserFeed',{ +$('ul').spectragram({ complete : myCallbackFunc(), max: 4, size: "medium", @@ -147,8 +118,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI # Further notes -Developed by [Adrian Quevedo](http://adrianquevedo.com) in Bogotá - Colombia. +Maintained by [Adrian Quevedo](https://github.com/adrianengine). This code is provided with no warranty. While I strive to maintain backwards compatibility, the code is still under active development. As this is the case, some revisions may break compatibility with earlier versions of the library. Please keep this in mind when using the plugin. -This plugin uses the Instagram(tm) API and is not endorsed or certified by Instagram or Instagram, inc. All Instagram(tm) trademarks displayed on this plugin are property of Instagram, Inc. +This plugin uses the Instagram Basic Display API and is not endorsed or certified by Instagram or Facebook, inc. All Instagram© trademarks displayed on this plugin are property of Facebook, Inc. diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..8e0576d --- /dev/null +++ b/package-lock.json @@ -0,0 +1,393 @@ +{ + "name": "spectragram", + "version": "2.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "align-text": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", + "integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=", + "dev": true, + "requires": { + "kind-of": "^3.0.2", + "longest": "^1.0.1", + "repeat-string": "^1.5.2" + } + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "camelcase": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz", + "integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=", + "dev": true + }, + "center-align": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/center-align/-/center-align-0.1.3.tgz", + "integrity": "sha1-qg0yYptu6XIgBBHL1EYckHvCt60=", + "dev": true, + "requires": { + "align-text": "^0.1.3", + "lazy-cache": "^1.0.3" + } + }, + "cli": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/cli/-/cli-1.0.1.tgz", + "integrity": "sha1-IoF1NPJL+klQw01TLUjsvGIbjBQ=", + "dev": true, + "requires": { + "exit": "0.1.2", + "glob": "^7.1.1" + } + }, + "cliui": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz", + "integrity": "sha1-S0dXYP+AJkx2LDoXGQMukcf+oNE=", + "dev": true, + "requires": { + "center-align": "^0.1.1", + "right-align": "^0.1.1", + "wordwrap": "0.0.2" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "console-browserify": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz", + "integrity": "sha1-8CQcRXMKn8YyOyBtvzjtx0HQuxA=", + "dev": true, + "requires": { + "date-now": "^0.1.4" + } + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "dev": true + }, + "date-now": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", + "integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=", + "dev": true + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "dev": true + }, + "dom-serializer": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.2.2.tgz", + "integrity": "sha512-2/xPb3ORsQ42nHYiSunXkDjPLBaEj/xTwUO4B7XCZQTRk7EBtTOPaygh10YAAh2OI1Qrp6NWfpAhzswj0ydt9g==", + "dev": true, + "requires": { + "domelementtype": "^2.0.1", + "entities": "^2.0.0" + }, + "dependencies": { + "domelementtype": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.0.1.tgz", + "integrity": "sha512-5HOHUDsYZWV8FGWN0Njbr/Rn7f/eWSQi1v7+HsUVwXgn8nWWlL64zKDkS0n8ZmQ3mlWOMuXOnR+7Nx/5tMO5AQ==", + "dev": true + }, + "entities": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-2.0.0.tgz", + "integrity": "sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw==", + "dev": true + } + } + }, + "domelementtype": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz", + "integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==", + "dev": true + }, + "domhandler": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.3.0.tgz", + "integrity": "sha1-LeWaCCLVAn+r/28DLCsloqir5zg=", + "dev": true, + "requires": { + "domelementtype": "1" + } + }, + "domutils": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz", + "integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=", + "dev": true, + "requires": { + "dom-serializer": "0", + "domelementtype": "1" + } + }, + "entities": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz", + "integrity": "sha1-sph6o4ITR/zeZCsk/fyeT7cSvyY=", + "dev": true + }, + "exit": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=", + "dev": true + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "htmlparser2": { + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz", + "integrity": "sha1-mWwosZFRaovoZQGn15dX5ccMEGg=", + "dev": true, + "requires": { + "domelementtype": "1", + "domhandler": "2.3", + "domutils": "1.5", + "entities": "1.0", + "readable-stream": "1.1" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true + }, + "is-buffer": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", + "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", + "dev": true + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true + }, + "jshint": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/jshint/-/jshint-2.11.0.tgz", + "integrity": "sha512-ooaD/hrBPhu35xXW4gn+o3SOuzht73gdBuffgJzrZBJZPGgGiiTvJEgTyxFvBO2nz0+X1G6etF8SzUODTlLY6Q==", + "dev": true, + "requires": { + "cli": "~1.0.0", + "console-browserify": "1.1.x", + "exit": "0.1.x", + "htmlparser2": "3.8.x", + "lodash": "~4.17.11", + "minimatch": "~3.0.2", + "shelljs": "0.3.x", + "strip-json-comments": "1.0.x" + } + }, + "kind-of": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", + "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", + "dev": true, + "requires": { + "is-buffer": "^1.1.5" + } + }, + "lazy-cache": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz", + "integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=", + "dev": true + }, + "lodash": { + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "dev": true + }, + "longest": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", + "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=", + "dev": true + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "repeat-string": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", + "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=", + "dev": true + }, + "right-align": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz", + "integrity": "sha1-YTObci/mo1FWiSENJOFMlhSGE+8=", + "dev": true, + "requires": { + "align-text": "^0.1.1" + } + }, + "shelljs": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz", + "integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=", + "dev": true + }, + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "dev": true + }, + "strip-json-comments": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-1.0.4.tgz", + "integrity": "sha1-HhX7ysl9Pumb8tc7TGVrCCu6+5E=", + "dev": true + }, + "uglify-js": { + "version": "2.8.29", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz", + "integrity": "sha1-KcVzMUgFe7Th913zW3qcty5qWd0=", + "dev": true, + "requires": { + "source-map": "~0.5.1", + "uglify-to-browserify": "~1.0.0", + "yargs": "~3.10.0" + } + }, + "uglify-to-browserify": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz", + "integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=", + "dev": true, + "optional": true + }, + "window-size": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz", + "integrity": "sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0=", + "dev": true + }, + "wordwrap": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz", + "integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8=", + "dev": true + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + }, + "yargs": { + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz", + "integrity": "sha1-9+572FfdfB0tOMDnTvvWgdFDH9E=", + "dev": true, + "requires": { + "camelcase": "^1.0.2", + "cliui": "^2.1.0", + "decamelize": "^1.0.0", + "window-size": "0.1.0" + } + } + } +} diff --git a/package.json b/package.json index 169e541..3b8a938 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spectragram", - "version": "1.1.1", + "version": "2.0.0", "description": "An easy jQuery plugin for Instagram API to fetch and display user, popular or tags photo feeds inside your web application or site.", "main": "spectragram.js", "files": [ diff --git a/spectragram.js b/spectragram.js index 2ccf5b0..7d32828 100644 --- a/spectragram.js +++ b/spectragram.js @@ -23,62 +23,50 @@ if ( typeof Object.create !== "function" ) { var Instagram = { - API_URL: "https://api.instagram.com/v1", - - // Initialize function + API_URL: "https://graph.instagram.com/me/media?fields=", + API_FIELDS: "caption,media_url,media_type,permalink,timestamp,username", + + /** + * Initializes the plugin. + * @param {object} options + * @param {jQuery Object} elem + */ initialize: function ( options, elem ) { this.elem = elem; this.$elem = $( elem ); this.accessToken = $.fn.spectragram.accessData.accessToken, this.options = $.extend( {}, $.fn.spectragram.options, options ); - this.endpoints = this.setEndpoints(); this.messages = { - defaultImageAltText: "Instagram Photo related with " + this.options.query, + defaultImageAltText: "Instagram Photo", notFound: "This user account is private or doesn't have any photos." }; - }, - // Set Endpoints - // Returns an object of endpoints to use on the app - setEndpoints: function () { - return { - usersSelf: "/users/self/?access_token=" + this.accessToken, - usersMediaRecent: "/users/self/media/recent/?&count=" + this.options.max + "&access_token=" + this.accessToken, - tagsMediaRecent: "/tags/" + this.options.query + "/media/recent?&count=" + this.options.max + "&access_token=" + this.accessToken - } + this.getPhotos(); }, - // Get Photos - // Call the fetch function and work with the response - getPhotos: function ( endpoint ) { + /** + * Calls the fetch function and work with the response. + */ + getPhotos: function () { var self = this; - self.fetch( endpoint ).done( function ( results ) { - var status = self.options.query || 'User'; - + self.fetch().done( function ( results ) { if ( results.data && results.data.length ) { - self.display( results ); + self.displayPhotos( results ); + } else if ( results.error.message ) { + $.error( "Spectragram.js - Error: " + results.error.message ); } else { - $.error( "Spectragram.js - Error: " + status + " does not have photos." ); + $.error( "Spectragram.js - Error: user does not have photos." ); } } ); }, - // Users - // Get the most recent media published by the owner of the access_token. - getUserFeed: function () { - this.getPhotos( this.endpoints.usersMediaRecent ); - }, - - // Tags - // Get a list of recently tagged media - getRecentTagged: function () { - $.error( "This endpoint has been retired" ); - }, - - fetch: function ( getData ) { - var getUrl = this.API_URL + getData; + /** + * Makes the ajax call and returns the result. + */ + fetch: function () { + var getUrl = this.API_URL + this.API_FIELDS + "&access_token=" + this.accessToken; return $.ajax( { type: "GET", @@ -88,60 +76,63 @@ if ( typeof Object.create !== "function" ) { } ); }, - display: function ( results ) { + /** + * Appends the markup to the DOM with the images. + * @param {object} results + */ + displayPhotos: function ( results ) { var $element, $image, - isWrapperEmpty, + hasCaption, + isWrapperEmpty, + isImage, imageGroup = [], imageCaption, - imageHeight, - imageWidth, max, - setSize, - size; + size; + + var sizeChart = { + "small": 160, + "medium": 320, + "large": 640 + }; isWrapperEmpty = $( this.options.wrapEachWith ).length === 0; + max = ( this.options.max >= results.data.length ) ? results.data.length : this.options.max; + size = sizeChart[this.options.size]; - if ( results.data === undefined || results.meta.code !== 200 || results.data.length === 0 ) { + if ( results.data === undefined || results.data.length === 0 ) { if ( isWrapperEmpty ) { this.$elem.append( this.messages.notFound ); } else { this.$elem.append( $( this.options.wrapEachWith ).append( this.messages.notFound ) ); - } - } else { - max = ( this.options.max >= results.data.length ) ? results.data.length : this.options.max; - setSize = this.options.size; - - for ( var i = 0; i < max; i++ ) { - if ( setSize === "small" ) { - size = results.data[i].images.thumbnail.url; - imageHeight = results.data[i].images.thumbnail.height; - imageWidth = results.data[i].images.thumbnail.width; - } else if ( setSize === "medium" ) { - size = results.data[i].images.low_resolution.url; - imageHeight = results.data[i].images.low_resolution.height; - imageWidth = results.data[i].images.low_resolution.width; - } else { - size = results.data[i].images.standard_resolution.url; - imageHeight = results.data[i].images.standard_resolution.height; - imageWidth = results.data[i].images.standard_resolution.width; - } + } + + return; + } + + for ( var i = 0; i < max; i++ ) { + + isImage = results.data[i].media_type === "IMAGE"; + + if (isImage) { + hasCaption = results.data[i].caption !== null || results.data[i].caption !== undefined; - imageCaption = ( results.data[i].caption !== null ) ? - $( "" ).text( results.data[i].caption.text ).html() : + imageCaption = ( hasCaption ) ? + $( "" ).text( results.data[i].caption ).html() : this.messages.defaultImageAltText; $image = $( "", { alt: imageCaption, attr: { - height: imageHeight, - width: imageWidth + height: size, + width: size }, - src: size + src: results.data[i].media_url } ); $element = $( "", { - href: results.data[i].link, + href: results.data[i].permalink, target: "_blank", title: imageCaption } ).append( $image ); @@ -151,10 +142,11 @@ if ( typeof Object.create !== "function" ) { } else { imageGroup.push( $( this.options.wrapEachWith ).append( $element ) ); } + } + } - this.$elem.append( imageGroup ); - } + this.$elem.append( imageGroup ); if ( typeof this.options.complete === "function" ) { this.options.complete.call( this ); @@ -162,19 +154,16 @@ if ( typeof Object.create !== "function" ) { } }; - jQuery.fn.spectragram = function ( method, options ) { + /** + * Spectragram Plugin Definition. + */ + jQuery.fn.spectragram = function ( options ) { if ( jQuery.fn.spectragram.accessData.accessToken ) { this.each( function () { var instagram = Object.create( Instagram ); instagram.initialize( options, this ); - - if ( instagram[method] ) { - return instagram[method]( this ); - } else { - $.error( "Method " + method + " does not exist on jQuery.spectragram" ); - } }); } else { @@ -182,16 +171,15 @@ if ( typeof Object.create !== "function" ) { } }; - // Plugin Default Options + // Plugin Default Options. jQuery.fn.spectragram.options = { complete : null, - max: 20, - query: "instagram", - size: "medium", + max: 25, + size: "large", wrapEachWith: "
  • " }; - // Instagram Access Data + // Instagram Access Data. jQuery.fn.spectragram.accessData = { accessToken: null }; diff --git a/spectragram.min.js b/spectragram.min.js index 220afb7..3d31ebd 100644 --- a/spectragram.min.js +++ b/spectragram.min.js @@ -1 +1 @@ -"function"!=typeof Object.create&&(Object.create=function(t){function e(){}return e.prototype=t,new e}),function(t,e,a,s){var i={API_URL:"https://api.instagram.com/v1",initialize:function(e,a){this.elem=a,this.$elem=t(a),this.accessToken=t.fn.spectragram.accessData.accessToken,this.options=t.extend({},t.fn.spectragram.options,e),this.endpoints=this.setEndpoints(),this.messages={defaultImageAltText:"Instagram Photo related with "+this.options.query,notFound:"This user account is private or doesn't have any photos."}},setEndpoints:function(){return{usersSelf:"/users/self/?access_token="+this.accessToken,usersMediaRecent:"/users/self/media/recent/?&count="+this.options.max+"&access_token="+this.accessToken,tagsMediaRecent:"/tags/"+this.options.query+"/media/recent?&count="+this.options.max+"&access_token="+this.accessToken}},getPhotos:function(e){var a=this;a.fetch(e).done(function(e){var s=a.options.query||"User";e.data&&e.data.length?a.display(e):t.error("Spectragram.js - Error: "+s+" does not have photos.")})},getUserFeed:function(){this.getPhotos(this.endpoints.usersMediaRecent)},getRecentTagged:function(){t.error("This endpoint has been retired")},fetch:function(e){var a=this.API_URL+e;return t.ajax({type:"GET",dataType:"jsonp",cache:!1,url:a})},display:function(e){var a,s,i,n,o,r,c,h,d,p=[];if(i=0===t(this.options.wrapEachWith).length,void 0===e.data||200!==e.meta.code||0===e.data.length)i?this.$elem.append(this.messages.notFound):this.$elem.append(t(this.options.wrapEachWith).append(this.messages.notFound));else{c=this.options.max>=e.data.length?e.data.length:this.options.max,h=this.options.size;for(var u=0;u").text(e.data[u].caption.text).html():this.messages.defaultImageAltText,s=t("",{alt:n,attr:{height:o,width:r},src:d}),a=t("
    ",{href:e.data[u].link,target:"_blank",title:n}).append(s),i?p.push(a):p.push(t(this.options.wrapEachWith).append(a));this.$elem.append(p)}"function"==typeof this.options.complete&&this.options.complete.call(this)}};jQuery.fn.spectragram=function(e,a){jQuery.fn.spectragram.accessData.accessToken?this.each(function(){var s=Object.create(i);if(s.initialize(a,this),s[e])return s[e](this);t.error("Method "+e+" does not exist on jQuery.spectragram")}):t.error("You must define an accessToken on jQuery.spectragram")},jQuery.fn.spectragram.options={complete:null,max:20,query:"instagram",size:"medium",wrapEachWith:"
  • "},jQuery.fn.spectragram.accessData={accessToken:null}}(jQuery,window,document); \ No newline at end of file +if(typeof Object.create!=="function"){Object.create=function(obj){function F(){}F.prototype=obj;return new F}}(function($,window,document,undefined){var Instagram={API_URL:"https://graph.instagram.com/me/media?fields=",API_FIELDS:"caption,media_url,media_type,permalink,timestamp,username",initialize:function(options,elem){this.elem=elem;this.$elem=$(elem);this.accessToken=$.fn.spectragram.accessData.accessToken,this.options=$.extend({},$.fn.spectragram.options,options);this.messages={defaultImageAltText:"Instagram Photo",notFound:"This user account is private or doesn't have any photos."};this.getPhotos()},getPhotos:function(){var self=this;self.fetch().done(function(results){if(results.data&&results.data.length){self.displayPhotos(results)}else if(results.error.message){$.error("Spectragram.js - Error: "+results.error.message)}else{$.error("Spectragram.js - Error: user does not have photos.")}})},fetch:function(){var getUrl=this.API_URL+this.API_FIELDS+"&access_token="+this.accessToken;return $.ajax({type:"GET",dataType:"jsonp",cache:false,url:getUrl})},displayPhotos:function(results){var $element,$image,hasCaption,isWrapperEmpty,isImage,imageGroup=[],imageCaption,max,size;var sizeChart={small:160,medium:320,large:640};isWrapperEmpty=$(this.options.wrapEachWith).length===0;max=this.options.max>=results.data.length?results.data.length:this.options.max;size=sizeChart[this.options.size];if(results.data===undefined||results.data.length===0){if(isWrapperEmpty){this.$elem.append(this.messages.notFound)}else{this.$elem.append($(this.options.wrapEachWith).append(this.messages.notFound))}return}for(var i=0;i").text(results.data[i].caption).html():this.messages.defaultImageAltText;$image=$("",{alt:imageCaption,attr:{height:size,width:size},src:results.data[i].media_url});$element=$("
    ",{href:results.data[i].permalink,target:"_blank",title:imageCaption}).append($image);if(isWrapperEmpty){imageGroup.push($element)}else{imageGroup.push($(this.options.wrapEachWith).append($element))}}}this.$elem.append(imageGroup);if(typeof this.options.complete==="function"){this.options.complete.call(this)}}};jQuery.fn.spectragram=function(options){if(jQuery.fn.spectragram.accessData.accessToken){this.each(function(){var instagram=Object.create(Instagram);instagram.initialize(options,this)})}else{$.error("You must define an accessToken on jQuery.spectragram")}};jQuery.fn.spectragram.options={complete:null,max:25,size:"large",wrapEachWith:"
  • "};jQuery.fn.spectragram.accessData={accessToken:null}})(jQuery,window,document); \ No newline at end of file