/ * E x t e r n a l A P I
=== === === === === === === === === === === === === === === === == * /
if ( typeof VMM != 'undefined' && typeof VMM . ExternalAPI == 'undefined' ) {
VMM . ExternalAPI = ( {
keys : {
google : "" ,
flickr : "" ,
twitter : ""
} ,
keys _master : {
vp : "Pellentesque nibh felis, eleifend id, commodo in, interdum vitae, leo" ,
flickr : "RAIvxHY4hE/Elm5cieh4X5ptMyDpj7MYIxziGxi0WGCcy1s+yr7rKQ==" ,
google : "jwNGnYw4hE9lmAez4ll0QD+jo6SKBJFknkopLS4FrSAuGfIwyj57AusuR0s8dAo=" ,
twitter : ""
} ,
init : function ( ) {
return this ;
} ,
setKeys : function ( d ) {
VMM . ExternalAPI . keys = d ;
} ,
pushQues : function ( ) {
if ( VMM . master _config . googlemaps . active ) {
VMM . ExternalAPI . googlemaps . pushQue ( ) ;
}
if ( VMM . master _config . youtube . active ) {
VMM . ExternalAPI . youtube . pushQue ( ) ;
}
if ( VMM . master _config . soundcloud . active ) {
VMM . ExternalAPI . soundcloud . pushQue ( ) ;
}
if ( VMM . master _config . googledocs . active ) {
VMM . ExternalAPI . googledocs . pushQue ( ) ;
}
if ( VMM . master _config . googleplus . active ) {
VMM . ExternalAPI . googleplus . pushQue ( ) ;
}
if ( VMM . master _config . wikipedia . active ) {
VMM . ExternalAPI . wikipedia . pushQue ( ) ;
}
if ( VMM . master _config . vimeo . active ) {
VMM . ExternalAPI . vimeo . pushQue ( ) ;
}
if ( VMM . master _config . vine . active ) {
VMM . ExternalAPI . vine . pushQue ( ) ;
}
if ( VMM . master _config . twitter . active ) {
VMM . ExternalAPI . twitter . pushQue ( ) ;
}
if ( VMM . master _config . flickr . active ) {
VMM . ExternalAPI . flickr . pushQue ( ) ;
}
if ( VMM . master _config . webthumb . active ) {
VMM . ExternalAPI . webthumb . pushQue ( ) ;
}
} ,
twitter : {
tweetArray : [ ] ,
get : function ( m ) {
var tweet = { mid : m . id , id : m . uid } ;
VMM . master _config . twitter . que . push ( tweet ) ;
VMM . master _config . twitter . active = true ;
//VMM.master_config.api.pushques.push(VMM.ExternalAPI.twitter.pushQue);
} ,
create : function ( tweet , callback ) {
var id = tweet . mid . toString ( ) ,
error _obj = { twitterid : tweet . mid } ,
the _url = "//api.twitter.com/1/statuses/show.json?id=" + tweet . mid + "&include_entities=true&callback=?" ;
//twitter_timeout = setTimeout(VMM.ExternalAPI.twitter.errorTimeOut, VMM.master_config.timers.api, tweet),
//callback_timeout= setTimeout(callback, VMM.master_config.timers.api, tweet);
VMM . ExternalAPI . twitter . getOEmbed ( tweet , callback ) ;
/ *
// Disabled thanks to twitter's new api
VMM . getJSON ( the _url , function ( d ) {
var id = d . id _str ,
twit = "<blockquote><p>" ,
td = VMM . Util . linkify _with _twitter ( d . text , "_blank" ) ;
// TWEET CONTENT
twit += td ;
twit += "</p></blockquote>" ;
// TWEET MEDIA
if ( typeof d . entities . media != 'undefined' ) {
if ( d . entities . media [ 0 ] . type == "photo" ) {
//twit += "<img src=' " + d.entities.media[0].media_url + "' alt=''>"
}
}
// TWEET AUTHOR
twit += "<div class='vcard author'>" ;
twit += "<a class='screen-name url' href='https://twitter.com/" + d . user . screen _name + "' data-screen-name='" + d . user . screen _name + "' target='_blank'>" ;
twit += "<span class='avatar'><img src=' " + d . user . profile _image _url + "' alt=''></span>" ;
twit += "<span class='fn'>" + d . user . name + "</span>" ;
twit += "<span class='nickname'>@" + d . user . screen _name + "<span class='thumbnail-inline'></span></span>" ;
twit += "</a>" ;
twit += "</div>" ;
VMM . attachElement ( "#" + tweet . id . toString ( ) , twit ) ;
VMM . attachElement ( "#text_thumb_" + tweet . id . toString ( ) , d . text ) ;
VMM . attachElement ( "#marker_content_" + tweet . id . toString ( ) , d . text ) ;
} )
. error ( function ( jqXHR , textStatus , errorThrown ) {
trace ( "TWITTER error" ) ;
trace ( "TWITTER ERROR: " + textStatus + " " + jqXHR . responseText ) ;
VMM . attachElement ( "#" + tweet . id , VMM . MediaElement . loadingmessage ( "ERROR LOADING TWEET " + tweet . mid ) ) ;
} )
. success ( function ( d ) {
clearTimeout ( twitter _timeout ) ;
clearTimeout ( callback _timeout ) ;
callback ( ) ;
} ) ;
* /
} ,
errorTimeOut : function ( tweet ) {
trace ( "TWITTER JSON ERROR TIMEOUT " + tweet . mid ) ;
VMM . attachElement ( "#" + tweet . id . toString ( ) , VMM . MediaElement . loadingmessage ( "Still waiting on Twitter: " + tweet . mid ) ) ;
// CHECK RATE STATUS
VMM . getJSON ( "//api.twitter.com/1/account/rate_limit_status.json" , function ( d ) {
trace ( "REMAINING TWITTER API CALLS " + d . remaining _hits ) ;
trace ( "TWITTER RATE LIMIT WILL RESET AT " + d . reset _time ) ;
var mes = "" ;
if ( d . remaining _hits == 0 ) {
mes = "<p>You've reached the maximum number of tweets you can load in an hour.</p>" ;
mes += "<p>You can view tweets again starting at: <br/>" + d . reset _time + "</p>" ;
} else {
mes = "<p>Still waiting on Twitter. " + tweet . mid + "</p>" ;
//mes = "<p>Tweet " + id + " was not found.</p>";
}
VMM . attachElement ( "#" + tweet . id . toString ( ) , VMM . MediaElement . loadingmessage ( mes ) ) ;
} ) ;
} ,
errorTimeOutOembed : function ( tweet ) {
trace ( "TWITTER JSON ERROR TIMEOUT " + tweet . mid ) ;
VMM . attachElement ( "#" + tweet . id . toString ( ) , VMM . MediaElement . loadingmessage ( "Still waiting on Twitter: " + tweet . mid ) ) ;
} ,
pushQue : function ( ) {
if ( VMM . master _config . twitter . que . length > 0 ) {
VMM . ExternalAPI . twitter . create ( VMM . master _config . twitter . que [ 0 ] , VMM . ExternalAPI . twitter . pushQue ) ;
VMM . Util . removeRange ( VMM . master _config . twitter . que , 0 ) ;
}
} ,
getOEmbed : function ( tweet , callback ) {
var the _url = "https://api.twitter.com/1/statuses/oembed.json?id=" + tweet . mid + "&omit_script=true&include_entities=true&callback=?" ,
twitter _timeout = setTimeout ( VMM . ExternalAPI . twitter . errorTimeOutOembed , VMM . master _config . timers . api , tweet ) ;
//callback_timeout= setTimeout(callback, VMM.master_config.timers.api, tweet);
VMM . getJSON ( the _url , function ( d ) {
var twit = "" ,
tuser = "" ;
// TWEET CONTENT
twit += d . html . split ( "<\/p>\—" ) [ 0 ] + "</p></blockquote>" ;
tuser = d . author _url . split ( "twitter.com\/" ) [ 1 ] ;
// TWEET AUTHOR
twit += "<div class='vcard author'>" ;
twit += "<a class='screen-name url' href='" + d . author _url + "' target='_blank'>" ;
twit += "<span class='avatar'></span>" ;
twit += "<span class='fn'>" + d . author _name + "</span>" ;
twit += "<span class='nickname'>@" + tuser + "<span class='thumbnail-inline'></span></span>" ;
twit += "</a>" ;
twit += "</div>" ;
VMM . attachElement ( "#" + tweet . id . toString ( ) , twit ) ;
VMM . attachElement ( "#text_thumb_" + tweet . id . toString ( ) , d . html ) ;
VMM . attachElement ( "#marker_content_" + tweet . id . toString ( ) , d . html ) ;
} )
. error ( function ( jqXHR , textStatus , errorThrown ) {
trace ( "TWITTER error" ) ;
trace ( "TWITTER ERROR: " + textStatus + " " + jqXHR . responseText ) ;
clearTimeout ( twitter _timeout ) ;
//clearTimeout(callback_timeout);
VMM . attachElement ( "#" + tweet . id , VMM . MediaElement . loadingmessage ( "ERROR LOADING TWEET " + tweet . mid ) ) ;
} )
. success ( function ( d ) {
clearTimeout ( twitter _timeout ) ;
// clearTimeout(callback_timeout);
callback ( ) ;
} ) ;
} ,
getHTML : function ( id ) {
//var the_url = document.location.protocol + "//api.twitter.com/1/statuses/oembed.json?id=" + id+ "&callback=?";
var the _url = "https://api.twitter.com/1/statuses/oembed.json?id=" + id + "&omit_script=true&include_entities=true&callback=?" ;
VMM . getJSON ( the _url , VMM . ExternalAPI . twitter . onJSONLoaded ) ;
} ,
onJSONLoaded : function ( d ) {
trace ( "TWITTER JSON LOADED" ) ;
var id = d . id ;
VMM . attachElement ( "#" + id , VMM . Util . linkify _with _twitter ( d . html ) ) ;
} ,
parseTwitterDate : function ( d ) {
var date = new Date ( Date . parse ( d ) ) ;
/ *
var t = d . replace ( /(\d{1,2}[:]\d{2}[:]\d{2}) (.*)/ , '$2 $1' ) ;
t = t . replace ( /(\+\S+) (.*)/ , '$2 $1' ) ;
var date = new Date ( Date . parse ( t ) ) . toLocaleDateString ( ) ;
var time = new Date ( Date . parse ( t ) ) . toLocaleTimeString ( ) ;
* /
return date ;
} ,
prettyParseTwitterDate : function ( d ) {
var date = new Date ( Date . parse ( d ) ) ;
return VMM . Date . prettyDate ( date , true ) ;
} ,
getTweets : function ( tweets ) {
var tweetArray = [ ] ;
var number _of _tweets = tweets . length ;
for ( var i = 0 ; i < tweets . length ; i ++ ) {
var twitter _id = "" ;
/ * F I N D T H E T W I T T E R I D
=== === === === === === === === === === === === === === === === == * /
if ( tweets [ i ] . tweet . match ( "status\/" ) ) {
twitter _id = tweets [ i ] . tweet . split ( "status\/" ) [ 1 ] ;
} else if ( tweets [ i ] . tweet . match ( "statuses\/" ) ) {
twitter _id = tweets [ i ] . tweet . split ( "statuses\/" ) [ 1 ] ;
} else {
twitter _id = "" ;
}
/ * F E T C H T H E D A T A
=== === === === === === === === === === === === === === === === == * /
var the _url = "//api.twitter.com/1/statuses/show.json?id=" + twitter _id + "&include_entities=true&callback=?" ;
VMM . getJSON ( the _url , function ( d ) {
var tweet = { }
/ * F O R M A T R E S P O N S E
=== === === === === === === === === === === === === === === === == * /
var twit = "<div class='twitter'><blockquote><p>" ;
var td = VMM . Util . linkify _with _twitter ( d . text , "_blank" ) ;
twit += td ;
twit += "</p>" ;
twit += "— " + d . user . name + " (<a href='https://twitter.com/" + d . user . screen _name + "'>@" + d . user . screen _name + "</a>) <a href='https://twitter.com/" + d . user . screen _name + "/status/" + d . id + "'>" + VMM . ExternalAPI . twitter . prettyParseTwitterDate ( d . created _at ) + " </a></blockquote></div>" ;
tweet . content = twit ;
tweet . raw = d ;
tweetArray . push ( tweet ) ;
/ * C H E C K I F T H A T S A L L O F T H E M
=== === === === === === === === === === === === === === === === == * /
if ( tweetArray . length == number _of _tweets ) {
var the _tweets = { tweetdata : tweetArray }
VMM . fireEvent ( global , "TWEETSLOADED" , the _tweets ) ;
}
} )
. success ( function ( ) { trace ( "second success" ) ; } )
. error ( function ( ) { trace ( "error" ) ; } )
. complete ( function ( ) { trace ( "complete" ) ; } ) ;
}
} ,
getTweetSearch : function ( tweets , number _of _tweets ) {
var _number _of _tweets = 40 ;
if ( number _of _tweets != null && number _of _tweets != "" ) {
_number _of _tweets = number _of _tweets ;
}
var the _url = "//search.twitter.com/search.json?q=" + tweets + "&rpp=" + _number _of _tweets + "&include_entities=true&result_type=mixed" ;
var tweetArray = [ ] ;
VMM . getJSON ( the _url , function ( d ) {
/ * F O R M A T R E S P O N S E
=== === === === === === === === === === === === === === === === == * /
for ( var i = 0 ; i < d . results . length ; i ++ ) {
var tweet = { }
var twit = "<div class='twitter'><blockquote><p>" ;
var td = VMM . Util . linkify _with _twitter ( d . results [ i ] . text , "_blank" ) ;
twit += td ;
twit += "</p>" ;
twit += "— " + d . results [ i ] . from _user _name + " (<a href='https://twitter.com/" + d . results [ i ] . from _user + "'>@" + d . results [ i ] . from _user + "</a>) <a href='https://twitter.com/" + d . results [ i ] . from _user + "/status/" + d . id + "'>" + VMM . ExternalAPI . twitter . prettyParseTwitterDate ( d . results [ i ] . created _at ) + " </a></blockquote></div>" ;
tweet . content = twit ;
tweet . raw = d . results [ i ] ;
tweetArray . push ( tweet ) ;
}
var the _tweets = { tweetdata : tweetArray }
VMM . fireEvent ( global , "TWEETSLOADED" , the _tweets ) ;
} ) ;
} ,
prettyHTML : function ( id , secondary ) {
var id = id . toString ( ) ;
var error _obj = {
twitterid : id
} ;
var the _url = "//api.twitter.com/1/statuses/show.json?id=" + id + "&include_entities=true&callback=?" ;
var twitter _timeout = setTimeout ( VMM . ExternalAPI . twitter . errorTimeOut , VMM . master _config . timers . api , id ) ;
VMM . getJSON ( the _url , VMM . ExternalAPI . twitter . formatJSON )
. error ( function ( jqXHR , textStatus , errorThrown ) {
trace ( "TWITTER error" ) ;
trace ( "TWITTER ERROR: " + textStatus + " " + jqXHR . responseText ) ;
VMM . attachElement ( "#twitter_" + id , "<p>ERROR LOADING TWEET " + id + "</p>" ) ;
} )
. success ( function ( d ) {
clearTimeout ( twitter _timeout ) ;
if ( secondary ) {
VMM . ExternalAPI . twitter . secondaryMedia ( d ) ;
}
} ) ;
} ,
formatJSON : function ( d ) {
var id = d . id _str ;
var twit = "<blockquote><p>" ;
var td = VMM . Util . linkify _with _twitter ( d . text , "_blank" ) ;
//td = td.replace(/(@([\w]+))/g,"<a href='http://twitter.com/$2' target='_blank'>$1</a>");
//td = td.replace(/(#([\w]+))/g,"<a href='http://twitter.com/#search?q=%23$2' target='_blank'>$1</a>");
twit += td ;
twit += "</p></blockquote>" ;
//twit += " <a href='https://twitter.com/" + d.user.screen_name + "/status/" + d.id_str + "' target='_blank' alt='link to original tweet' title='link to original tweet'>" + "<span class='created-at'></span>" + " </a>";
twit += "<div class='vcard author'>" ;
twit += "<a class='screen-name url' href='https://twitter.com/" + d . user . screen _name + "' data-screen-name='" + d . user . screen _name + "' target='_blank'>" ;
twit += "<span class='avatar'><img src=' " + d . user . profile _image _url + "' alt=''></span>" ;
twit += "<span class='fn'>" + d . user . name + "</span>" ;
twit += "<span class='nickname'>@" + d . user . screen _name + "<span class='thumbnail-inline'></span></span>" ;
twit += "</a>" ;
twit += "</div>" ;
if ( typeof d . entities . media != 'undefined' ) {
if ( d . entities . media [ 0 ] . type == "photo" ) {
twit += "<img src=' " + d . entities . media [ 0 ] . media _url + "' alt=''>"
}
}
VMM . attachElement ( "#twitter_" + id . toString ( ) , twit ) ;
VMM . attachElement ( "#text_thumb_" + id . toString ( ) , d . text ) ;
}
} ,
googlemaps : {
maptype : "TERRAIN" , // see also below for default if this is a google type
setMapType : function ( d ) {
if ( d != "" ) {
VMM . ExternalAPI . googlemaps . maptype = d ;
}
} ,
get : function ( m ) {
var timer ,
api _key ,
map _url ;
m . vars = VMM . Util . getUrlVars ( m . id ) ;
if ( VMM . ExternalAPI . keys . google != "" ) {
api _key = VMM . ExternalAPI . keys . google ;
} else {
api _key = Aes . Ctr . decrypt ( VMM . ExternalAPI . keys _master . google , VMM . ExternalAPI . keys _master . vp , 256 ) ;
}
/ *
Investigating a google map api change on the latest release that causes custom map types to stop working
http : //stackoverflow.com/questions/13486271/google-map-markermanager-cannot-call-method-substr-of-undefined
soulution is to use api ver 3.9
* /
map _url = "//maps.googleapis.com/maps/api/js?key=" + api _key + "&v=3.9&libraries=places&sensor=false&callback=VMM.ExternalAPI.googlemaps.onMapAPIReady" ;
if ( VMM . master _config . googlemaps . active ) {
VMM . master _config . googlemaps . que . push ( m ) ;
} else {
VMM . master _config . googlemaps . que . push ( m ) ;
if ( VMM . master _config . googlemaps . api _loaded ) {
} else {
LoadLib . js ( map _url , function ( ) {
trace ( "Google Maps API Library Loaded" ) ;
} ) ;
}
}
} ,
create : function ( m ) {
VMM . ExternalAPI . googlemaps . createAPIMap ( m ) ;
} ,
createiFrameMap : function ( m ) {
var embed _url = m . id + "&output=embed" ,
mc = "" ,
unique _map _id = m . uid . toString ( ) + "_gmap" ;
mc += "<div class='google-map' id='" + unique _map _id + "' style='width=100%;height=100%;'>" ;
mc += "<iframe width='100%' height='100%' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='" + embed _url + "'></iframe>" ;
mc += "</div>" ;
VMM . attachElement ( "#" + m . uid , mc ) ;
} ,
createAPIMap : function ( m ) {
var map _attribution = "" ,
layer ,
map ,
map _options ,
unique _map _id = m . uid . toString ( ) + "_gmap" ,
map _attribution _html = "" ,
location = new google . maps . LatLng ( 41.875696 , - 87.624207 ) ,
latlong ,
zoom = 11 ,
has _location = false ,
has _zoom = false ,
api _limit = false ,
map _bounds ;
function mapProvider ( name ) {
if ( name in VMM . ExternalAPI . googlemaps . map _providers ) {
map _attribution = VMM . ExternalAPI . googlemaps . map _attribution [ VMM . ExternalAPI . googlemaps . map _providers [ name ] . attribution ] ;
return VMM . ExternalAPI . googlemaps . map _providers [ name ] ;
} else {
if ( VMM . ExternalAPI . googlemaps . defaultType ( name ) ) {
trace ( "GOOGLE MAP DEFAULT TYPE" ) ;
return google . maps . MapTypeId [ name . toUpperCase ( ) ] ;
} else {
trace ( "Not a maptype: " + name ) ;
}
}
}
google . maps . VeriteMapType = function ( name ) {
if ( VMM . ExternalAPI . googlemaps . defaultType ( name ) ) {
return google . maps . MapTypeId [ name . toUpperCase ( ) ] ;
} else {
var provider = mapProvider ( name ) ;
return google . maps . ImageMapType . call ( this , {
"getTileUrl" : function ( coord , zoom ) {
var index = ( zoom + coord . x + coord . y ) % VMM . ExternalAPI . googlemaps . map _subdomains . length ;
var retURL = provider . url
. replace ( "{S}" , VMM . ExternalAPI . googlemaps . map _subdomains [ index ] )
. replace ( "{Z}" , zoom )
. replace ( "{X}" , coord . x )
. replace ( "{Y}" , coord . y )
. replace ( "{z}" , zoom )
. replace ( "{x}" , coord . x )
. replace ( "{y}" , coord . y ) ;
// trace(retURL);
return retURL ;
} ,
"tileSize" : new google . maps . Size ( 256 , 256 ) ,
"name" : name ,
"minZoom" : provider . minZoom ,
"maxZoom" : provider . maxZoom
} ) ;
}
} ;
google . maps . VeriteMapType . prototype = new google . maps . ImageMapType ( "_" ) ;
/ * M a k e t h e M a p
=== === === === === === === === === === === === === === === === == * /
if ( VMM . ExternalAPI . googlemaps . maptype != "" ) {
if ( VMM . ExternalAPI . googlemaps . defaultType ( VMM . ExternalAPI . googlemaps . maptype ) ) {
layer = google . maps . MapTypeId [ VMM . ExternalAPI . googlemaps . maptype . toUpperCase ( ) ] ;
} else {
layer = VMM . ExternalAPI . googlemaps . maptype ;
}
} else {
layer = google . maps . MapTypeId [ 'TERRAIN' ] ;
}
var new _google _url _regex = new RegExp ( /@([0-9\.\-]+),([0-9\.\-]+),(\d+)z/ ) ;
if ( m . id . match ( new _google _url _regex ) ) {
var match = m . id . match ( new _google _url _regex )
lat = parseFloat ( match [ 1 ] ) ;
lng = parseFloat ( match [ 2 ] ) ;
location = new google . maps . LatLng ( lat , lng ) ;
zoom = parseFloat ( match [ 3 ] ) ;
has _location = has _zoom = true ;
} else {
if ( type . of ( VMM . Util . getUrlVars ( m . id ) [ "ll" ] ) == "string" ) {
has _location = true ;
latlong = VMM . Util . getUrlVars ( m . id ) [ "ll" ] . split ( "," ) ;
location = new google . maps . LatLng ( parseFloat ( latlong [ 0 ] ) , parseFloat ( latlong [ 1 ] ) ) ;
} else if ( type . of ( VMM . Util . getUrlVars ( m . id ) [ "sll" ] ) == "string" ) {
latlong = VMM . Util . getUrlVars ( m . id ) [ "sll" ] . split ( "," ) ;
location = new google . maps . LatLng ( parseFloat ( latlong [ 0 ] ) , parseFloat ( latlong [ 1 ] ) ) ;
}
if ( type . of ( VMM . Util . getUrlVars ( m . id ) [ "z" ] ) == "string" ) {
has _zoom = true ;
zoom = parseFloat ( VMM . Util . getUrlVars ( m . id ) [ "z" ] ) ;
}
}
map _options = {
zoom : zoom ,
draggable : false ,
disableDefaultUI : true ,
mapTypeControl : false ,
zoomControl : true ,
zoomControlOptions : {
style : google . maps . ZoomControlStyle . SMALL ,
position : google . maps . ControlPosition . TOP _RIGHT
} ,
center : location ,
mapTypeId : layer ,
mapTypeControlOptions : {
mapTypeIds : [ layer ]
}
}
VMM . attachElement ( "#" + m . uid , "<div class='google-map' id='" + unique _map _id + "' style='width=100%;height=100%;'></div>" ) ;
map = new google . maps . Map ( document . getElementById ( unique _map _id ) , map _options ) ;
if ( VMM . ExternalAPI . googlemaps . defaultType ( VMM . ExternalAPI . googlemaps . maptype ) ) {
} else {
map . mapTypes . set ( layer , new google . maps . VeriteMapType ( layer ) ) ;
// ATTRIBUTION
map _attribution _html = "<div class='map-attribution'><div class='attribution-text'>" + map _attribution + "</div></div>" ;
VMM . appendElement ( "#" + unique _map _id , map _attribution _html ) ;
}
// DETERMINE IF KML IS POSSIBLE
if ( type . of ( VMM . Util . getUrlVars ( m . id ) [ "msid" ] ) == "string" ) {
loadKML ( ) ;
} else {
//loadPlaces();
if ( type . of ( VMM . Util . getUrlVars ( m . id ) [ "q" ] ) == "string" ) {
geocodePlace ( ) ;
}
}
// GEOCODE
function geocodePlace ( ) {
var geocoder = new google . maps . Geocoder ( ) ,
address = VMM . Util . getUrlVars ( m . id ) [ "q" ] ,
marker ;
if ( address . match ( "loc:" ) ) {
var address _latlon = address . split ( ":" ) [ 1 ] . split ( "+" ) ;
location = new google . maps . LatLng ( parseFloat ( address _latlon [ 0 ] ) , parseFloat ( address _latlon [ 1 ] ) ) ;
has _location = true ;
}
geocoder . geocode ( { 'address' : address } , function ( results , status ) {
if ( status == google . maps . GeocoderStatus . OK ) {
marker = new google . maps . Marker ( {
map : map ,
position : results [ 0 ] . geometry . location
} ) ;
// POSITION MAP
//map.setCenter(results[0].geometry.location);
//map.panTo(location);
if ( typeof results [ 0 ] . geometry . viewport != 'undefined' ) {
map . fitBounds ( results [ 0 ] . geometry . viewport ) ;
} else if ( typeof results [ 0 ] . geometry . bounds != 'undefined' ) {
map . fitBounds ( results [ 0 ] . geometry . bounds ) ;
} else {
map . setCenter ( results [ 0 ] . geometry . location ) ;
}
if ( has _location ) {
map . panTo ( location ) ;
}
if ( has _zoom ) {
map . setZoom ( zoom ) ;
}
} else {
trace ( "Geocode for " + address + " was not successful for the following reason: " + status ) ;
trace ( "TRYING PLACES SEARCH" ) ;
if ( has _location ) {
map . panTo ( location ) ;
}
if ( has _zoom ) {
map . setZoom ( zoom ) ;
}
loadPlaces ( ) ;
}
} ) ;
}
// PLACES
function loadPlaces ( ) {
var place ,
search _request ,
infowindow ,
search _bounds ,
bounds _sw ,
bounds _ne ;
place _search = new google . maps . places . PlacesService ( map ) ;
infowindow = new google . maps . InfoWindow ( ) ;
search _request = {
query : "" ,
types : [ 'country' , 'neighborhood' , 'political' , 'locality' , 'geocode' ]
} ;
if ( type . of ( VMM . Util . getUrlVars ( m . id ) [ "q" ] ) == "string" ) {
search _request . query = VMM . Util . getUrlVars ( m . id ) [ "q" ] ;
}
if ( has _location ) {
search _request . location = location ;
search _request . radius = "15000" ;
} else {
bounds _sw = new google . maps . LatLng ( - 89.999999 , - 179.999999 ) ;
bounds _ne = new google . maps . LatLng ( 89.999999 , 179.999999 ) ;
search _bounds = new google . maps . LatLngBounds ( bounds _sw , bounds _ne ) ;
//search_request.location = search_bounds;
}
place _search . textSearch ( search _request , placeResults ) ;
function placeResults ( results , status ) {
if ( status == google . maps . places . PlacesServiceStatus . OK ) {
for ( var i = 0 ; i < results . length ; i ++ ) {
//createMarker(results[i]);
}
if ( has _location ) {
map . panTo ( location ) ;
} else {
if ( results . length >= 1 ) {
map . panTo ( results [ 0 ] . geometry . location ) ;
if ( has _zoom ) {
map . setZoom ( zoom ) ;
}
}
}
} else {
trace ( "Place search for " + search _request . query + " was not successful for the following reason: " + status ) ;
// IF There's a problem loading the map, load a simple iFrame version instead
trace ( "YOU MAY NEED A GOOGLE MAPS API KEY IN ORDER TO USE THIS FEATURE OF TIMELINEJS" ) ;
trace ( "FIND OUT HOW TO GET YOUR KEY HERE: https://developers.google.com/places/documentation/#Authentication" ) ;
if ( has _location ) {
map . panTo ( location ) ;
if ( has _zoom ) {
map . setZoom ( zoom ) ;
}
} else {
trace ( "USING SIMPLE IFRAME MAP EMBED" ) ;
if ( m . id [ 0 ] . match ( "https" ) ) {
m . id = m . url [ 0 ] . replace ( "https" , "http" ) ;
}
VMM . ExternalAPI . googlemaps . createiFrameMap ( m ) ;
}
}
}
function createMarker ( place ) {
var marker , placeLoc ;
placeLoc = place . geometry . location ;
marker = new google . maps . Marker ( {
map : map ,
position : place . geometry . location
} ) ;
google . maps . event . addListener ( marker , 'click' , function ( ) {
infowindow . setContent ( place . name ) ;
infowindow . open ( map , this ) ;
} ) ;
}
}
function loadPlacesAlt ( ) {
var api _key ,
places _url ,
has _key = false ;
trace ( "LOADING PLACES API FOR GOOGLE MAPS" ) ;
if ( VMM . ExternalAPI . keys . google != "" ) {
api _key = VMM . ExternalAPI . keys . google ;
has _key = true ;
} else {
trace ( "YOU NEED A GOOGLE MAPS API KEY IN ORDER TO USE THIS FEATURE OF TIMELINEJS" ) ;
trace ( "FIND OUT HOW TO GET YOUR KEY HERE: https://developers.google.com/places/documentation/#Authentication" ) ;
}
places _url = "https://maps.googleapis.com/maps/api/place/textsearch/json?key=" + api _key + "&sensor=false&language=" + m . lang + "&" ;
if ( type . of ( VMM . Util . getUrlVars ( m . id ) [ "q" ] ) == "string" ) {
places _url += "query=" + VMM . Util . getUrlVars ( m . id ) [ "q" ] ;
}
if ( has _location ) {
places _url += "&location=" + location ;
}
if ( has _key ) {
VMM . getJSON ( places _url , function ( d ) {
trace ( "PLACES JSON" ) ;
var places _location = "" ,
places _bounds = "" ,
places _bounds _ne = "" ,
places _bounds _sw = "" ;
trace ( d ) ;
if ( d . status == "OVER_QUERY_LIMIT" ) {
trace ( "OVER_QUERY_LIMIT" ) ;
if ( has _location ) {
map . panTo ( location ) ;
if ( has _zoom ) {
map . setZoom ( zoom ) ;
}
} else {
trace ( "DOING TRADITIONAL MAP IFRAME EMBED UNTIL QUERY LIMIT RESTORED" ) ;
api _limit = true ;
VMM . ExternalAPI . googlemaps . createiFrameMap ( m ) ;
}
} else {
if ( d . results . length >= 1 ) {
//location = new google.maps.LatLng(parseFloat(d.results[0].geometry.location.lat),parseFloat(d.results[0].geometry.location.lng));
//map.panTo(location);
places _bounds _ne = new google . maps . LatLng ( parseFloat ( d . results [ 0 ] . geometry . viewport . northeast . lat ) , parseFloat ( d . results [ 0 ] . geometry . viewport . northeast . lng ) ) ;
places _bounds _sw = new google . maps . LatLng ( parseFloat ( d . results [ 0 ] . geometry . viewport . southwest . lat ) , parseFloat ( d . results [ 0 ] . geometry . viewport . southwest . lng ) ) ;
places _bounds = new google . maps . LatLngBounds ( places _bounds _sw , places _bounds _ne )
map . fitBounds ( places _bounds ) ;
} else {
trace ( "NO RESULTS" ) ;
}
if ( has _location ) {
map . panTo ( location ) ;
}
if ( has _zoom ) {
map . setZoom ( zoom ) ;
}
}
} )
. error ( function ( jqXHR , textStatus , errorThrown ) {
trace ( "PLACES JSON ERROR" ) ;
trace ( "PLACES JSON ERROR: " + textStatus + " " + jqXHR . responseText ) ;
} )
. success ( function ( d ) {
trace ( "PLACES JSON SUCCESS" ) ;
} ) ;
} else {
if ( has _location ) {
map . panTo ( location ) ;
if ( has _zoom ) {
map . setZoom ( zoom ) ;
}
} else {
trace ( "DOING TRADITIONAL MAP IFRAME EMBED BECAUSE NO GOOGLE MAP API KEY WAS PROVIDED" ) ;
VMM . ExternalAPI . googlemaps . createiFrameMap ( m ) ;
}
}
}
// KML
function loadKML ( ) {
var kml _url , kml _layer , infowindow , text ;
kml _url = m . id + "&output=kml" ;
kml _url = kml _url . replace ( "&output=embed" , "" ) ;
kml _layer = new google . maps . KmlLayer ( kml _url , { preserveViewport : true } ) ;
infowindow = new google . maps . InfoWindow ( ) ;
kml _layer . setMap ( map ) ;
google . maps . event . addListenerOnce ( kml _layer , "defaultviewport_changed" , function ( ) {
if ( has _location ) {
map . panTo ( location ) ;
} else {
map . fitBounds ( kml _layer . getDefaultViewport ( ) ) ;
}
if ( has _zoom ) {
map . setZoom ( zoom ) ;
}
} ) ;
google . maps . event . addListener ( kml _layer , 'click' , function ( kmlEvent ) {
text = kmlEvent . featureData . description ;
showInfoWindow ( text ) ;
function showInfoWindow ( c ) {
infowindow . setContent ( c ) ;
infowindow . open ( map ) ;
}
} ) ;
}
} ,
pushQue : function ( ) {
for ( var i = 0 ; i < VMM . master _config . googlemaps . que . length ; i ++ ) {
VMM . ExternalAPI . googlemaps . create ( VMM . master _config . googlemaps . que [ i ] ) ;
}
VMM . master _config . googlemaps . que = [ ] ;
} ,
onMapAPIReady : function ( ) {
VMM . master _config . googlemaps . map _active = true ;
VMM . master _config . googlemaps . places _active = true ;
VMM . ExternalAPI . googlemaps . onAPIReady ( ) ;
} ,
onPlacesAPIReady : function ( ) {
VMM . master _config . googlemaps . places _active = true ;
VMM . ExternalAPI . googlemaps . onAPIReady ( ) ;
} ,
onAPIReady : function ( ) {
if ( ! VMM . master _config . googlemaps . active ) {
if ( VMM . master _config . googlemaps . map _active && VMM . master _config . googlemaps . places _active ) {
VMM . master _config . googlemaps . active = true ;
VMM . ExternalAPI . googlemaps . pushQue ( ) ;
}
}
} ,
defaultType : function ( name ) {
if ( name . toLowerCase ( ) == "satellite" || name . toLowerCase ( ) == "hybrid" || name . toLowerCase ( ) == "terrain" || name . toLowerCase ( ) == "roadmap" ) {
return true ;
} else {
return false ;
}
} ,
map _subdomains : [ "a" , "b" , "c" , "d" ] ,
map _attribution : {
"stamen" : "Map tiles by <a href='http://stamen.com'>Stamen Design</a>, under <a href='http://creativecommons.org/licenses/by/3.0'>CC BY 3.0</a>. Data by <a href='http://openstreetmap.org'>OpenStreetMap</a>, under <a href='http://creativecommons.org/licenses/by-sa/3.0'>CC BY SA</a>." ,
"apple" : "Map data © 2012 Apple, Imagery © 2012 Apple" ,
"osm" : "© <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors"
} ,
map _providers : {
"toner" : {
"url" : "https://stamen-tiles-{S}.a.ssl.fastly.net/toner/{Z}/{X}/{Y}.png" ,
"minZoom" : 0 ,
"maxZoom" : 20 ,
"attribution" : "stamen"
} ,
"toner-lines" : {
"url" : "https://stamen-tiles-{S}.a.ssl.fastly.net/toner-lines/{Z}/{X}/{Y}.png" ,
"minZoom" : 0 ,
"maxZoom" : 20 ,
"attribution" : "stamen"
} ,
"toner-labels" : {
"url" : "https://stamen-tiles-{S}.a.ssl.fastly.net/toner-labels/{Z}/{X}/{Y}.png" ,
"minZoom" : 0 ,
"maxZoom" : 20 ,
"attribution" : "stamen"
} ,
"sterrain" : {
"url" : "https://stamen-tiles-{S}.a.ssl.fastly.net/terrain/{Z}/{X}/{Y}.jpg" ,
"minZoom" : 4 ,
"maxZoom" : 20 ,
"attribution" : "stamen"
} ,
"apple" : {
"url" : "//gsp2.apple.com/tile?api=1&style=slideshow&layers=default&lang=en_US&z={z}&x={x}&y={y}&v=9" ,
"minZoom" : 4 ,
"maxZoom" : 14 ,
"attribution" : "apple"
} ,
"watercolor" : {
"url" : "https://stamen-tiles-{S}.a.ssl.fastly.net/watercolor/{Z}/{X}/{Y}.jpg" ,
"minZoom" : 3 ,
"maxZoom" : 16 ,
"attribution" : "stamen"
} ,
"osm" : {
"url" : "//tile.openstreetmap.org/{z}/{x}/{y}.png" ,
"minZoom" : 3 ,
"maxZoom" : 18 ,
"attribution" : "osm"
}
}
} ,
googleplus : {
get : function ( m ) {
var api _key ;
var gplus = { user : m . user , activity : m . id , id : m . uid } ;
VMM . master _config . googleplus . que . push ( gplus ) ;
VMM . master _config . googleplus . active = true ;
} ,
create : function ( gplus , callback ) {
var mediaElem = "" ,
api _key = "" ,
g _activity = "" ,
g _content = "" ,
g _attachments = "" ,
gperson _api _url ,
gactivity _api _url ;
googleplus _timeout = setTimeout ( VMM . ExternalAPI . googleplus . errorTimeOut , VMM . master _config . timers . api , gplus ) ,
callback _timeout = setTimeout ( callback , VMM . master _config . timers . api , gplus ) ;
if ( VMM . master _config . Timeline . api _keys . google != "" ) {
api _key = VMM . master _config . Timeline . api _keys . google ;
} else {
api _key = Aes . Ctr . decrypt ( VMM . master _config . api _keys _master . google , VMM . master _config . vp , 256 ) ;
}
gperson _api _url = "https://www.googleapis.com/plus/v1/people/" + gplus . user + "/activities/public?alt=json&maxResults=100&fields=items(id,url)&key=" + api _key ;
//mediaElem = "<iframe class='doc' frameborder='0' width='100%' height='100%' src='" + gplus.url + "&embedded=true'></iframe>";
mediaElem = "GOOGLE PLUS API CALL" ;
VMM . getJSON ( gperson _api _url , function ( p _data ) {
for ( var i = 0 ; i < p _data . items . length ; i ++ ) {
trace ( "loop" ) ;
if ( p _data . items [ i ] . url . split ( "posts/" ) [ 1 ] == gplus . activity ) {
trace ( "FOUND IT!!" ) ;
g _activity = p _data . items [ i ] . id ;
gactivity _api _url = "https://www.googleapis.com/plus/v1/activities/" + g _activity + "?alt=json&key=" + api _key ;
VMM . getJSON ( gactivity _api _url , function ( a _data ) {
trace ( a _data ) ;
//a_data.url
//a_data.image.url
//a_data.actor.displayName
//a_data.provider.title
//a_data.object.content
//g_content += "<h4>" + a_data.title + "</h4>";
if ( typeof a _data . annotation != 'undefined' ) {
g _content += "<div class='googleplus-annotation'>'" + a _data . annotation + "</div>" ;
g _content += a _data . object . content ;
} else {
g _content += a _data . object . content ;
}
if ( typeof a _data . object . attachments != 'undefined' ) {
//g_attachments += "<div class='googleplus-attachemnts'>";
for ( var k = 0 ; k < a _data . object . attachments . length ; k ++ ) {
if ( a _data . object . attachments [ k ] . objectType == "photo" ) {
g _attachments = "<a href='" + a _data . object . url + "' target='_blank'>" + "<img src='" + a _data . object . attachments [ k ] . image . url + "' class='article-thumb'></a>" + g _attachments ;
} else if ( a _data . object . attachments [ k ] . objectType == "video" ) {
g _attachments = "<img src='" + a _data . object . attachments [ k ] . image . url + "' class='article-thumb'>" + g _attachments ;
g _attachments += "<div>" ;
g _attachments += "<a href='" + a _data . object . attachments [ k ] . url + "' target='_blank'>"
g _attachments += "<h5>" + a _data . object . attachments [ k ] . displayName + "</h5>" ;
//g_attachments += "<p>" + a_data.object.attachments[k].content + "</p>";
g _attachments += "</a>" ;
g _attachments += "</div>" ;
} else if ( a _data . object . attachments [ k ] . objectType == "article" ) {
g _attachments += "<div>" ;
g _attachments += "<a href='" + a _data . object . attachments [ k ] . url + "' target='_blank'>"
g _attachments += "<h5>" + a _data . object . attachments [ k ] . displayName + "</h5>" ;
g _attachments += "<p>" + a _data . object . attachments [ k ] . content + "</p>" ;
g _attachments += "</a>" ;
g _attachments += "</div>" ;
}
trace ( a _data . object . attachments [ k ] ) ;
}
g _attachments = "<div class='googleplus-attachments'>" + g _attachments + "</div>" ;
}
//mediaElem = "<div class='googleplus'>";
mediaElem = "<div class='googleplus-content'>" + g _content + g _attachments + "</div>" ;
mediaElem += "<div class='vcard author'><a class='screen-name url' href='" + a _data . url + "' target='_blank'>" ;
mediaElem += "<span class='avatar'><img src='" + a _data . actor . image . url + "' style='max-width: 32px; max-height: 32px;'></span>"
mediaElem += "<span class='fn'>" + a _data . actor . displayName + "</span>" ;
mediaElem += "<span class='nickname'><span class='thumbnail-inline'></span></span>" ;
mediaElem += "</a></div>" ;
VMM . attachElement ( "#googleplus_" + gplus . activity , mediaElem ) ;
} ) ;
break ;
}
}
} )
. error ( function ( jqXHR , textStatus , errorThrown ) {
var error _obj = VMM . parseJSON ( jqXHR . responseText ) ;
trace ( error _obj . error . message ) ;
VMM . attachElement ( "#googleplus_" + gplus . activity , VMM . MediaElement . loadingmessage ( "<p>ERROR LOADING GOOGLE+ </p><p>" + error _obj . error . message + "</p>" ) ) ;
} )
. success ( function ( d ) {
clearTimeout ( googleplus _timeout ) ;
clearTimeout ( callback _timeout ) ;
callback ( ) ;
} ) ;
} ,
pushQue : function ( ) {
if ( VMM . master _config . googleplus . que . length > 0 ) {
VMM . ExternalAPI . googleplus . create ( VMM . master _config . googleplus . que [ 0 ] , VMM . ExternalAPI . googleplus . pushQue ) ;
VMM . Util . removeRange ( VMM . master _config . googleplus . que , 0 ) ;
}
/ *
for ( var i = 0 ; i < VMM . master _config . googleplus . que . length ; i ++ ) {
VMM . ExternalAPI . googleplus . create ( VMM . master _config . googleplus . que [ i ] ) ;
}
VMM . master _config . googleplus . que = [ ] ;
* /
} ,
errorTimeOut : function ( gplus ) {
trace ( "GOOGLE+ JSON ERROR TIMEOUT " + gplus . activity ) ;
VMM . attachElement ( "#googleplus_" + gplus . activity , VMM . MediaElement . loadingmessage ( "<p>Still waiting on GOOGLE+ </p><p>" + gplus . activity + "</p>" ) ) ;
}
} ,
googledocs : {
get : function ( m ) {
VMM . master _config . googledocs . que . push ( m ) ;
VMM . master _config . googledocs . active = true ;
} ,
create : function ( m ) {
var mediaElem = "" ;
if ( m . id . match ( /docs.google.com/i ) ) {
mediaElem = "<iframe class='doc' frameborder='0' width='100%' height='100%' src='" + m . id + "&embedded=true'></iframe>" ;
} else {
mediaElem = "<iframe class='doc' frameborder='0' width='100%' height='100%' src='" + "//docs.google.com/viewer?url=" + m . id + "&embedded=true'></iframe>" ;
}
VMM . attachElement ( "#" + m . uid , mediaElem ) ;
} ,
pushQue : function ( ) {
for ( var i = 0 ; i < VMM . master _config . googledocs . que . length ; i ++ ) {
VMM . ExternalAPI . googledocs . create ( VMM . master _config . googledocs . que [ i ] ) ;
}
VMM . master _config . googledocs . que = [ ] ;
}
} ,
flickr : {
get : function ( m ) {
VMM . master _config . flickr . que . push ( m ) ;
VMM . master _config . flickr . active = true ;
} ,
create : function ( m , callback ) {
var api _key ,
callback _timeout = setTimeout ( callback , VMM . master _config . timers . api , m ) ;
if ( typeof VMM . master _config . Timeline != 'undefined' && VMM . master _config . Timeline . api _keys . flickr != "" ) {
api _key = VMM . master _config . Timeline . api _keys . flickr ;
} else {
api _key = Aes . Ctr . decrypt ( VMM . master _config . api _keys _master . flickr , VMM . master _config . vp , 256 )
}
var the _url = "https://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=" + api _key + "&photo_id=" + m . id + "&format=json&jsoncallback=?" ;
VMM . getJSON ( the _url , function ( d ) {
var flickr _id = VMM . ExternalAPI . flickr . getFlickrIdFromUrl ( d . sizes . size [ 0 ] . url ) ;
var flickr _large _id = "#" + m . uid ,
flickr _thumb _id = "#" + m . uid + "_thumb" ;
//flickr_thumb_id = "flickr_" + uid + "_thumb";
var flickr _img _size ,
flickr _img _thumb ,
flickr _size _found = false ,
flickr _best _size = "Large" ;
flickr _best _size = VMM . ExternalAPI . flickr . sizes ( VMM . master _config . sizes . api . height ) ;
for ( var i = 0 ; i < d . sizes . size . length ; i ++ ) {
if ( d . sizes . size [ i ] . label == flickr _best _size ) {
flickr _size _found = true ;
flickr _img _size = d . sizes . size [ i ] . source ;
}
}
if ( ! flickr _size _found ) {
flickr _img _size = d . sizes . size [ d . sizes . size . length - 2 ] . source ;
}
flickr _img _thumb = d . sizes . size [ 0 ] . source ;
VMM . Lib . attr ( flickr _large _id , "src" , flickr _img _size ) ;
//VMM.attachElement(flickr_large_id, "<a href='" + flick.link + "' target='_blank'><img src='" + flickr_img_size + "'></a>");
VMM . attachElement ( flickr _thumb _id , "<img src='" + flickr _img _thumb + "'>" ) ;
} )
. error ( function ( jqXHR , textStatus , errorThrown ) {
trace ( "FLICKR error" ) ;
trace ( "FLICKR ERROR: " + textStatus + " " + jqXHR . responseText ) ;
} )
. success ( function ( d ) {
clearTimeout ( callback _timeout ) ;
callback ( ) ;
} ) ;
} ,
pushQue : function ( ) {
if ( VMM . master _config . flickr . que . length > 0 ) {
VMM . ExternalAPI . flickr . create ( VMM . master _config . flickr . que [ 0 ] , VMM . ExternalAPI . flickr . pushQue ) ;
VMM . Util . removeRange ( VMM . master _config . flickr . que , 0 ) ;
}
} ,
sizes : function ( s ) {
var _size = "" ;
if ( s <= 75 ) {
_size = "Thumbnail" ;
} else if ( s <= 180 ) {
_size = "Small" ;
} else if ( s <= 240 ) {
_size = "Small 320" ;
} else if ( s <= 375 ) {
_size = "Medium" ;
} else if ( s <= 480 ) {
_size = "Medium 640" ;
} else if ( s <= 600 ) {
_size = "Large" ;
} else {
_size = "Large" ;
}
return _size ;
} ,
getFlickrIdFromUrl : function ( url ) {
var idx = url . indexOf ( "flickr.com/photos/" ) ;
if ( idx == - 1 ) return null ;
var pos = idx + "flickr.com/photos/" . length ;
var photo _info = url . substr ( pos )
if ( photo _info . indexOf ( '/' ) == - 1 ) return null ;
if ( photo _info . indexOf ( '/' ) == 0 ) photo _info = photo _info . substr ( 1 ) ;
return photo _info . split ( "/" ) [ 1 ] ;
}
} ,
instagram : {
get : function ( m , thumb ) {
if ( thumb ) {
return "//instagr.am/p/" + m . id + "/media/?size=t" ;
} else {
return "//instagr.am/p/" + m . id + "/media/?size=" + VMM . ExternalAPI . instagram . sizes ( VMM . master _config . sizes . api . height ) ;
}
} ,
sizes : function ( s ) {
var _size = "" ;
if ( s <= 150 ) {
_size = "t" ;
} else if ( s <= 306 ) {
_size = "m" ;
} else {
_size = "l" ;
}
return _size ;
} ,
isInstagramUrl : function ( url ) {
return url . match ( "instagr.am/p/" ) || url . match ( "instagram.com/p/" ) ;
} ,
getInstagramIdFromUrl : function ( url ) {
try {
return url . split ( "\/p\/" ) [ 1 ] . split ( "/" ) [ 0 ] ;
} catch ( e ) {
trace ( "Invalid Instagram url: " + url ) ;
return null ;
}
}
} ,
soundcloud : {
get : function ( m ) {
VMM . master _config . soundcloud . que . push ( m ) ;
VMM . master _config . soundcloud . active = true ;
} ,
create : function ( m , callback ) {
var the _url = "//soundcloud.com/oembed?url=" + m . id + "&maxheight=168&format=js&callback=?" ;
VMM . getJSON ( the _url , function ( d ) {
VMM . attachElement ( "#" + m . uid , d . html ) ;
callback ( ) ;
} ) ;
} ,
pushQue : function ( ) {
if ( VMM . master _config . soundcloud . que . length > 0 ) {
VMM . ExternalAPI . soundcloud . create ( VMM . master _config . soundcloud . que [ 0 ] , VMM . ExternalAPI . soundcloud . pushQue ) ;
VMM . Util . removeRange ( VMM . master _config . soundcloud . que , 0 ) ;
}
}
} ,
wikipedia : {
get : function ( m ) {
VMM . master _config . wikipedia . que . push ( m ) ;
VMM . master _config . wikipedia . active = true ;
} ,
create : function ( m , callback ) {
var the _url = "//" + m . lang + ".wikipedia.org/w/api.php?action=query&prop=extracts&redirects=&titles=" + m . id + "&exintro=1&format=json&callback=?" ;
callback _timeout = setTimeout ( callback , VMM . master _config . timers . api , m ) ;
if ( VMM . Browser . browser == "Explorer" && parseInt ( VMM . Browser . version , 10 ) >= 7 && window . XDomainRequest ) {
var temp _text = "<h4><a href='http://" + VMM . master _config . language . api . wikipedia + ".wikipedia.org/wiki/" + m . id + "' target='_blank'>" + m . url + "</a></h4>" ;
temp _text += "<span class='wiki-source'>" + VMM . master _config . language . messages . wikipedia + "</span>" ;
temp _text += "<p>Wikipedia entry unable to load using Internet Explorer 8 or below.</p>" ;
VMM . attachElement ( "#" + m . uid , temp _text ) ;
}
VMM . getJSON ( the _url , function ( d ) {
if ( d . query ) {
var wiki _extract ,
wiki _title ,
_wiki = "" ,
wiki _text = "" ,
wiki _number _of _paragraphs = 1 ,
wiki _text _array = [ ] ;
wiki _extract = VMM . Util . getObjectAttributeByIndex ( d . query . pages , 0 ) . extract ;
wiki _title = VMM . Util . getObjectAttributeByIndex ( d . query . pages , 0 ) . title ;
if ( wiki _extract . match ( "<p>" ) ) {
wiki _text _array = wiki _extract . split ( "<p>" ) ;
} else {
wiki _text _array . push ( wiki _extract ) ;
}
for ( var i = 0 ; i < wiki _text _array . length ; i ++ ) {
if ( i + 1 <= wiki _number _of _paragraphs && i + 1 < wiki _text _array . length ) {
wiki _text += "<p>" + wiki _text _array [ i + 1 ] ;
}
}
_wiki = "<h4><a href='http://" + VMM . master _config . language . api . wikipedia + ".wikipedia.org/wiki/" + wiki _title + "' target='_blank'>" + wiki _title + "</a></h4>" ;
_wiki += "<span class='wiki-source'>" + VMM . master _config . language . messages . wikipedia + "</span>" ;
_wiki += VMM . Util . linkify _wikipedia ( wiki _text ) ;
if ( wiki _extract . match ( "REDIRECT" ) ) {
} else {
VMM . attachElement ( "#" + m . uid , _wiki ) ;
}
}
//callback();
} )
. error ( function ( jqXHR , textStatus , errorThrown ) {
trace ( "WIKIPEDIA error" ) ;
trace ( "WIKIPEDIA ERROR: " + textStatus + " " + jqXHR . responseText ) ;
trace ( errorThrown ) ;
VMM . attachElement ( "#" + m . uid , VMM . MediaElement . loadingmessage ( "<p>Wikipedia is not responding</p>" ) ) ;
// TRY AGAIN?
clearTimeout ( callback _timeout ) ;
if ( VMM . master _config . wikipedia . tries < 4 ) {
trace ( "WIKIPEDIA ATTEMPT " + VMM . master _config . wikipedia . tries ) ;
trace ( m ) ;
VMM . master _config . wikipedia . tries ++ ;
VMM . ExternalAPI . wikipedia . create ( m , callback ) ;
} else {
callback ( ) ;
}
} )
. success ( function ( d ) {
VMM . master _config . wikipedia . tries = 0 ;
clearTimeout ( callback _timeout ) ;
callback ( ) ;
} ) ;
} ,
pushQue : function ( ) {
if ( VMM . master _config . wikipedia . que . length > 0 ) {
trace ( "WIKIPEDIA PUSH QUE " + VMM . master _config . wikipedia . que . length ) ;
VMM . ExternalAPI . wikipedia . create ( VMM . master _config . wikipedia . que [ 0 ] , VMM . ExternalAPI . wikipedia . pushQue ) ;
VMM . Util . removeRange ( VMM . master _config . wikipedia . que , 0 ) ;
}
}
} ,
youtube : {
get : function ( m ) {
var the _url = "//gdata.youtube.com/feeds/api/videos/" + m . id + "?v=2&alt=jsonc&callback=?" ;
VMM . master _config . youtube . que . push ( m ) ;
if ( ! VMM . master _config . youtube . active ) {
if ( ! VMM . master _config . youtube . api _loaded ) {
LoadLib . js ( '//www.youtube.com/player_api' , function ( ) {
trace ( "YouTube API Library Loaded" ) ;
} ) ;
}
}
// THUMBNAIL
VMM . getJSON ( the _url , function ( d ) {
VMM . ExternalAPI . youtube . createThumb ( d , m )
} ) ;
} ,
create : function ( m ) {
if ( typeof ( m . start ) != 'undefined' ) {
var vidstart = m . start . toString ( ) ,
vid _start _minutes = 0 ,
vid _start _seconds = 0 ;
if ( vidstart . match ( 'm' ) ) {
vid _start _minutes = parseInt ( vidstart . split ( "m" ) [ 0 ] , 10 ) ;
vid _start _seconds = parseInt ( vidstart . split ( "m" ) [ 1 ] . split ( "s" ) [ 0 ] , 10 ) ;
m . start = ( vid _start _minutes * 60 ) + vid _start _seconds ;
} else {
m . start = 0 ;
}
} else {
m . start = 0 ;
}
var p = {
active : false ,
player : { } ,
name : m . uid ,
playing : false ,
hd : false
} ;
if ( typeof ( m . hd ) != 'undefined' ) {
p . hd = true ;
}
p . player [ m . id ] = new YT . Player ( m . uid , {
height : '390' ,
width : '640' ,
playerVars : {
enablejsapi : 1 ,
color : ( "dark" == VMM . master _config . Timeline . youtubeTheme ) ? "red" : "white" , // https://developers.google.com/youtube/player_parameters#color
showinfo : 0 ,
theme : ( "undefined" !== VMM . master _config . Timeline . youtubeTheme ) ? VMM . master _config . Timeline . youtubeTheme : "light" , // https://developers.google.com/youtube/player_parameters#theme
start : m . start ,
rel : 0
} ,
videoId : m . id ,
events : {
'onReady' : VMM . ExternalAPI . youtube . onPlayerReady ,
'onStateChange' : VMM . ExternalAPI . youtube . onStateChange
}
} ) ;
VMM . master _config . youtube . array . push ( p ) ;
} ,
createThumb : function ( d , m ) {
trace ( "CREATE THUMB" ) ;
trace ( d ) ;
trace ( m ) ;
if ( typeof d . data != 'undefined' ) {
var thumb _id = "#" + m . uid + "_thumb" ;
VMM . attachElement ( thumb _id , "<img src='" + d . data . thumbnail . sqDefault + "'>" ) ;
}
} ,
pushQue : function ( ) {
for ( var i = 0 ; i < VMM . master _config . youtube . que . length ; i ++ ) {
VMM . ExternalAPI . youtube . create ( VMM . master _config . youtube . que [ i ] ) ;
}
VMM . master _config . youtube . que = [ ] ;
} ,
onAPIReady : function ( ) {
VMM . master _config . youtube . active = true ;
VMM . ExternalAPI . youtube . pushQue ( ) ;
} ,
stopPlayers : function ( ) {
for ( var i = 0 ; i < VMM . master _config . youtube . array . length ; i ++ ) {
if ( VMM . master _config . youtube . array [ i ] . playing ) {
if ( typeof VMM . master _config . youtube . array [ i ] . player . the _name !== 'undefined' ) {
VMM . master _config . youtube . array [ i ] . player . the _name . stopVideo ( ) ;
}
}
}
} ,
onStateChange : function ( e ) {
for ( var i = 0 ; i < VMM . master _config . youtube . array . length ; i ++ ) {
for ( var z in VMM . master _config . youtube . array [ i ] . player ) {
if ( VMM . master _config . youtube . array [ i ] . player [ z ] == e . target ) {
VMM . master _config . youtube . array [ i ] . player . the _name = VMM . master _config . youtube . array [ i ] . player [ z ] ;
}
}
if ( VMM . master _config . youtube . array [ i ] . player . the _name == e . target ) {
if ( e . data == YT . PlayerState . PLAYING ) {
VMM . master _config . youtube . array [ i ] . playing = true ;
if ( VMM . master _config . youtube . array [ i ] . hd === false ) {
VMM . master _config . youtube . array [ i ] . hd = true ;
VMM . master _config . youtube . array [ i ] . player . the _name . setPlaybackQuality ( "hd720" ) ;
}
}
}
}
} ,
onPlayerReady : function ( e ) {
}
} ,
vimeo : {
get : function ( m ) {
VMM . master _config . vimeo . que . push ( m ) ;
VMM . master _config . vimeo . active = true ;
} ,
create : function ( m , callback ) {
trace ( "VIMEO CREATE" ) ;
// THUMBNAIL
var thumb _url = "//vimeo.com/api/v2/video/" + m . id + ".json" ,
video _url = "//player.vimeo.com/video/" + m . id + "?title=0&byline=0&portrait=0&color=ffffff" ;
VMM . getJSON ( thumb _url , function ( d ) {
VMM . ExternalAPI . vimeo . createThumb ( d , m ) ;
callback ( ) ;
} ) ;
// VIDEO
VMM . attachElement ( "#" + m . uid , "<iframe autostart='false' frameborder='0' width='100%' height='100%' src='" + video _url + "'></iframe>" ) ;
} ,
createThumb : function ( d , m ) {
trace ( "VIMEO CREATE THUMB" ) ;
var thumb _id = "#" + m . uid + "_thumb" ;
VMM . attachElement ( thumb _id , "<img src='" + d [ 0 ] . thumbnail _small + "'>" ) ;
} ,
pushQue : function ( ) {
if ( VMM . master _config . vimeo . que . length > 0 ) {
VMM . ExternalAPI . vimeo . create ( VMM . master _config . vimeo . que [ 0 ] , VMM . ExternalAPI . vimeo . pushQue ) ;
VMM . Util . removeRange ( VMM . master _config . vimeo . que , 0 ) ;
}
}
} ,
vine : {
get : function ( m ) {
VMM . master _config . vine . que . push ( m ) ;
VMM . master _config . vine . active = true ;
} ,
create : function ( m , callback ) {
trace ( "VINE CREATE" ) ;
var video _url = "https://vine.co/v/" + m . id + "/embed/simple" ;
// VIDEO
// TODO: NEED TO ADD ASYNC SCRIPT TO TIMELINE FLOW
VMM . attachElement ( "#" + m . uid , "<iframe frameborder='0' width='100%' height='100%' src='" + video _url + "'></iframe><script async src='https://platform.vine.co/static/scripts/embed.js' charset='utf-8'></script>" ) ;
} ,
pushQue : function ( ) {
if ( VMM . master _config . vine . que . length > 0 ) {
VMM . ExternalAPI . vine . create ( VMM . master _config . vine . que [ 0 ] , VMM . ExternalAPI . vine . pushQue ) ;
VMM . Util . removeRange ( VMM . master _config . vine . que , 0 ) ;
}
}
} ,
webthumb : {
get : function ( m , thumb ) {
VMM . master _config . webthumb . que . push ( m ) ;
VMM . master _config . webthumb . active = true ;
} ,
sizes : function ( s ) {
var _size = "" ;
if ( s <= 150 ) {
_size = "t" ;
} else if ( s <= 306 ) {
_size = "m" ;
} else {
_size = "l" ;
}
return _size ;
} ,
create : function ( m ) {
trace ( "WEB THUMB CREATE" ) ;
var thumb _url = "//api.pagepeeker.com/v2/thumbs.php?" ;
url = m . id . replace ( "http://" , "" ) ; //.split("/")[0];
// Main Image
VMM . attachElement ( "#" + m . uid , "<a href='" + m . id + "' target='_blank'><img src='" + thumb _url + "size=x&url=" + url + "'></a>" ) ;
// Thumb
VMM . attachElement ( "#" + m . uid + "_thumb" , "<img src='" + thumb _url + "size=t&url=" + url + "'>" ) ;
} ,
pushQue : function ( ) {
for ( var i = 0 ; i < VMM . master _config . webthumb . que . length ; i ++ ) {
VMM . ExternalAPI . webthumb . create ( VMM . master _config . webthumb . que [ i ] ) ;
}
VMM . master _config . webthumb . que = [ ] ;
}
}
} ) . init ( ) ;
}
/ * Y O U T U B E A P I R E A D Y
Can ' t find a way to customize this callback and keep it in the VMM namespace
Youtube wants it to be this function .
=== === === === === === === === === === === === === === === === == * /
function onYouTubePlayerAPIReady ( ) {
trace ( "GLOBAL YOUTUBE API CALLED" )
VMM . ExternalAPI . youtube . onAPIReady ( ) ;
}