//StoryJS Embed Loader
// Provide a bootstrap method for instantiating a timeline. On page load, check the definition of these window scoped variables in this order: [url_config, timeline_config, storyjs_config, config]. As soon as one of these is found to be defined with type 'object,' it will be used to automatically instantiate a timeline.
/ * C o d e K i t I m p o r t
http : //incident57.com/codekit/
=== === === === === === === === === === === === === === === === == * /
// @codekit-prepend "Embed.LoadLib.js";
var WebFontConfig ;
if ( typeof embed _path == 'undefined' ) {
// REPLACE WITH YOUR BASEPATH IF YOU WANT OTHERWISE IT WILL TRY AND FIGURE IT OUT
var _tmp _script _path = getEmbedScriptPath ( "storyjs-embed.js" ) ;
var embed _path = _tmp _script _path . substr ( 0 , _tmp _script _path . lastIndexOf ( 'js/' ) )
}
function getEmbedScriptPath ( scriptname ) {
var scriptTags = document . getElementsByTagName ( 'script' ) ,
script _path = "" ,
script _path _end = "" ;
for ( var i = 0 ; i < scriptTags . length ; i ++ ) {
if ( scriptTags [ i ] . src . match ( scriptname ) ) {
script _path = scriptTags [ i ] . src ;
}
}
if ( script _path != "" ) {
script _path _end = "/"
}
return script _path . split ( '?' ) [ 0 ] . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) + script _path _end ;
}
/ * C H E C K T O S E E I F A C O N F I G I S A L R E A D Y D E F I N E D ( F O R E A S Y E M B E D )
=== === === === === === === === === === === === === === === === == * /
( function ( ) {
if ( typeof url _config == 'object' ) {
createStoryJS ( url _config ) ;
} else if ( typeof timeline _config == 'object' ) {
createStoryJS ( timeline _config ) ;
} else if ( typeof storyjs _config == 'object' ) {
createStoryJS ( storyjs _config ) ;
} else if ( typeof config == 'object' ) {
createStoryJS ( config ) ;
} else {
// No existing config. Call createStoryJS(your_config) manually with a config
}
} ) ( ) ;
/ * C R E A T E S t o r y J S E m b e d
=== === === === === === === === === === === === === === === === == * /
function createStoryJS ( c , src ) {
/ * V A R S
=== === === === === === === === === === === === === === === === == * /
var storyjs _embedjs , t , te , x ,
isCDN = false ,
js _version = "2.24" ,
jquery _version _required = "1.7.1" ,
jquery _version = "" ,
ready = {
timeout : "" ,
checks : 0 ,
finished : false ,
js : false ,
css : false ,
jquery : false ,
has _jquery : false ,
language : false ,
font : {
css : false ,
js : false
}
} ,
path = {
base : embed _path ,
css : embed _path + "css/" ,
js : embed _path + "js/" ,
locale : embed _path + "js/locale/" ,
jquery : "//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ,
font : {
google : false ,
css : embed _path + "css/themes/font/" ,
js : "//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"
}
} ,
storyjs _e _config = {
version : js _version ,
debug : false ,
type : 'timeline' ,
id : 'storyjs' ,
embed _id : 'timeline-embed' ,
embed : true ,
width : '100%' ,
height : '100%' ,
source : 'https://docs.google.com/spreadsheet/pub?key=0Agl_Dv6iEbDadFYzRjJPUGktY0NkWXFUWkVIZDNGRHc&output=html' ,
lang : 'en' ,
font : 'default' ,
css : path . css + 'timeline.css?' + js _version ,
js : '' ,
api _keys : {
google : "" ,
flickr : "" ,
twitter : ""
} ,
gmap _key : ""
} ,
font _presets = [
{ name : "Merriweather-NewsCycle" , google : [ 'News+Cycle:400,700:latin' , 'Merriweather:400,700,900:latin' ] } ,
{ name : "NewsCycle-Merriweather" , google : [ 'News+Cycle:400,700:latin' , 'Merriweather:300,400,700:latin' ] } ,
{ name : "PoiretOne-Molengo" , google : [ 'Poiret+One::latin' , 'Molengo::latin' ] } ,
{ name : "Arvo-PTSans" , google : [ 'Arvo:400,700,400italic:latin' , 'PT+Sans:400,700,400italic:latin' ] } ,
{ name : "PTSerif-PTSans" , google : [ 'PT+Sans:400,700,400italic:latin' , 'PT+Serif:400,700,400italic:latin' ] } ,
{ name : "PT" , google : [ 'PT+Sans+Narrow:400,700:latin' , 'PT+Sans:400,700,400italic:latin' , 'PT+Serif:400,700,400italic:latin' ] } ,
{ name : "DroidSerif-DroidSans" , google : [ 'Droid+Sans:400,700:latin' , 'Droid+Serif:400,700,400italic:latin' ] } ,
{ name : "Lekton-Molengo" , google : [ 'Lekton:400,700,400italic:latin' , 'Molengo::latin' ] } ,
{ name : "NixieOne-Ledger" , google : [ 'Nixie+One::latin' , 'Ledger::latin' ] } ,
{ name : "AbrilFatface-Average" , google : [ 'Average::latin' , 'Abril+Fatface::latin' ] } ,
{ name : "PlayfairDisplay-Muli" , google : [ 'Playfair+Display:400,400italic:latin' , 'Muli:300,400,300italic,400italic:latin' ] } ,
{ name : "Rancho-Gudea" , google : [ 'Rancho::latin' , 'Gudea:400,700,400italic:latin' ] } ,
{ name : "Bevan-PotanoSans" , google : [ 'Bevan::latin' , 'Pontano+Sans::latin' ] } ,
{ name : "BreeSerif-OpenSans" , google : [ 'Bree+Serif::latin' , 'Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800:latin' ] } ,
{ name : "SansitaOne-Kameron" , google : [ 'Sansita+One::latin' , 'Kameron:400,700:latin' ] } ,
{ name : "Lora-Istok" , google : [ 'Lora:400,700,400italic,700italic:latin' , 'Istok+Web:400,700,400italic,700italic:latin' ] } ,
{ name : "Pacifico-Arimo" , google : [ 'Pacifico::latin' , 'Arimo:400,700,400italic,700italic:latin' ] }
] ;
/ * B U I L D C O N F I G
=== === === === === === === === === === === === === === === === == * /
if ( typeof c == 'object' ) {
for ( x in c ) {
if ( Object . prototype . hasOwnProperty . call ( c , x ) ) {
storyjs _e _config [ x ] = c [ x ] ;
}
}
}
if ( typeof src != 'undefined' ) {
storyjs _e _config . source = src ;
}
/ * C D N V E R S I O N ?
=== === === === === === === === === === === === === === === === == * /
if ( typeof url _config == 'object' ) {
isCDN = true ;
/ * I S T H E S O U R C E G O O G L E S P R E A D S H E E T W I T H J U S T T H E K E Y ?
=== === === === === === === === === === === === === === === === == * /
if ( storyjs _e _config . source . match ( "docs.google.com" ) || storyjs _e _config . source . match ( "json" ) || storyjs _e _config . source . match ( "storify" ) ) {
} else {
storyjs _e _config . source = "https://docs.google.com/spreadsheet/pub?key=" + storyjs _e _config . source + "&output=html" ;
}
}
/ * D E T E R M I N E T Y P E
=== === === === === === === === === === === === === === === === == * /
// Check for old installs still using the old method of language
if ( storyjs _e _config . js . match ( "locale" ) ) {
storyjs _e _config . lang = storyjs _e _config . js . split ( "locale/" ) [ 1 ] . replace ( ".js" , "" ) ;
storyjs _e _config . js = path . js + 'timeline-min.js?' + js _version ;
}
if ( storyjs _e _config . js . match ( "/" ) ) {
} else {
storyjs _e _config . css = path . css + storyjs _e _config . type + ".css?" + js _version ;
// Use unminified js file if in debug mode
storyjs _e _config . js = path . js + storyjs _e _config . type ;
if ( storyjs _e _config . debug ) {
storyjs _e _config . js += ".js?" + js _version ;
} else {
storyjs _e _config . js += "-min.js?" + js _version ;
}
storyjs _e _config . id = "storyjs-" + storyjs _e _config . type ;
}
/ * P R E P A R E L A N G U A G E
=== === === === === === === === === === === === === === === === == * /
if ( storyjs _e _config . lang . match ( "/" ) ) {
path . locale = storyjs _e _config . lang ;
} else {
path . locale = path . locale + storyjs _e _config . lang + ".js?" + js _version ;
}
/ * P R E P A R E
=== === === === === === === === === === === === === === === === == * /
createEmbedDiv ( ) ;
/ * L o a d C S S
=== === === === === === === === === === === === === === === === == * /
LoadLib . css ( storyjs _e _config . css , onloaded _css ) ;
/ * L o a d F O N T
=== === === === === === === === === === === === === === === === == * /
if ( storyjs _e _config . font == "default" ) {
ready . font . js = true ;
ready . font . css = true ;
} else {
// FONT CSS
var fn ;
if ( storyjs _e _config . font . match ( "/" ) ) {
fn = storyjs _e _config . font . split ( ".css" ) [ 0 ] . split ( "/" ) ;
path . font . name = fn [ fn . length - 1 ] ;
path . font . css = storyjs _e _config . font ;
} else {
path . font . name = storyjs _e _config . font ;
path . font . css = path . font . css + storyjs _e _config . font + ".css?" + js _version ;
}
LoadLib . css ( path . font . css , onloaded _font _css ) ;
// FONT GOOGLE JS
for ( var i = 0 ; i < font _presets . length ; i ++ ) {
if ( path . font . name == font _presets [ i ] . name ) {
path . font . google = true ;
WebFontConfig = { google : { families : font _presets [ i ] . google } } ;
}
}
if ( path . font . google ) {
LoadLib . js ( path . font . js , onloaded _font _js ) ;
} else {
ready . font . js = true ;
}
}
/ * L o a d j Q u e r y
=== === === === === === === === === === === === === === === === == * /
try {
ready . has _jquery = jQuery ;
ready . has _jquery = true ;
if ( ready . has _jquery ) {
var jquery _version = parseFloat ( jQuery . fn . jquery ) ;
if ( jquery _version < parseFloat ( jquery _version _required ) ) {
//console.log("NOT THE REQUIRED VERSION OF JQUERY, LOADING THE REQUIRED VERSION");
//console.log("YOU HAVE VERSION " + jQuery.fn.jquery + ", JQUERY VERSION " + jquery_version_required + " OR ABOVE NEEDED");
ready . jquery = false ;
} else {
ready . jquery = true ;
}
}
} catch ( err ) {
ready . jquery = false ;
}
if ( ! ready . jquery ) {
LoadLib . js ( path . jquery , onloaded _jquery ) ;
} else {
onloaded _jquery ( ) ;
}
/ * O n L o a d e d
=== === === === === === === === === === === === === === === === == * /
function onloaded _jquery ( ) {
LoadLib . js ( storyjs _e _config . js , onloaded _js ) ;
}
function onloaded _js ( ) {
ready . js = true ;
if ( storyjs _e _config . lang != "en" ) {
LazyLoad . js ( path . locale , onloaded _language ) ;
} else {
ready . language = true ;
}
onloaded _check ( ) ;
}
function onloaded _language ( ) {
ready . language = true ;
onloaded _check ( ) ;
}
function onloaded _css ( ) {
ready . css = true ;
onloaded _check ( ) ;
}
function onloaded _font _css ( ) {
ready . font . css = true ;
onloaded _check ( ) ;
}
function onloaded _font _js ( ) {
ready . font . js = true ;
onloaded _check ( ) ;
}
function onloaded _check ( ) {
if ( ready . checks > 40 ) {
return ;
alert ( "Error Loading Files" ) ;
} else {
ready . checks ++ ;
if ( ready . js && ready . css && ready . font . css && ready . font . js && ready . language ) {
if ( ! ready . finished ) {
ready . finished = true ;
buildEmbed ( ) ;
}
} else {
ready . timeout = setTimeout ( 'onloaded_check_again();' , 250 ) ;
}
}
} ;
this . onloaded _check _again = function ( ) {
onloaded _check ( ) ;
} ;
/ * B u i l d T i m e l i n e
=== === === === === === === === === === === === === === === === == * /
function createEmbedDiv ( ) {
var embed _classname = "storyjs-embed" ;
t = document . createElement ( 'div' ) ;
if ( storyjs _e _config . embed _id != "" ) {
te = document . getElementById ( storyjs _e _config . embed _id ) ;
} else {
te = document . getElementById ( "timeline-embed" ) ;
}
te . appendChild ( t ) ;
t . setAttribute ( "id" , storyjs _e _config . id ) ;
if ( storyjs _e _config . width . toString ( ) . match ( "%" ) ) {
te . style . width = storyjs _e _config . width . split ( "%" ) [ 0 ] + "%" ;
} else {
storyjs _e _config . width = storyjs _e _config . width - 2 ;
te . style . width = ( storyjs _e _config . width ) + 'px' ;
}
if ( storyjs _e _config . height . toString ( ) . match ( "%" ) ) {
te . style . height = storyjs _e _config . height ;
embed _classname += " full-embed" ;
te . style . height = storyjs _e _config . height . split ( "%" ) [ 0 ] + "%" ;
} else if ( storyjs _e _config . width . toString ( ) . match ( "%" ) ) {
embed _classname += " full-embed" ;
storyjs _e _config . height = storyjs _e _config . height - 16 ;
te . style . height = ( storyjs _e _config . height ) + 'px' ;
} else {
embed _classname += " sized-embed" ;
storyjs _e _config . height = storyjs _e _config . height - 16 ;
te . style . height = ( storyjs _e _config . height ) + 'px' ;
}
te . setAttribute ( "class" , embed _classname ) ;
te . setAttribute ( "className" , embed _classname ) ;
t . style . position = 'relative' ;
}
function buildEmbed ( ) {
VMM . debug = storyjs _e _config . debug ;
storyjs _embedjs = new VMM . Timeline ( storyjs _e _config . id ) ;
storyjs _embedjs . init ( storyjs _e _config ) ;
if ( isCDN ) {
VMM . bindEvent ( global , onHeadline , "HEADLINE" ) ;
}
}
}