Le repo des sources pour le site web des JM2L
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

10084 lines
302 KiB

  1. /*
  2. TimelineJS - ver. 2.35.2 - 2014-11-24
  3. Copyright (c) 2012-2013 Northwestern University
  4. a project of the Northwestern University Knight Lab, originally created by Zach Wise
  5. https://github.com/NUKnightLab/TimelineJS
  6. This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  7. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. */
  9. /* **********************************************
  10. Begin VMM.js
  11. ********************************************** */
  12. /**
  13. * VéritéCo JS Core
  14. * Designed and built by Zach Wise at VéritéCo zach@verite.co
  15. * This Source Code Form is subject to the terms of the Mozilla Public
  16. * License, v. 2.0. If a copy of the MPL was not distributed with this
  17. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  18. */
  19. /* Simple JavaScript Inheritance
  20. By John Resig http://ejohn.org/
  21. MIT Licensed.
  22. ================================================== */
  23. (function() {
  24. var initializing = false,
  25. fnTest = /xyz/.test(function() {
  26. xyz;
  27. }) ? /\b_super\b/: /.*/;
  28. // The base Class implementation (does nothing)
  29. this.Class = function() {};
  30. // Create a new Class that inherits from this class
  31. Class.extend = function(prop) {
  32. var _super = this.prototype;
  33. // Instantiate a base class (but only create the instance,
  34. // don't run the init constructor)
  35. initializing = true;
  36. var prototype = new this();
  37. initializing = false;
  38. // Copy the properties over onto the new prototype
  39. for (var name in prop) {
  40. // Check if we're overwriting an existing function
  41. prototype[name] = typeof prop[name] == "function" &&
  42. typeof _super[name] == "function" && fnTest.test(prop[name]) ?
  43. (function(name, fn) {
  44. return function() {
  45. var tmp = this._super;
  46. // Add a new ._super() method that is the same method
  47. // but on the super-class
  48. this._super = _super[name];
  49. // The method only need to be bound temporarily, so we
  50. // remove it when we're done executing
  51. var ret = fn.apply(this, arguments);
  52. this._super = tmp;
  53. return ret;
  54. };
  55. })(name, prop[name]) :
  56. prop[name];
  57. }
  58. // The dummy class constructor
  59. function Class() {
  60. // All construction is actually done in the init method
  61. if (!initializing && this.init)
  62. this.init.apply(this, arguments);
  63. }
  64. // Populate our constructed prototype object
  65. Class.prototype = prototype;
  66. // Enforce the constructor to be what we expect
  67. Class.prototype.constructor = Class;
  68. // And make this class extendable
  69. Class.extend = arguments.callee;
  70. return Class;
  71. };
  72. })();
  73. /* Access to the Global Object
  74. access the global object without hard-coding the identifier window
  75. ================================================== */
  76. var global = (function () {
  77. return this || (1,eval)('this');
  78. }());
  79. /* VMM
  80. ================================================== */
  81. if (typeof VMM == 'undefined') {
  82. /* Main Scope Container
  83. ================================================== */
  84. //var VMM = {};
  85. var VMM = Class.extend({});
  86. /* Debug
  87. ================================================== */
  88. VMM.debug = true;
  89. /* Master Config
  90. ================================================== */
  91. VMM.master_config = ({
  92. init: function() {
  93. return this;
  94. },
  95. sizes: {
  96. api: {
  97. width: 0,
  98. height: 0
  99. }
  100. },
  101. vp: "Pellentesque nibh felis, eleifend id, commodo in, interdum vitae, leo",
  102. api_keys_master: {
  103. flickr: "RAIvxHY4hE/Elm5cieh4X5ptMyDpj7MYIxziGxi0WGCcy1s+yr7rKQ==",
  104. //google: "jwNGnYw4hE9lmAez4ll0QD+jo6SKBJFknkopLS4FrSAuGfIwyj57AusuR0s8dAo=",
  105. google: "uQKadH1VMlCsp560gN2aOiMz4evWkl1s34yryl3F/9FJOsn+/948CbBUvKLN46U=",
  106. twitter: ""
  107. },
  108. timers: {
  109. api: 7000
  110. },
  111. api: {
  112. pushques: []
  113. },
  114. twitter: {
  115. active: false,
  116. array: [],
  117. api_loaded: false,
  118. que: []
  119. },
  120. flickr: {
  121. active: false,
  122. array: [],
  123. api_loaded: false,
  124. que: []
  125. },
  126. youtube: {
  127. active: false,
  128. array: [],
  129. api_loaded: false,
  130. que: []
  131. },
  132. vimeo: {
  133. active: false,
  134. array: [],
  135. api_loaded: false,
  136. que: []
  137. },
  138. vine: {
  139. active: false,
  140. array: [],
  141. api_loaded: false,
  142. que: []
  143. },
  144. webthumb: {
  145. active: false,
  146. array: [],
  147. api_loaded: false,
  148. que: []
  149. },
  150. googlemaps: {
  151. active: false,
  152. map_active: false,
  153. places_active: false,
  154. array: [],
  155. api_loaded: false,
  156. que: []
  157. },
  158. googledocs: {
  159. active: false,
  160. array: [],
  161. api_loaded: false,
  162. que: []
  163. },
  164. googleplus: {
  165. active: false,
  166. array: [],
  167. api_loaded: false,
  168. que: []
  169. },
  170. wikipedia: {
  171. active: false,
  172. array: [],
  173. api_loaded: false,
  174. que: [],
  175. tries: 0
  176. },
  177. soundcloud: {
  178. active: false,
  179. array: [],
  180. api_loaded: false,
  181. que: []
  182. }
  183. }).init();
  184. //VMM.createElement(tag, value, cName, attrs, styles);
  185. VMM.createElement = function(tag, value, cName, attrs, styles) {
  186. var ce = "";
  187. if (tag != null && tag != "") {
  188. // TAG
  189. ce += "<" + tag;
  190. if (cName != null && cName != "") {
  191. ce += " class='" + cName + "'";
  192. };
  193. if (attrs != null && attrs != "") {
  194. ce += " " + attrs;
  195. };
  196. if (styles != null && styles != "") {
  197. ce += " style='" + styles + "'";
  198. };
  199. ce += ">";
  200. if (value != null && value != "") {
  201. ce += value;
  202. }
  203. // CLOSE TAG
  204. ce = ce + "</" + tag + ">";
  205. }
  206. return ce;
  207. };
  208. VMM.createMediaElement = function(media, caption, credit) {
  209. var ce = "";
  210. var _valid = false;
  211. ce += "<div class='media'>";
  212. if (media != null && media != "") {
  213. valid = true;
  214. ce += "<img src='" + media + "'>";
  215. // CREDIT
  216. if (credit != null && credit != "") {
  217. ce += VMM.createElement("div", credit, "credit");
  218. }
  219. // CAPTION
  220. if (caption != null && caption != "") {
  221. ce += VMM.createElement("div", caption, "caption");
  222. }
  223. }
  224. ce += "</div>";
  225. return ce;
  226. };
  227. // Hide URL Bar for iOS and Android by Scott Jehl
  228. // https://gist.github.com/1183357
  229. VMM.hideUrlBar = function () {
  230. var win = window,
  231. doc = win.document;
  232. // If there's a hash, or addEventListener is undefined, stop here
  233. if( !location.hash || !win.addEventListener ){
  234. //scroll to 1
  235. window.scrollTo( 0, 1 );
  236. var scrollTop = 1,
  237. //reset to 0 on bodyready, if needed
  238. bodycheck = setInterval(function(){
  239. if( doc.body ){
  240. clearInterval( bodycheck );
  241. scrollTop = "scrollTop" in doc.body ? doc.body.scrollTop : 1;
  242. win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
  243. }
  244. }, 15 );
  245. win.addEventListener( "load", function(){
  246. setTimeout(function(){
  247. //reset to hide addr bar at onload
  248. win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
  249. }, 0);
  250. }, false );
  251. }
  252. };
  253. }
  254. /* Trace (console.log)
  255. ================================================== */
  256. function trace( msg ) {
  257. if (VMM.debug) {
  258. if (window.console) {
  259. console.log(msg);
  260. } else if ( typeof( jsTrace ) != 'undefined' ) {
  261. jsTrace.send( msg );
  262. } else {
  263. //alert(msg);
  264. }
  265. }
  266. }
  267. /* Extending Date to include Week
  268. ================================================== */
  269. Date.prototype.getWeek = function() {
  270. var onejan = new Date(this.getFullYear(),0,1);
  271. return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
  272. }
  273. /* Extending Date to include Day of Year
  274. ================================================== */
  275. Date.prototype.getDayOfYear = function() {
  276. var onejan = new Date(this.getFullYear(),0,1);
  277. return Math.ceil((this - onejan) / 86400000);
  278. }
  279. /* A MORE SPECIFIC TYPEOF();
  280. // http://rolandog.com/archives/2007/01/18/typeof-a-more-specific-typeof/
  281. ================================================== */
  282. // type.of()
  283. var is={
  284. Null:function(a){return a===null;},
  285. Undefined:function(a){return a===undefined;},
  286. nt:function(a){return(a===null||a===undefined);},
  287. Function:function(a){return(typeof(a)==="function")?a.constructor.toString().match(/Function/)!==null:false;},
  288. String:function(a){return(typeof(a)==="string")?true:(typeof(a)==="object")?a.constructor.toString().match(/string/i)!==null:false;},
  289. Array:function(a){return(typeof(a)==="object")?a.constructor.toString().match(/array/i)!==null||a.length!==undefined:false;},
  290. Boolean:function(a){return(typeof(a)==="boolean")?true:(typeof(a)==="object")?a.constructor.toString().match(/boolean/i)!==null:false;},
  291. Date:function(a){return(typeof(a)==="date")?true:(typeof(a)==="object")?a.constructor.toString().match(/date/i)!==null:false;},
  292. HTML:function(a){return(typeof(a)==="object")?a.constructor.toString().match(/html/i)!==null:false;},
  293. Number:function(a){return(typeof(a)==="number")?true:(typeof(a)==="object")?a.constructor.toString().match(/Number/)!==null:false;},
  294. Object:function(a){return(typeof(a)==="object")?a.constructor.toString().match(/object/i)!==null:false;},
  295. RegExp:function(a){return(typeof(a)==="function")?a.constructor.toString().match(/regexp/i)!==null:false;}
  296. };
  297. var type={
  298. of:function(a){
  299. for(var i in is){
  300. if(is[i](a)){
  301. return i.toLowerCase();
  302. }
  303. }
  304. }
  305. };
  306. /* **********************************************
  307. Begin VMM.Library.js
  308. ********************************************** */
  309. /* * LIBRARY ABSTRACTION
  310. ================================================== */
  311. if(typeof VMM != 'undefined') {
  312. VMM.smoothScrollTo = function(elem, duration, ease) {
  313. if( typeof( jQuery ) != 'undefined' ){
  314. var _ease = "easein",
  315. _duration = 1000;
  316. if (duration != null) {
  317. if (duration < 1) {
  318. _duration = 1;
  319. } else {
  320. _duration = Math.round(duration);
  321. }
  322. }
  323. if (ease != null && ease != "") {
  324. _ease = ease;
  325. }
  326. if (jQuery(window).scrollTop() != VMM.Lib.offset(elem).top) {
  327. VMM.Lib.animate('html,body', _duration, _ease, {scrollTop: VMM.Lib.offset(elem).top})
  328. }
  329. }
  330. };
  331. VMM.attachElement = function(element, content) {
  332. if( typeof( jQuery ) != 'undefined' ){
  333. jQuery(element).html(content);
  334. }
  335. };
  336. VMM.appendElement = function(element, content) {
  337. if( typeof( jQuery ) != 'undefined' ){
  338. jQuery(element).append(content);
  339. }
  340. };
  341. VMM.getHTML = function(element) {
  342. var e;
  343. if( typeof( jQuery ) != 'undefined' ){
  344. e = jQuery(element).html();
  345. return e;
  346. }
  347. };
  348. VMM.getElement = function(element, p) {
  349. var e;
  350. if( typeof( jQuery ) != 'undefined' ){
  351. if (p) {
  352. e = jQuery(element).parent().get(0);
  353. } else {
  354. e = jQuery(element).get(0);
  355. }
  356. return e;
  357. }
  358. };
  359. VMM.bindEvent = function(element, the_handler, the_event_type, event_data) {
  360. var e;
  361. var _event_type = "click";
  362. var _event_data = {};
  363. if (the_event_type != null && the_event_type != "") {
  364. _event_type = the_event_type;
  365. }
  366. if (_event_data != null && _event_data != "") {
  367. _event_data = event_data;
  368. }
  369. if( typeof( jQuery ) != 'undefined' ){
  370. jQuery(element).bind(_event_type, _event_data, the_handler);
  371. //return e;
  372. }
  373. };
  374. VMM.unbindEvent = function(element, the_handler, the_event_type) {
  375. var e;
  376. var _event_type = "click";
  377. var _event_data = {};
  378. if (the_event_type != null && the_event_type != "") {
  379. _event_type = the_event_type;
  380. }
  381. if( typeof( jQuery ) != 'undefined' ){
  382. jQuery(element).unbind(_event_type, the_handler);
  383. //return e;
  384. }
  385. };
  386. VMM.fireEvent = function(element, the_event_type, the_data) {
  387. var e;
  388. var _event_type = "click";
  389. var _data = [];
  390. if (the_event_type != null && the_event_type != "") {
  391. _event_type = the_event_type;
  392. }
  393. if (the_data != null && the_data != "") {
  394. _data = the_data;
  395. }
  396. if( typeof( jQuery ) != 'undefined' ){
  397. jQuery(element).trigger(_event_type, _data);
  398. //return e;
  399. }
  400. };
  401. VMM.getJSON = function(url, data, callback) {
  402. if( typeof( jQuery ) != 'undefined' ){
  403. jQuery.ajaxSetup({
  404. timeout: 3000
  405. });
  406. /* CHECK FOR IE
  407. ================================================== */
  408. if ( VMM.Browser.browser == "Explorer" &&
  409. parseInt(VMM.Browser.version, 10) >= 7 &&
  410. window.XDomainRequest &&
  411. url.match('^https?://')) {
  412. trace("old IE JSON doesn't like retrieving from different protocol");
  413. var colon = url.indexOf(':');
  414. url = url.substr(colon+1);
  415. }
  416. return jQuery.getJSON(url, data, callback);
  417. }
  418. }
  419. VMM.parseJSON = function(the_json) {
  420. if( typeof( jQuery ) != 'undefined' ){
  421. return jQuery.parseJSON(the_json);
  422. }
  423. }
  424. // ADD ELEMENT AND RETURN IT
  425. VMM.appendAndGetElement = function(append_to_element, tag, cName, content) {
  426. var e,
  427. _tag = "<div>",
  428. _class = "",
  429. _content = "",
  430. _id = "";
  431. if (tag != null && tag != "") {
  432. _tag = tag;
  433. }
  434. if (cName != null && cName != "") {
  435. _class = cName;
  436. }
  437. if (content != null && content != "") {
  438. _content = content;
  439. }
  440. if( typeof( jQuery ) != 'undefined' ){
  441. e = jQuery(tag);
  442. e.addClass(_class);
  443. e.html(_content);
  444. jQuery(append_to_element).append(e);
  445. }
  446. return e;
  447. };
  448. VMM.Lib = {
  449. init: function() {
  450. return this;
  451. },
  452. hide: function(element, duration) {
  453. if (duration != null && duration != "") {
  454. if( typeof( jQuery ) != 'undefined' ){
  455. jQuery(element).hide(duration);
  456. }
  457. } else {
  458. if( typeof( jQuery ) != 'undefined' ){
  459. jQuery(element).hide();
  460. }
  461. }
  462. },
  463. remove: function(element) {
  464. if( typeof( jQuery ) != 'undefined' ){
  465. jQuery(element).remove();
  466. }
  467. },
  468. detach: function(element) {
  469. if( typeof( jQuery ) != 'undefined' ){
  470. jQuery(element).detach();
  471. }
  472. },
  473. append: function(element, value) {
  474. if( typeof( jQuery ) != 'undefined' ){
  475. jQuery(element).append(value);
  476. }
  477. },
  478. prepend: function(element, value) {
  479. if( typeof( jQuery ) != 'undefined' ){
  480. jQuery(element).prepend(value);
  481. }
  482. },
  483. show: function(element, duration) {
  484. if (duration != null && duration != "") {
  485. if( typeof( jQuery ) != 'undefined' ){
  486. jQuery(element).show(duration);
  487. }
  488. } else {
  489. if( typeof( jQuery ) != 'undefined' ){
  490. jQuery(element).show();
  491. }
  492. }
  493. },
  494. load: function(element, callback_function, event_data) {
  495. var _event_data = {elem:element}; // return element by default
  496. if (_event_data != null && _event_data != "") {
  497. _event_data = event_data;
  498. }
  499. if( typeof( jQuery ) != 'undefined' ){
  500. jQuery(element).load(_event_data, callback_function);
  501. }
  502. },
  503. addClass: function(element, cName) {
  504. if( typeof( jQuery ) != 'undefined' ){
  505. jQuery(element).addClass(cName);
  506. }
  507. },
  508. removeClass: function(element, cName) {
  509. if( typeof( jQuery ) != 'undefined' ){
  510. jQuery(element).removeClass(cName);
  511. }
  512. },
  513. attr: function(element, aName, value) {
  514. if (value != null && value != "") {
  515. if( typeof( jQuery ) != 'undefined' ){
  516. jQuery(element).attr(aName, value);
  517. }
  518. } else {
  519. if( typeof( jQuery ) != 'undefined' ){
  520. return jQuery(element).attr(aName);
  521. }
  522. }
  523. },
  524. prop: function(element, aName, value) {
  525. if (typeof jQuery == 'undefined' || !/[1-9]\.[3-9].[1-9]/.test(jQuery.fn.jquery)) {
  526. VMM.Lib.attribute(element, aName, value);
  527. } else {
  528. jQuery(element).prop(aName, value);
  529. }
  530. },
  531. attribute: function(element, aName, value) {
  532. if (value != null && value != "") {
  533. if( typeof( jQuery ) != 'undefined' ){
  534. jQuery(element).attr(aName, value);
  535. }
  536. } else {
  537. if( typeof( jQuery ) != 'undefined' ){
  538. return jQuery(element).attr(aName);
  539. }
  540. }
  541. },
  542. visible: function(element, show) {
  543. if (show != null) {
  544. if( typeof( jQuery ) != 'undefined' ){
  545. if (show) {
  546. jQuery(element).show(0);
  547. } else {
  548. jQuery(element).hide(0);
  549. }
  550. }
  551. } else {
  552. if( typeof( jQuery ) != 'undefined' ){
  553. if ( jQuery(element).is(':visible')){
  554. return true;
  555. } else {
  556. return false;
  557. }
  558. }
  559. }
  560. },
  561. css: function(element, prop, value) {
  562. if (value != null && value != "") {
  563. if( typeof( jQuery ) != 'undefined' ){
  564. jQuery(element).css(prop, value);
  565. }
  566. } else {
  567. if( typeof( jQuery ) != 'undefined' ){
  568. return jQuery(element).css(prop);
  569. }
  570. }
  571. },
  572. cssmultiple: function(element, propval) {
  573. if( typeof( jQuery ) != 'undefined' ){
  574. return jQuery(element).css(propval);
  575. }
  576. },
  577. offset: function(element) {
  578. var p;
  579. if( typeof( jQuery ) != 'undefined' ){
  580. p = jQuery(element).offset();
  581. }
  582. return p;
  583. },
  584. position: function(element) {
  585. var p;
  586. if( typeof( jQuery ) != 'undefined' ){
  587. p = jQuery(element).position();
  588. }
  589. return p;
  590. },
  591. width: function(element, s) {
  592. if (s != null && s != "") {
  593. if( typeof( jQuery ) != 'undefined' ){
  594. jQuery(element).width(s);
  595. }
  596. } else {
  597. if( typeof( jQuery ) != 'undefined' ){
  598. return jQuery(element).width();
  599. }
  600. }
  601. },
  602. height: function(element, s) {
  603. if (s != null && s != "") {
  604. if( typeof( jQuery ) != 'undefined' ){
  605. jQuery(element).height(s);
  606. }
  607. } else {
  608. if( typeof( jQuery ) != 'undefined' ){
  609. return jQuery(element).height();
  610. }
  611. }
  612. },
  613. toggleClass: function(element, cName) {
  614. if( typeof( jQuery ) != 'undefined' ){
  615. jQuery(element).toggleClass(cName);
  616. }
  617. },
  618. each:function(element, return_function) {
  619. if( typeof( jQuery ) != 'undefined' ){
  620. jQuery(element).each(return_function);
  621. }
  622. },
  623. html: function(element, str) {
  624. var e;
  625. if( typeof( jQuery ) != 'undefined' ){
  626. e = jQuery(element).html();
  627. return e;
  628. }
  629. if (str != null && str != "") {
  630. if( typeof( jQuery ) != 'undefined' ){
  631. jQuery(element).html(str);
  632. }
  633. } else {
  634. var e;
  635. if( typeof( jQuery ) != 'undefined' ){
  636. e = jQuery(element).html();
  637. return e;
  638. }
  639. }
  640. },
  641. find: function(element, selec) {
  642. if( typeof( jQuery ) != 'undefined' ){
  643. return jQuery(element).find(selec);
  644. }
  645. },
  646. stop: function(element) {
  647. if( typeof( jQuery ) != 'undefined' ){
  648. jQuery(element).stop();
  649. }
  650. },
  651. delay_animate: function(delay, element, duration, ease, att, callback_function) {
  652. if (VMM.Browser.device == "mobile" || VMM.Browser.device == "tablet") {
  653. var _tdd = Math.round((duration/1500)*10)/10,
  654. __duration = _tdd + 's';
  655. VMM.Lib.css(element, '-webkit-transition', 'all '+ __duration + ' ease');
  656. VMM.Lib.css(element, '-moz-transition', 'all '+ __duration + ' ease');
  657. VMM.Lib.css(element, '-o-transition', 'all '+ __duration + ' ease');
  658. VMM.Lib.css(element, '-ms-transition', 'all '+ __duration + ' ease');
  659. VMM.Lib.css(element, 'transition', 'all '+ __duration + ' ease');
  660. VMM.Lib.cssmultiple(element, _att);
  661. } else {
  662. if( typeof( jQuery ) != 'undefined' ){
  663. jQuery(element).delay(delay).animate(att, {duration:duration, easing:ease} );
  664. }
  665. }
  666. },
  667. animate: function(element, duration, ease, att, que, callback_function) {
  668. var _ease = "easein",
  669. _que = false,
  670. _duration = 1000,
  671. _att = {};
  672. if (duration != null) {
  673. if (duration < 1) {
  674. _duration = 1;
  675. } else {
  676. _duration = Math.round(duration);
  677. }
  678. }
  679. if (ease != null && ease != "") {
  680. _ease = ease;
  681. }
  682. if (que != null && que != "") {
  683. _que = que;
  684. }
  685. if (att != null) {
  686. _att = att
  687. } else {
  688. _att = {opacity: 0}
  689. }
  690. if (VMM.Browser.device == "mobile" || VMM.Browser.device == "tablet") {
  691. var _tdd = Math.round((_duration/1500)*10)/10,
  692. __duration = _tdd + 's';
  693. _ease = " cubic-bezier(0.33, 0.66, 0.66, 1)";
  694. //_ease = " ease-in-out";
  695. for (x in _att) {
  696. if (Object.prototype.hasOwnProperty.call(_att, x)) {
  697. trace(x + " to " + _att[x]);
  698. VMM.Lib.css(element, '-webkit-transition', x + ' ' + __duration + _ease);
  699. VMM.Lib.css(element, '-moz-transition', x + ' ' + __duration + _ease);
  700. VMM.Lib.css(element, '-o-transition', x + ' ' + __duration + _ease);
  701. VMM.Lib.css(element, '-ms-transition', x + ' ' + __duration + _ease);
  702. VMM.Lib.css(element, 'transition', x + ' ' + __duration + _ease);
  703. }
  704. }
  705. VMM.Lib.cssmultiple(element, _att);
  706. } else {
  707. if( typeof( jQuery ) != 'undefined' ){
  708. if (callback_function != null && callback_function != "") {
  709. jQuery(element).animate(_att, {queue:_que, duration:_duration, easing:_ease, complete:callback_function} );
  710. } else {
  711. jQuery(element).animate(_att, {queue:_que, duration:_duration, easing:_ease} );
  712. }
  713. }
  714. }
  715. }
  716. }
  717. }
  718. if( typeof( jQuery ) != 'undefined' ){
  719. /* XDR AJAX EXTENTION FOR jQuery
  720. https://github.com/jaubourg/ajaxHooks/blob/master/src/ajax/xdr.js
  721. ================================================== */
  722. (function( jQuery ) {
  723. if ( window.XDomainRequest ) {
  724. jQuery.ajaxTransport(function( s ) {
  725. if ( s.crossDomain && s.async ) {
  726. if ( s.timeout ) {
  727. s.xdrTimeout = s.timeout;
  728. delete s.timeout;
  729. }
  730. var xdr;
  731. return {
  732. send: function( _, complete ) {
  733. function callback( status, statusText, responses, responseHeaders ) {
  734. xdr.onload = xdr.onerror = xdr.ontimeout = jQuery.noop;
  735. xdr = undefined;
  736. complete( status, statusText, responses, responseHeaders );
  737. }
  738. xdr = new XDomainRequest();
  739. xdr.open( s.type, s.url );
  740. xdr.onload = function() {
  741. callback( 200, "OK", { text: xdr.responseText }, "Content-Type: " + xdr.contentType );
  742. };
  743. xdr.onerror = function() {
  744. callback( 404, "Not Found" );
  745. };
  746. if ( s.xdrTimeout ) {
  747. xdr.ontimeout = function() {
  748. callback( 0, "timeout" );
  749. };
  750. xdr.timeout = s.xdrTimeout;
  751. }
  752. xdr.send( ( s.hasContent && s.data ) || null );
  753. },
  754. abort: function() {
  755. if ( xdr ) {
  756. xdr.onerror = jQuery.noop();
  757. xdr.abort();
  758. }
  759. }
  760. };
  761. }
  762. });
  763. }
  764. })( jQuery );
  765. /* jQuery Easing v1.3
  766. http://gsgd.co.uk/sandbox/jquery/easing/
  767. ================================================== */
  768. jQuery.easing['jswing'] = jQuery.easing['swing'];
  769. jQuery.extend( jQuery.easing, {
  770. def: 'easeOutQuad',
  771. swing: function (x, t, b, c, d) {
  772. //alert(jQuery.easing.default);
  773. return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
  774. },
  775. easeInExpo: function (x, t, b, c, d) {
  776. return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
  777. },
  778. easeOutExpo: function (x, t, b, c, d) {
  779. return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
  780. },
  781. easeInOutExpo: function (x, t, b, c, d) {
  782. if (t==0) return b;
  783. if (t==d) return b+c;
  784. if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
  785. return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
  786. },
  787. easeInQuad: function (x, t, b, c, d) {
  788. return c*(t/=d)*t + b;
  789. },
  790. easeOutQuad: function (x, t, b, c, d) {
  791. return -c *(t/=d)*(t-2) + b;
  792. },
  793. easeInOutQuad: function (x, t, b, c, d) {
  794. if ((t/=d/2) < 1) return c/2*t*t + b;
  795. return -c/2 * ((--t)*(t-2) - 1) + b;
  796. }
  797. });
  798. }
  799. /* **********************************************
  800. Begin VMM.Browser.js
  801. ********************************************** */
  802. /* * DEVICE AND BROWSER DETECTION
  803. ================================================== */
  804. if(typeof VMM != 'undefined' && typeof VMM.Browser == 'undefined') {
  805. VMM.Browser = {
  806. init: function () {
  807. this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
  808. this.version = this.searchVersion(navigator.userAgent)
  809. || this.searchVersion(navigator.appVersion)
  810. || "an unknown version";
  811. this.tridentVersion = this.searchTridentVersion(navigator.userAgent);
  812. this.OS = this.searchString(this.dataOS) || "an unknown OS";
  813. this.device = this.searchDevice(navigator.userAgent);
  814. this.orientation = this.searchOrientation(window.orientation);
  815. },
  816. searchOrientation: function(orientation) {
  817. var orient = "";
  818. if ( orientation == 0 || orientation == 180) {
  819. orient = "portrait";
  820. } else if ( orientation == 90 || orientation == -90) {
  821. orient = "landscape";
  822. } else {
  823. orient = "normal";
  824. }
  825. return orient;
  826. },
  827. searchDevice: function(d) {
  828. var device = "";
  829. if (d.match(/Android/i) || d.match(/iPhone|iPod/i)) {
  830. device = "mobile";
  831. } else if (d.match(/iPad/i)) {
  832. device = "tablet";
  833. } else if (d.match(/BlackBerry/i) || d.match(/IEMobile/i)) {
  834. device = "other mobile";
  835. } else {
  836. device = "desktop";
  837. }
  838. return device;
  839. },
  840. searchString: function (data) {
  841. for (var i=0;i<data.length;i++) {
  842. var dataString = data[i].string,
  843. dataProp = data[i].prop;
  844. this.versionSearchString = data[i].versionSearch || data[i].identity;
  845. if (dataString) {
  846. if (dataString.indexOf(data[i].subString) != -1) {
  847. return data[i].identity;
  848. }
  849. } else if (dataProp) {
  850. return data[i].identity;
  851. }
  852. }
  853. },
  854. searchVersion: function (dataString) {
  855. var index = dataString.indexOf(this.versionSearchString);
  856. if (index == -1) return;
  857. return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
  858. },
  859. searchTridentVersion: function (dataString) {
  860. var index = dataString.indexOf("Trident/");
  861. if (index == -1) return 0;
  862. return parseFloat(dataString.substring(index + 8));
  863. },
  864. dataBrowser: [
  865. {
  866. string: navigator.userAgent,
  867. subString: "Chrome",
  868. identity: "Chrome"
  869. },
  870. { string: navigator.userAgent,
  871. subString: "OmniWeb",
  872. versionSearch: "OmniWeb/",
  873. identity: "OmniWeb"
  874. },
  875. {
  876. string: navigator.vendor,
  877. subString: "Apple",
  878. identity: "Safari",
  879. versionSearch: "Version"
  880. },
  881. {
  882. prop: window.opera,
  883. identity: "Opera",
  884. versionSearch: "Version"
  885. },
  886. {
  887. string: navigator.vendor,
  888. subString: "iCab",
  889. identity: "iCab"
  890. },
  891. {
  892. string: navigator.vendor,
  893. subString: "KDE",
  894. identity: "Konqueror"
  895. },
  896. {
  897. string: navigator.userAgent,
  898. subString: "Firefox",
  899. identity: "Firefox"
  900. },
  901. {
  902. string: navigator.vendor,
  903. subString: "Camino",
  904. identity: "Camino"
  905. },
  906. { // for newer Netscapes (6+)
  907. string: navigator.userAgent,
  908. subString: "Netscape",
  909. identity: "Netscape"
  910. },
  911. {
  912. string: navigator.userAgent,
  913. subString: "MSIE",
  914. identity: "Explorer",
  915. versionSearch: "MSIE"
  916. },
  917. {
  918. string: navigator.userAgent,
  919. subString: "Gecko",
  920. identity: "Mozilla",
  921. versionSearch: "rv"
  922. },
  923. { // for older Netscapes (4-)
  924. string: navigator.userAgent,
  925. subString: "Mozilla",
  926. identity: "Netscape",
  927. versionSearch: "Mozilla"
  928. }
  929. ],
  930. dataOS : [
  931. {
  932. string: navigator.platform,
  933. subString: "Win",
  934. identity: "Windows"
  935. },
  936. {
  937. string: navigator.platform,
  938. subString: "Mac",
  939. identity: "Mac"
  940. },
  941. {
  942. string: navigator.userAgent,
  943. subString: "iPhone",
  944. identity: "iPhone/iPod"
  945. },
  946. {
  947. string: navigator.userAgent,
  948. subString: "iPad",
  949. identity: "iPad"
  950. },
  951. {
  952. string: navigator.platform,
  953. subString: "Linux",
  954. identity: "Linux"
  955. }
  956. ]
  957. }
  958. VMM.Browser.init();
  959. }
  960. /* **********************************************
  961. Begin VMM.FileExtention.js
  962. ********************************************** */
  963. /* * File Extention
  964. ================================================== */
  965. if(typeof VMM != 'undefined' && typeof VMM.FileExtention == 'undefined') {
  966. VMM.FileExtention = {
  967. googleDocType: function(url) {
  968. var fileName = url.replace(/\s\s*$/, ''),
  969. fileExtension = "",
  970. validFileExtensions = ["DOC","DOCX","XLS","XLSX","PPT","PPTX","PDF","PAGES","AI","PSD","TIFF","DXF","SVG","EPS","PS","TTF","XPS","ZIP","RAR"],
  971. flag = false;
  972. fileExtension = fileName.substr(fileName.length - 5, 5);
  973. for (var i = 0; i < validFileExtensions.length; i++) {
  974. if (fileExtension.toLowerCase().match(validFileExtensions[i].toString().toLowerCase()) || fileName.match("docs.google.com") ) {
  975. flag = true;
  976. }
  977. }
  978. return flag;
  979. }
  980. }
  981. }
  982. /* **********************************************
  983. Begin VMM.Date.js
  984. ********************************************** */
  985. /* * Utilities and Useful Functions
  986. ================================================== */
  987. if(typeof VMM != 'undefined' && typeof VMM.Date == 'undefined') {
  988. VMM.Date = ({
  989. init: function() {
  990. return this;
  991. },
  992. dateformats: {
  993. year: "yyyy",
  994. month_short: "mmm",
  995. month: "mmmm yyyy",
  996. full_short: "mmm d",
  997. full: "mmmm d',' yyyy",
  998. time_short: "h:MM:ss TT",
  999. time_no_seconds_short: "h:MM TT",
  1000. time_no_seconds_small_date: "h:MM TT'<br/><small>'mmmm d',' yyyy'</small>'",
  1001. full_long: "mmm d',' yyyy 'at' hh:MM TT",
  1002. full_long_small_date: "hh:MM TT'<br/><small>mmm d',' yyyy'</small>'"
  1003. },
  1004. month: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  1005. month_abbr: ["Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."],
  1006. day: ["Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  1007. day_abbr: ["Sun.", "Mon.", "Tues.", "Wed.", "Thurs.", "Fri.", "Sat."],
  1008. hour: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
  1009. hour_suffix: ["am"],
  1010. //B.C.
  1011. bc_format: {
  1012. year: "yyyy",
  1013. month_short: "mmm",
  1014. month: "mmmm yyyy",
  1015. full_short: "mmm d",
  1016. full: "mmmm d',' yyyy",
  1017. time_no_seconds_short: "h:MM TT",
  1018. time_no_seconds_small_date: "dddd', 'h:MM TT'<br/><small>'mmmm d',' yyyy'</small>'",
  1019. full_long: "dddd',' mmm d',' yyyy 'at' hh:MM TT",
  1020. full_long_small_date: "hh:MM TT'<br/><small>'dddd',' mmm d',' yyyy'</small>'"
  1021. },
  1022. setLanguage: function(lang) {
  1023. trace("SET DATE LANGUAGE");
  1024. VMM.Date.dateformats = lang.dateformats;
  1025. VMM.Date.month = lang.date.month;
  1026. VMM.Date.month_abbr = lang.date.month_abbr;
  1027. VMM.Date.day = lang.date.day;
  1028. VMM.Date.day_abbr = lang.date.day_abbr;
  1029. dateFormat.i18n.dayNames = lang.date.day_abbr.concat(lang.date.day);
  1030. dateFormat.i18n.monthNames = lang.date.month_abbr.concat(lang.date.month);
  1031. },
  1032. parse: function(d, precision) {
  1033. "use strict";
  1034. var date,
  1035. date_array,
  1036. time_array,
  1037. time_parse,
  1038. p = {
  1039. year: false,
  1040. month: false,
  1041. day: false,
  1042. hour: false,
  1043. minute: false,
  1044. second: false,
  1045. millisecond: false
  1046. };
  1047. if (type.of(d) == "date") {
  1048. trace("DEBUG THIS, ITs A DATE");
  1049. date = d;
  1050. } else {
  1051. date = new Date(0);
  1052. date.setMonth(0); date.setDate(1); date.setHours(0); date.setMinutes(0); date.setSeconds(0); date.setMilliseconds(0);
  1053. if ( d.match(/,/gi) ) {
  1054. date_array = d.split(",");
  1055. for(var i = 0; i < date_array.length; i++) {
  1056. date_array[i] = parseInt(date_array[i], 10);
  1057. }
  1058. if (date_array[0]) {
  1059. date.setFullYear(date_array[0]);
  1060. p.year = true;
  1061. }
  1062. if (date_array[1]) {
  1063. date.setMonth(date_array[1] - 1);
  1064. p.month = true;
  1065. }
  1066. if (date_array[2]) {
  1067. date.setDate(date_array[2]);
  1068. p.day = true;
  1069. }
  1070. if (date_array[3]) {
  1071. date.setHours(date_array[3]);
  1072. p.hour = true;
  1073. }
  1074. if (date_array[4]) {
  1075. date.setMinutes(date_array[4]);
  1076. p.minute = true;
  1077. }
  1078. if (date_array[5]) {
  1079. date.setSeconds(date_array[5]);
  1080. if (date_array[5] >= 1) {
  1081. p.second = true;
  1082. }
  1083. }
  1084. if (date_array[6]) {
  1085. date.setMilliseconds(date_array[6]);
  1086. if (date_array[6] >= 1) {
  1087. p.millisecond = true;
  1088. }
  1089. }
  1090. } else if (d.match("/")) {
  1091. if (d.match(" ")) {
  1092. time_parse = d.split(" ");
  1093. if (d.match(":")) {
  1094. time_array = time_parse[1].split(":");
  1095. if (time_array[0] >= 0 ) {
  1096. date.setHours(time_array[0]);
  1097. p.hour = true;
  1098. }
  1099. if (time_array[1] >= 0) {
  1100. date.setMinutes(time_array[1]);
  1101. p.minute = true;
  1102. }
  1103. if (time_array[2] >= 0) {
  1104. date.setSeconds(time_array[2]);
  1105. p.second = true;
  1106. }
  1107. if (time_array[3] >= 0) {
  1108. date.setMilliseconds(time_array[3]);
  1109. p.millisecond = true;
  1110. }
  1111. }
  1112. date_array = time_parse[0].split("/");
  1113. } else {
  1114. date_array = d.split("/");
  1115. }
  1116. if (date_array[2]) {
  1117. date.setFullYear(date_array[2]);
  1118. p.year = true;
  1119. }
  1120. if (date_array[0] >= 0) {
  1121. var month = date_array[0] - 1;
  1122. date.setMonth(month);
  1123. // if (date.getMonth() != month) {
  1124. // date.setMonth(month); // WTF javascript?
  1125. // }
  1126. p.month = true;
  1127. }
  1128. if (date_array[1] >= 0) {
  1129. if (date_array[1].length > 2) {
  1130. date.setFullYear(date_array[1]);
  1131. p.year = true;
  1132. } else {
  1133. date.setDate(date_array[1]);
  1134. p.day = true;
  1135. }
  1136. }
  1137. } else if (d.match("now")) {
  1138. var now = new Date();
  1139. date.setFullYear(now.getFullYear());
  1140. p.year = true;
  1141. date.setMonth(now.getMonth());
  1142. p.month = true;
  1143. date.setDate(now.getDate());
  1144. p.day = true;
  1145. if (d.match("hours")) {
  1146. date.setHours(now.getHours());
  1147. p.hour = true;
  1148. }
  1149. if (d.match("minutes")) {
  1150. date.setHours(now.getHours());
  1151. date.setMinutes(now.getMinutes());
  1152. p.hour = true;
  1153. p.minute = true;
  1154. }
  1155. if (d.match("seconds")) {
  1156. date.setHours(now.getHours());
  1157. date.setMinutes(now.getMinutes());
  1158. date.setSeconds(now.getSeconds());
  1159. p.hour = true;
  1160. p.minute = true;
  1161. p.second = true;
  1162. }
  1163. if (d.match("milliseconds")) {
  1164. date.setHours(now.getHours());
  1165. date.setMinutes(now.getMinutes());
  1166. date.setSeconds(now.getSeconds());
  1167. date.setMilliseconds(now.getMilliseconds());
  1168. p.hour = true;
  1169. p.minute = true;
  1170. p.second = true;
  1171. p.millisecond = true;
  1172. }
  1173. } else if (d.length <= 8) {
  1174. p.year = true;
  1175. date.setFullYear(parseInt(d, 10));
  1176. date.setMonth(0);
  1177. date.setDate(1);
  1178. date.setHours(0);
  1179. date.setMinutes(0);
  1180. date.setSeconds(0);
  1181. date.setMilliseconds(0);
  1182. } else if (d.match("T")) {
  1183. if (navigator.userAgent.match(/MSIE\s(?!9.0)/)) {
  1184. // IE 8 < Won't accept dates with a "-" in them.
  1185. time_parse = d.split("T");
  1186. if (d.match(":")) {
  1187. time_array = time_parse[1].split(":");
  1188. if (time_array[0] >= 1) {
  1189. date.setHours(time_array[0]);
  1190. p.hour = true;
  1191. }
  1192. if (time_array[1] >= 1) {
  1193. date.setMinutes(time_array[1]);
  1194. p.minute = true;
  1195. }
  1196. if (time_array[2] >= 1) {
  1197. date.setSeconds(time_array[2]);
  1198. if (time_array[2] >= 1) {
  1199. p.second = true;
  1200. }
  1201. }
  1202. if (time_array[3] >= 1) {
  1203. date.setMilliseconds(time_array[3]);
  1204. if (time_array[3] >= 1) {
  1205. p.millisecond = true;
  1206. }
  1207. }
  1208. }
  1209. date_array = time_parse[0].split("-");
  1210. if (date_array[0]) {
  1211. date.setFullYear(date_array[0]);
  1212. p.year = true;
  1213. }
  1214. if (date_array[1] >= 0) {
  1215. date.setMonth(date_array[1] - 1);
  1216. p.month = true;
  1217. }
  1218. if (date_array[2] >= 0) {
  1219. date.setDate(date_array[2]);
  1220. p.day = true;
  1221. }
  1222. } else {
  1223. date = new Date(Date.parse(d));
  1224. p.year = true;
  1225. p.month = true;
  1226. p.day = true;
  1227. p.hour = true;
  1228. p.minute = true;
  1229. if (date.getSeconds() >= 1) {
  1230. p.second = true;
  1231. }
  1232. if (date.getMilliseconds() >= 1) {
  1233. p.millisecond = true;
  1234. }
  1235. }
  1236. } else {
  1237. date = new Date(
  1238. parseInt(d.slice(0,4), 10),
  1239. parseInt(d.slice(4,6), 10) - 1,
  1240. parseInt(d.slice(6,8), 10),
  1241. parseInt(d.slice(8,10), 10),
  1242. parseInt(d.slice(10,12), 10)
  1243. );
  1244. p.year = true;
  1245. p.month = true;
  1246. p.day = true;
  1247. p.hour = true;
  1248. p.minute = true;
  1249. if (date.getSeconds() >= 1) {
  1250. p.second = true;
  1251. }
  1252. if (date.getMilliseconds() >= 1) {
  1253. p.millisecond = true;
  1254. }
  1255. }
  1256. }
  1257. if (precision != null && precision != "") {
  1258. return {
  1259. date: date,
  1260. precision: p
  1261. };
  1262. } else {
  1263. return date;
  1264. }
  1265. },
  1266. prettyDate: function(d, is_abbr, p, d2) {
  1267. var _date,
  1268. _date2,
  1269. format,
  1270. bc_check,
  1271. is_pair = false,
  1272. bc_original,
  1273. bc_number,
  1274. bc_string;
  1275. if (d2 != null && d2 != "" && typeof d2 != 'undefined') {
  1276. is_pair = true;
  1277. trace("D2 " + d2);
  1278. }
  1279. if (type.of(d) == "date") {
  1280. if (type.of(p) == "object") {
  1281. if (p.millisecond || p.second && d.getSeconds() >= 1) {
  1282. // YEAR MONTH DAY HOUR MINUTE
  1283. if (is_abbr){
  1284. format = VMM.Date.dateformats.time_short;
  1285. } else {
  1286. format = VMM.Date.dateformats.time_short;
  1287. }
  1288. } else if (p.minute) {
  1289. // YEAR MONTH DAY HOUR MINUTE
  1290. if (is_abbr){
  1291. format = VMM.Date.dateformats.time_no_seconds_short;
  1292. } else {
  1293. format = VMM.Date.dateformats.time_no_seconds_small_date;
  1294. }
  1295. } else if (p.hour) {
  1296. // YEAR MONTH DAY HOUR
  1297. if (is_abbr) {
  1298. format = VMM.Date.dateformats.time_no_seconds_short;
  1299. } else {
  1300. format = VMM.Date.dateformats.time_no_seconds_small_date;
  1301. }
  1302. } else if (p.day) {
  1303. // YEAR MONTH DAY
  1304. if (is_abbr) {
  1305. format = VMM.Date.dateformats.full_short;
  1306. } else {
  1307. format = VMM.Date.dateformats.full;
  1308. }
  1309. } else if (p.month) {
  1310. // YEAR MONTH
  1311. if (is_abbr) {
  1312. format = VMM.Date.dateformats.month_short;
  1313. } else {
  1314. format = VMM.Date.dateformats.month;
  1315. }
  1316. } else if (p.year) {
  1317. format = VMM.Date.dateformats.year;
  1318. } else {
  1319. format = VMM.Date.dateformats.year;
  1320. }
  1321. } else {
  1322. if (d.getMonth() === 0 && d.getDate() == 1 && d.getHours() === 0 && d.getMinutes() === 0 ) {
  1323. // YEAR ONLY
  1324. format = VMM.Date.dateformats.year;
  1325. } else if (d.getDate() <= 1 && d.getHours() === 0 && d.getMinutes() === 0) {
  1326. // YEAR MONTH
  1327. if (is_abbr) {
  1328. format = VMM.Date.dateformats.month_short;
  1329. } else {
  1330. format = VMM.Date.dateformats.month;
  1331. }
  1332. } else if (d.getHours() === 0 && d.getMinutes() === 0) {
  1333. // YEAR MONTH DAY
  1334. if (is_abbr) {
  1335. format = VMM.Date.dateformats.full_short;
  1336. } else {
  1337. format = VMM.Date.dateformats.full;
  1338. }
  1339. } else if (d.getMinutes() === 0) {
  1340. // YEAR MONTH DAY HOUR
  1341. if (is_abbr) {
  1342. format = VMM.Date.dateformats.time_no_seconds_short;
  1343. } else {
  1344. format = VMM.Date.dateformats.time_no_seconds_small_date;
  1345. }
  1346. } else {
  1347. // YEAR MONTH DAY HOUR MINUTE
  1348. if (is_abbr){
  1349. format = VMM.Date.dateformats.time_no_seconds_short;
  1350. } else {
  1351. format = VMM.Date.dateformats.full_long;
  1352. }
  1353. }
  1354. }
  1355. _date = dateFormat(d, format, false);
  1356. //_date = "Jan"
  1357. bc_check = _date.split(" ");
  1358. // BC TIME SUPPORT
  1359. for(var i = 0; i < bc_check.length; i++) {
  1360. if ( parseInt(bc_check[i], 10) < 0 ) {
  1361. trace("YEAR IS BC");
  1362. bc_original = bc_check[i];
  1363. bc_number = Math.abs( parseInt(bc_check[i], 10) );
  1364. bc_string = bc_number.toString() + " B.C.";
  1365. _date = _date.replace(bc_original, bc_string);
  1366. }
  1367. }
  1368. if (is_pair) {
  1369. _date2 = dateFormat(d2, format, false);
  1370. bc_check = _date2.split(" ");
  1371. // BC TIME SUPPORT
  1372. for(var j = 0; j < bc_check.length; j++) {
  1373. if ( parseInt(bc_check[j], 10) < 0 ) {
  1374. trace("YEAR IS BC");
  1375. bc_original = bc_check[j];
  1376. bc_number = Math.abs( parseInt(bc_check[j], 10) );
  1377. bc_string = bc_number.toString() + " B.C.";
  1378. _date2 = _date2.replace(bc_original, bc_string);
  1379. }
  1380. }
  1381. }
  1382. } else {
  1383. trace("NOT A VALID DATE?");
  1384. trace(d);
  1385. }
  1386. if (is_pair) {
  1387. return _date + " &mdash; " + _date2;
  1388. } else {
  1389. return _date;
  1390. }
  1391. }
  1392. }).init();
  1393. /*
  1394. * Date Format 1.2.3
  1395. * (c) 2007-2009 Steven Levithan <stevenlevithan.com>
  1396. * MIT license
  1397. *
  1398. * Includes enhancements by Scott Trenda <scott.trenda.net>
  1399. * and Kris Kowal <cixar.com/~kris.kowal/>
  1400. *
  1401. * Accepts a date, a mask, or a date and a mask.
  1402. * Returns a formatted version of the given date.
  1403. * The date defaults to the current date/time.
  1404. * The mask defaults to dateFormat.masks.default.
  1405. */
  1406. var dateFormat = function () {
  1407. var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[WLloSZ]|"[^"]*"|'[^']*'/g,
  1408. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
  1409. timezoneClip = /[^-+\dA-Z]/g,
  1410. pad = function (val, len) {
  1411. val = String(val);
  1412. len = len || 2;
  1413. while (val.length < len) val = "0" + val;
  1414. return val;
  1415. };
  1416. // Regexes and supporting functions are cached through closure
  1417. return function (date, mask, utc) {
  1418. var dF = dateFormat;
  1419. // You can't provide utc if you skip other args (use the "UTC:" mask prefix)
  1420. if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
  1421. mask = date;
  1422. date = undefined;
  1423. }
  1424. // Passing date through Date applies Date.parse, if necessary
  1425. // Caused problems in IE
  1426. // date = date ? new Date(date) : new Date;
  1427. if (isNaN(date)) {
  1428. trace("invalid date " + date);
  1429. //return "";
  1430. }
  1431. mask = String(dF.masks[mask] || mask || dF.masks["default"]);
  1432. // Allow setting the utc argument via the mask
  1433. if (mask.slice(0, 4) == "UTC:") {
  1434. mask = mask.slice(4);
  1435. utc = true;
  1436. }
  1437. var _ = utc ? "getUTC" : "get",
  1438. d = date[_ + "Date"](),
  1439. D = date[_ + "Day"](),
  1440. m = date[_ + "Month"](),
  1441. y = date[_ + "FullYear"](),
  1442. H = date[_ + "Hours"](),
  1443. M = date[_ + "Minutes"](),
  1444. s = date[_ + "Seconds"](),
  1445. L = date[_ + "Milliseconds"](),
  1446. W = date.getWeek(),
  1447. o = utc ? 0 : date.getTimezoneOffset(),
  1448. flags = {
  1449. d: d,
  1450. dd: pad(d),
  1451. ddd: dF.i18n.dayNames[D],
  1452. dddd: dF.i18n.dayNames[D + 7],
  1453. m: m + 1,
  1454. mm: pad(m + 1),
  1455. mmm: dF.i18n.monthNames[m],
  1456. mmmm: dF.i18n.monthNames[m + 12],
  1457. yy: String(y).slice(2),
  1458. yyyy: y,
  1459. h: H % 12 || 12,
  1460. hh: pad(H % 12 || 12),
  1461. H: H,
  1462. HH: pad(H),
  1463. M: M,
  1464. MM: pad(M),
  1465. s: s,
  1466. ss: pad(s),
  1467. l: pad(L, 3),
  1468. L: pad(L > 99 ? Math.round(L / 10) : L),
  1469. t: H < 12 ? "a" : "p",
  1470. tt: H < 12 ? "am" : "pm",
  1471. T: H < 12 ? "A" : "P",
  1472. TT: H < 12 ? "AM" : "PM",
  1473. Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
  1474. o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
  1475. S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10],
  1476. W: W
  1477. };
  1478. return mask.replace(token, function ($0) {
  1479. return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
  1480. });
  1481. };
  1482. }();
  1483. // Some common format strings
  1484. dateFormat.masks = {
  1485. "default": "ddd mmm dd yyyy HH:MM:ss",
  1486. shortDate: "m/d/yy",
  1487. mediumDate: "mmm d, yyyy",
  1488. longDate: "mmmm d, yyyy",
  1489. fullDate: "dddd, mmmm d, yyyy",
  1490. shortTime: "h:MM TT",
  1491. mediumTime: "h:MM:ss TT",
  1492. longTime: "h:MM:ss TT Z",
  1493. isoDate: "yyyy-mm-dd",
  1494. isoTime: "HH:MM:ss",
  1495. isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
  1496. isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
  1497. };
  1498. // Internationalization strings
  1499. dateFormat.i18n = {
  1500. dayNames: [
  1501. "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
  1502. "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
  1503. ],
  1504. monthNames: [
  1505. "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
  1506. "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
  1507. ]
  1508. };
  1509. // For convenience...
  1510. Date.prototype.format = function (mask, utc) {
  1511. return dateFormat(this, mask, utc);
  1512. };
  1513. }
  1514. /* **********************************************
  1515. Begin VMM.Util.js
  1516. ********************************************** */
  1517. /* * Utilities and Useful Functions
  1518. ================================================== */
  1519. if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
  1520. VMM.Util = ({
  1521. init: function() {
  1522. return this;
  1523. },
  1524. removeRange: function(array, from, to) { // rather than change Array.prototype; Thanks Jeff McWhirter for nudge
  1525. var rest = array.slice((to || from) + 1 || array.length);
  1526. array.length = from < 0 ? array.length + from : from;
  1527. return array.push.apply(array, rest);
  1528. },
  1529. /* * CORRECT PROTOCOL (DOES NOT WORK)
  1530. ================================================== */
  1531. correctProtocol: function(url) {
  1532. var loc = (window.parent.location.protocol).toString(),
  1533. prefix = "",
  1534. the_url = url.split("://", 2);
  1535. if (loc.match("http")) {
  1536. prefix = loc;
  1537. } else {
  1538. prefix = "https";
  1539. }
  1540. return prefix + "://" + the_url[1];
  1541. },
  1542. /* * MERGE CONFIG
  1543. ================================================== */
  1544. mergeConfig: function(config_main, config_to_merge) {
  1545. var x;
  1546. for (x in config_to_merge) {
  1547. if (Object.prototype.hasOwnProperty.call(config_to_merge, x)) {
  1548. config_main[x] = config_to_merge[x];
  1549. }
  1550. }
  1551. return config_main;
  1552. },
  1553. /* * GET OBJECT ATTRIBUTE BY INDEX
  1554. ================================================== */
  1555. getObjectAttributeByIndex: function(obj, index) {
  1556. if(typeof obj != 'undefined') {
  1557. var i = 0;
  1558. for (var attr in obj){
  1559. if (index === i){
  1560. return obj[attr];
  1561. }
  1562. i++;
  1563. }
  1564. return "";
  1565. } else {
  1566. return "";
  1567. }
  1568. },
  1569. /* * ORDINAL
  1570. ================================================== */
  1571. ordinal: function(n) {
  1572. return ["th","st","nd","rd"][(!( ((n%10) >3) || (Math.floor(n%100/10)==1)) ) * (n%10)];
  1573. },
  1574. /* * RANDOM BETWEEN
  1575. ================================================== */
  1576. //VMM.Util.randomBetween(1, 3)
  1577. randomBetween: function(min, max) {
  1578. return Math.floor(Math.random() * (max - min + 1) + min);
  1579. },
  1580. /* * AVERAGE
  1581. * http://jsfromhell.com/array/average
  1582. * var x = VMM.Util.average([2, 3, 4]);
  1583. * VMM.Util.average([2, 3, 4]).mean
  1584. ================================================== */
  1585. average: function(a) {
  1586. var r = {mean: 0, variance: 0, deviation: 0}, t = a.length;
  1587. for(var m, s = 0, l = t; l--; s += a[l]);
  1588. for(m = r.mean = s / t, l = t, s = 0; l--; s += Math.pow(a[l] - m, 2));
  1589. return r.deviation = Math.sqrt(r.variance = s / t), r;
  1590. },
  1591. /* * CUSTOM SORT
  1592. ================================================== */
  1593. customSort: function(a, b) {
  1594. var a1= a, b1= b;
  1595. if(a1== b1) return 0;
  1596. return a1> b1? 1: -1;
  1597. },
  1598. /* * Remove Duplicates from Array
  1599. ================================================== */
  1600. deDupeArray: function(arr) {
  1601. var i,
  1602. len=arr.length,
  1603. out=[],
  1604. obj={};
  1605. for (i=0;i<len;i++) {
  1606. obj[arr[i]]=0;
  1607. }
  1608. for (i in obj) {
  1609. out.push(i);
  1610. }
  1611. return out;
  1612. },
  1613. /* * Returns a word count number
  1614. ================================================== */
  1615. wordCount: function(s) {
  1616. var fullStr = s + " ";
  1617. var initial_whitespace_rExp = /^[^A-Za-z0-9\'\-]+/gi;
  1618. var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
  1619. var non_alphanumerics_rExp = /[^A-Za-z0-9\'\-]+/gi;
  1620. var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
  1621. var splitString = cleanedStr.split(" ");
  1622. var word_count = splitString.length -1;
  1623. if (fullStr.length <2) {
  1624. word_count = 0;
  1625. }
  1626. return word_count;
  1627. },
  1628. ratio: {
  1629. fit: function(w, h, ratio_w, ratio_h) {
  1630. //VMM.Util.ratio.fit(w, h, ratio_w, ratio_h).width;
  1631. var _fit = {width:0,height:0};
  1632. // TRY WIDTH FIRST
  1633. _fit.width = w;
  1634. //_fit.height = Math.round((h / ratio_h) * ratio_w);
  1635. _fit.height = Math.round((w / ratio_w) * ratio_h);
  1636. if (_fit.height > h) {
  1637. _fit.height = h;
  1638. //_fit.width = Math.round((w / ratio_w) * ratio_h);
  1639. _fit.width = Math.round((h / ratio_h) * ratio_w);
  1640. if (_fit.width > w) {
  1641. trace("FIT: DIDN'T FIT!!! ")
  1642. }
  1643. }
  1644. return _fit;
  1645. },
  1646. r16_9: function(w,h) {
  1647. //VMM.Util.ratio.r16_9(w, h) // Returns corresponding number
  1648. if (w !== null && w !== "") {
  1649. return Math.round((h / 16) * 9);
  1650. } else if (h !== null && h !== "") {
  1651. return Math.round((w / 9) * 16);
  1652. }
  1653. },
  1654. r4_3: function(w,h) {
  1655. if (w !== null && w !== "") {
  1656. return Math.round((h / 4) * 3);
  1657. } else if (h !== null && h !== "") {
  1658. return Math.round((w / 3) * 4);
  1659. }
  1660. }
  1661. },
  1662. doubledigit: function(n) {
  1663. return (n < 10 ? '0' : '') + n;
  1664. },
  1665. /* * Returns a truncated segement of a long string of between min and max words. If possible, ends on a period (otherwise goes to max).
  1666. ================================================== */
  1667. truncateWords: function(s, min, max) {
  1668. if (!min) min = 30;
  1669. if (!max) max = min;
  1670. var initial_whitespace_rExp = /^[^A-Za-z0-9\'\-]+/gi;
  1671. var left_trimmedStr = s.replace(initial_whitespace_rExp, "");
  1672. var words = left_trimmedStr.split(" ");
  1673. var result = [];
  1674. min = Math.min(words.length, min);
  1675. max = Math.min(words.length, max);
  1676. for (var i = 0; i<min; i++) {
  1677. result.push(words[i]);
  1678. }
  1679. for (var j = min; i<max; i++) {
  1680. var word = words[i];
  1681. result.push(word);
  1682. if (word.charAt(word.length-1) == '.') {
  1683. break;
  1684. }
  1685. }
  1686. return (result.join(' '));
  1687. },
  1688. /* * Turns plain text links into real links
  1689. ================================================== */
  1690. linkify: function(text,targets,is_touch) {
  1691. // http://, https://, ftp://
  1692. var urlPattern = /\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim;
  1693. // www. sans http:// or https://
  1694. var pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
  1695. // Email addresses
  1696. var emailAddressPattern = /(([a-zA-Z0-9_\-\.]+)@[a-zA-Z_]+?(?:\.[a-zA-Z]{2,6}))+/gim;
  1697. return text
  1698. .replace(urlPattern, "<a target='_blank' href='$&' onclick='void(0)'>$&</a>")
  1699. .replace(pseudoUrlPattern, "$1<a target='_blank' onclick='void(0)' href='http://$2'>$2</a>")
  1700. .replace(emailAddressPattern, "<a target='_blank' onclick='void(0)' href='mailto:$1'>$1</a>");
  1701. },
  1702. linkify_with_twitter: function(text,targets,is_touch) {
  1703. // http://, https://, ftp://
  1704. var urlPattern = /\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim;
  1705. var url_pattern = /(\()((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\))|(\[)((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\])|(\{)((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\})|(<|&(?:lt|#60|#x3c);)((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(>|&(?:gt|#62|#x3e);)|((?:^|[^=\s'"\]])\s*['"]?|[^=\s]\s+)(\b(?:ht|f)tps?:\/\/[a-z0-9\-._~!$'()*+,;=:\/?#[\]@%]+(?:(?!&(?:gt|#0*62|#x0*3e);|&(?:amp|apos|quot|#0*3[49]|#x0*2[27]);[.!&',:?;]?(?:[^a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]|$))&[a-z0-9\-._~!$'()*+,;=:\/?#[\]@%]*)*[a-z0-9\-_~$()*+=\/#[\]@%])/img;
  1706. var url_replace = '$1$4$7$10$13<a href="$2$5$8$11$14" target="_blank" class="hyphenate">$2$5$8$11$14</a>$3$6$9$12';
  1707. // www. sans http:// or https://
  1708. var pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
  1709. function replaceURLWithHTMLLinks(text) {
  1710. var exp = /(\b(https?|ftp|file):\/\/([-A-Z0-9+&@#%?=~_|!:,.;]*)([-A-Z0-9+&@#%?\/=~_|!:,.;]*)[-A-Z0-9+&@#\/%=~_|])/ig;
  1711. return text.replace(exp, "<a href='$1' target='_blank'>$3</a>");
  1712. }
  1713. // Email addresses
  1714. var emailAddressPattern = /(([a-zA-Z0-9_\-\.]+)@[a-zA-Z_]+?(?:\.[a-zA-Z]{2,6}))+/gim;
  1715. //var twitterHandlePattern = /(@([\w]+))/g;
  1716. var twitterHandlePattern = /\B@([\w-]+)/gm;
  1717. var twitterSearchPattern = /(#([\w]+))/g;
  1718. return text
  1719. //.replace(urlPattern, "<a target='_blank' href='$&' onclick='void(0)'>$&</a>")
  1720. .replace(url_pattern, url_replace)
  1721. .replace(pseudoUrlPattern, "$1<a target='_blank' class='hyphenate' onclick='void(0)' href='http://$2'>$2</a>")
  1722. .replace(emailAddressPattern, "<a target='_blank' onclick='void(0)' href='mailto:$1'>$1</a>")
  1723. .replace(twitterHandlePattern, "<a href='http://twitter.com/$1' target='_blank' onclick='void(0)'>@$1</a>");
  1724. // TURN THIS BACK ON TO AUTOMAGICALLY LINK HASHTAGS TO TWITTER SEARCH
  1725. //.replace(twitterSearchPattern, "<a href='http://twitter.com/search?q=%23$2' target='_blank' 'void(0)'>$1</a>");
  1726. },
  1727. linkify_wikipedia: function(text) {
  1728. var urlPattern = /<i[^>]*>(.*?)<\/i>/gim;
  1729. return text
  1730. .replace(urlPattern, "<a target='_blank' href='http://en.wikipedia.org/wiki/$&' onclick='void(0)'>$&</a>")
  1731. .replace(/<i\b[^>]*>/gim, "")
  1732. .replace(/<\/i>/gim, "")
  1733. .replace(/<b\b[^>]*>/gim, "")
  1734. .replace(/<\/b>/gim, "");
  1735. },
  1736. /* * Turns plain text links into real links
  1737. ================================================== */
  1738. // VMM.Util.unlinkify();
  1739. unlinkify: function(text) {
  1740. if(!text) return text;
  1741. text = text.replace(/<a\b[^>]*>/i,"");
  1742. text = text.replace(/<\/a>/i, "");
  1743. return text;
  1744. },
  1745. untagify: function(text) {
  1746. if (!text) {
  1747. return text;
  1748. }
  1749. text = text.replace(/<\/?\s*\w.*?>/g,"");
  1750. return text;
  1751. },
  1752. /* * TK
  1753. ================================================== */
  1754. nl2br: function(text) {
  1755. return text.replace(/(\r\n|[\r\n]|\\n|\\r)/g,"<br/>");
  1756. },
  1757. /* * Generate a Unique ID
  1758. ================================================== */
  1759. // VMM.Util.unique_ID(size);
  1760. unique_ID: function(size) {
  1761. var getRandomNumber = function(range) {
  1762. return Math.floor(Math.random() * range);
  1763. };
  1764. var getRandomChar = function() {
  1765. var chars = "abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ";
  1766. return chars.substr( getRandomNumber(62), 1 );
  1767. };
  1768. var randomID = function(size) {
  1769. var str = "";
  1770. for(var i = 0; i < size; i++) {
  1771. str += getRandomChar();
  1772. }
  1773. return str;
  1774. };
  1775. return randomID(size);
  1776. },
  1777. /* * Tells you if a number is even or not
  1778. ================================================== */
  1779. // VMM.Util.isEven(n)
  1780. isEven: function(n){
  1781. return (n%2 === 0) ? true : false;
  1782. },
  1783. /* * Get URL Variables
  1784. ================================================== */
  1785. // var somestring = VMM.Util.getUrlVars(str_url)["varname"];
  1786. getUrlVars: function(string) {
  1787. var str = string.toString();
  1788. if (str.match('&#038;')) {
  1789. str = str.replace("&#038;", "&");
  1790. } else if (str.match('&#38;')) {
  1791. str = str.replace("&#38;", "&");
  1792. } else if (str.match('&amp;')) {
  1793. str = str.replace("&amp;", "&");
  1794. }
  1795. var vars = [], hash;
  1796. var hashes = str.slice(str.indexOf('?') + 1).split('&');
  1797. for(var i = 0; i < hashes.length; i++) {
  1798. hash = hashes[i].split('=');
  1799. vars.push(hash[0]);
  1800. vars[hash[0]] = hash[1];
  1801. }
  1802. return vars;
  1803. },
  1804. /* * Cleans up strings to become real HTML
  1805. ================================================== */
  1806. toHTML: function(text) {
  1807. text = this.nl2br(text);
  1808. text = this.linkify(text);
  1809. return text.replace(/\s\s/g,"&nbsp;&nbsp;");
  1810. },
  1811. /* * Returns text strings as CamelCase
  1812. ================================================== */
  1813. toCamelCase: function(s,forceLowerCase) {
  1814. if(forceLowerCase !== false) forceLowerCase = true;
  1815. var sps = ((forceLowerCase) ? s.toLowerCase() : s).split(" ");
  1816. for(var i=0; i<sps.length; i++) {
  1817. sps[i] = sps[i].substr(0,1).toUpperCase() + sps[i].substr(1);
  1818. }
  1819. return sps.join(" ");
  1820. },
  1821. /* * Replaces dumb quote marks with smart ones
  1822. ================================================== */
  1823. properQuotes: function(str) {
  1824. return str.replace(/\"([^\"]*)\"/gi,"&#8220;$1&#8221;");
  1825. },
  1826. /* * Add Commas to numbers
  1827. ================================================== */
  1828. niceNumber: function(nStr){
  1829. nStr += '';
  1830. x = nStr.split('.');
  1831. x1 = x[0];
  1832. x2 = x.length > 1 ? '.' + x[1] : '';
  1833. var rgx = /(\d+)(\d{3})/;
  1834. while (rgx.test(x1)) {
  1835. x1 = x1.replace(rgx, '$1' + ',' + '$2');
  1836. }
  1837. return x1 + x2;
  1838. },
  1839. /* * Transform text to Title Case
  1840. ================================================== */
  1841. toTitleCase: function(t){
  1842. if ( VMM.Browser.browser == "Explorer" && parseInt(VMM.Browser.version, 10) >= 7) {
  1843. return t.replace("_", "%20");
  1844. } else {
  1845. var __TitleCase = {
  1846. __smallWords: ['a', 'an', 'and', 'as', 'at', 'but','by', 'en', 'for', 'if', 'in', 'of', 'on', 'or','the', 'to', 'v[.]?', 'via', 'vs[.]?'],
  1847. init: function() {
  1848. this.__smallRE = this.__smallWords.join('|');
  1849. this.__lowerCaseWordsRE = new RegExp('\\b(' + this.__smallRE + ')\\b', 'gi');
  1850. this.__firstWordRE = new RegExp('^([^a-zA-Z0-9 \\r\\n\\t]*)(' + this.__smallRE + ')\\b', 'gi');
  1851. this.__lastWordRE = new RegExp('\\b(' + this.__smallRE + ')([^a-zA-Z0-9 \\r\\n\\t]*)$', 'gi');
  1852. },
  1853. toTitleCase: function(string) {
  1854. var line = '';
  1855. var split = string.split(/([:.;?!][ ]|(?:[ ]|^)["“])/);
  1856. for (var i = 0; i < split.length; ++i) {
  1857. var s = split[i];
  1858. s = s.replace(/\b([a-zA-Z][a-z.'’]*)\b/g,this.__titleCaseDottedWordReplacer);
  1859. // lowercase the list of small words
  1860. s = s.replace(this.__lowerCaseWordsRE, this.__lowerReplacer);
  1861. // if the first word in the title is a small word then capitalize it
  1862. s = s.replace(this.__firstWordRE, this.__firstToUpperCase);
  1863. // if the last word in the title is a small word, then capitalize it
  1864. s = s.replace(this.__lastWordRE, this.__firstToUpperCase);
  1865. line += s;
  1866. }
  1867. // special cases
  1868. line = line.replace(/ V(s?)\. /g, ' v$1. ');
  1869. line = line.replace(/(['’])S\b/g, '$1s');
  1870. line = line.replace(/\b(AT&T|Q&A)\b/ig, this.__upperReplacer);
  1871. return line;
  1872. },
  1873. __titleCaseDottedWordReplacer: function (w) {
  1874. return (w.match(/[a-zA-Z][.][a-zA-Z]/)) ? w : __TitleCase.__firstToUpperCase(w);
  1875. },
  1876. __lowerReplacer: function (w) { return w.toLowerCase() },
  1877. __upperReplacer: function (w) { return w.toUpperCase() },
  1878. __firstToUpperCase: function (w) {
  1879. var split = w.split(/(^[^a-zA-Z0-9]*[a-zA-Z0-9])(.*)$/);
  1880. if (split[1]) {
  1881. split[1] = split[1].toUpperCase();
  1882. }
  1883. return split.join('');
  1884. }
  1885. };
  1886. __TitleCase.init();
  1887. t = t.replace(/_/g," ");
  1888. t = __TitleCase.toTitleCase(t);
  1889. return t;
  1890. }
  1891. }
  1892. }).init();
  1893. }
  1894. /* **********************************************
  1895. Begin LazyLoad.js
  1896. ********************************************** */
  1897. /*jslint browser: true, eqeqeq: true, bitwise: true, newcap: true, immed: true, regexp: false */
  1898. /*
  1899. LazyLoad makes it easy and painless to lazily load one or more external
  1900. JavaScript or CSS files on demand either during or after the rendering of a web
  1901. page.
  1902. Supported browsers include Firefox 2+, IE6+, Safari 3+ (including Mobile
  1903. Safari), Google Chrome, and Opera 9+. Other browsers may or may not work and
  1904. are not officially supported.
  1905. Visit https://github.com/rgrove/lazyload/ for more info.
  1906. Copyright (c) 2011 Ryan Grove <ryan@wonko.com>
  1907. All rights reserved.
  1908. Permission is hereby granted, free of charge, to any person obtaining a copy of
  1909. this software and associated documentation files (the 'Software'), to deal in
  1910. the Software without restriction, including without limitation the rights to
  1911. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  1912. the Software, and to permit persons to whom the Software is furnished to do so,
  1913. subject to the following conditions:
  1914. The above copyright notice and this permission notice shall be included in all
  1915. copies or substantial portions of the Software.
  1916. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1917. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  1918. FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  1919. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  1920. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1921. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  1922. @module lazyload
  1923. @class LazyLoad
  1924. @static
  1925. @version 2.0.3 (git)
  1926. */
  1927. LazyLoad = (function (doc) {
  1928. // -- Private Variables ------------------------------------------------------
  1929. // User agent and feature test information.
  1930. var env,
  1931. // Reference to the <head> element (populated lazily).
  1932. head,
  1933. // Requests currently in progress, if any.
  1934. pending = {},
  1935. // Number of times we've polled to check whether a pending stylesheet has
  1936. // finished loading. If this gets too high, we're probably stalled.
  1937. pollCount = 0,
  1938. // Queued requests.
  1939. queue = {css: [], js: []},
  1940. // Reference to the browser's list of stylesheets.
  1941. styleSheets = doc.styleSheets;
  1942. // -- Private Methods --------------------------------------------------------
  1943. /**
  1944. Creates and returns an HTML element with the specified name and attributes.
  1945. @method createNode
  1946. @param {String} name element name
  1947. @param {Object} attrs name/value mapping of element attributes
  1948. @return {HTMLElement}
  1949. @private
  1950. */
  1951. function createNode(name, attrs) {
  1952. var node = doc.createElement(name), attr;
  1953. for (attr in attrs) {
  1954. if (attrs.hasOwnProperty(attr)) {
  1955. node.setAttribute(attr, attrs[attr]);
  1956. }
  1957. }
  1958. return node;
  1959. }
  1960. /**
  1961. Called when the current pending resource of the specified type has finished
  1962. loading. Executes the associated callback (if any) and loads the next
  1963. resource in the queue.
  1964. @method finish
  1965. @param {String} type resource type ('css' or 'js')
  1966. @private
  1967. */
  1968. function finish(type) {
  1969. var p = pending[type],
  1970. callback,
  1971. urls;
  1972. if (p) {
  1973. callback = p.callback;
  1974. urls = p.urls;
  1975. urls.shift();
  1976. pollCount = 0;
  1977. // If this is the last of the pending URLs, execute the callback and
  1978. // start the next request in the queue (if any).
  1979. if (!urls.length) {
  1980. callback && callback.call(p.context, p.obj);
  1981. pending[type] = null;
  1982. queue[type].length && load(type);
  1983. }
  1984. }
  1985. }
  1986. /**
  1987. Populates the <code>env</code> variable with user agent and feature test
  1988. information.
  1989. @method getEnv
  1990. @private
  1991. */
  1992. function getEnv() {
  1993. var ua = navigator.userAgent;
  1994. env = {
  1995. // True if this browser supports disabling async mode on dynamically
  1996. // created script nodes. See
  1997. // http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
  1998. async: doc.createElement('script').async === true
  1999. };
  2000. (env.webkit = /AppleWebKit\//.test(ua))
  2001. || (env.ie = /MSIE/.test(ua))
  2002. || (env.opera = /Opera/.test(ua))
  2003. || (env.gecko = /Gecko\//.test(ua))
  2004. || (env.unknown = true);
  2005. }
  2006. /**
  2007. Loads the specified resources, or the next resource of the specified type
  2008. in the queue if no resources are specified. If a resource of the specified
  2009. type is already being loaded, the new request will be queued until the
  2010. first request has been finished.
  2011. When an array of resource URLs is specified, those URLs will be loaded in
  2012. parallel if it is possible to do so while preserving execution order. All
  2013. browsers support parallel loading of CSS, but only Firefox and Opera
  2014. support parallel loading of scripts. In other browsers, scripts will be
  2015. queued and loaded one at a time to ensure correct execution order.
  2016. @method load
  2017. @param {String} type resource type ('css' or 'js')
  2018. @param {String|Array} urls (optional) URL or array of URLs to load
  2019. @param {Function} callback (optional) callback function to execute when the
  2020. resource is loaded
  2021. @param {Object} obj (optional) object to pass to the callback function
  2022. @param {Object} context (optional) if provided, the callback function will
  2023. be executed in this object's context
  2024. @private
  2025. */
  2026. function load(type, urls, callback, obj, context) {
  2027. var _finish = function () { finish(type); },
  2028. isCSS = type === 'css',
  2029. nodes = [],
  2030. i, len, node, p, pendingUrls, url;
  2031. env || getEnv();
  2032. if (urls) {
  2033. // If urls is a string, wrap it in an array. Otherwise assume it's an
  2034. // array and create a copy of it so modifications won't be made to the
  2035. // original.
  2036. urls = typeof urls === 'string' ? [urls] : urls.concat();
  2037. // Create a request object for each URL. If multiple URLs are specified,
  2038. // the callback will only be executed after all URLs have been loaded.
  2039. //
  2040. // Sadly, Firefox and Opera are the only browsers capable of loading
  2041. // scripts in parallel while preserving execution order. In all other
  2042. // browsers, scripts must be loaded sequentially.
  2043. //
  2044. // All browsers respect CSS specificity based on the order of the link
  2045. // elements in the DOM, regardless of the order in which the stylesheets
  2046. // are actually downloaded.
  2047. if (isCSS || env.async || env.gecko || env.opera) {
  2048. // Load in parallel.
  2049. queue[type].push({
  2050. urls : urls,
  2051. callback: callback,
  2052. obj : obj,
  2053. context : context
  2054. });
  2055. } else {
  2056. // Load sequentially.
  2057. for (i = 0, len = urls.length; i < len; ++i) {
  2058. queue[type].push({
  2059. urls : [urls[i]],
  2060. callback: i === len - 1 ? callback : null, // callback is only added to the last URL
  2061. obj : obj,
  2062. context : context
  2063. });
  2064. }
  2065. }
  2066. }
  2067. // If a previous load request of this type is currently in progress, we'll
  2068. // wait our turn. Otherwise, grab the next item in the queue.
  2069. if (pending[type] || !(p = pending[type] = queue[type].shift())) {
  2070. return;
  2071. }
  2072. head || (head = doc.head || doc.getElementsByTagName('head')[0]);
  2073. pendingUrls = p.urls;
  2074. for (i = 0, len = pendingUrls.length; i < len; ++i) {
  2075. url = pendingUrls[i];
  2076. if (isCSS) {
  2077. node = env.gecko ? createNode('style') : createNode('link', {
  2078. href: url,
  2079. rel : 'stylesheet'
  2080. });
  2081. } else {
  2082. node = createNode('script', {src: url});
  2083. node.async = false;
  2084. }
  2085. node.className = 'lazyload';
  2086. node.setAttribute('charset', 'utf-8');
  2087. if (env.ie && !isCSS) {
  2088. node.onreadystatechange = function () {
  2089. if (/loaded|complete/.test(node.readyState)) {
  2090. node.onreadystatechange = null;
  2091. _finish();
  2092. }
  2093. };
  2094. } else if (isCSS && (env.gecko || env.webkit)) {
  2095. // Gecko and WebKit don't support the onload event on link nodes.
  2096. if (env.webkit) {
  2097. // In WebKit, we can poll for changes to document.styleSheets to
  2098. // figure out when stylesheets have loaded.
  2099. p.urls[i] = node.href; // resolve relative URLs (or polling won't work)
  2100. pollWebKit();
  2101. } else {
  2102. // In Gecko, we can import the requested URL into a <style> node and
  2103. // poll for the existence of node.sheet.cssRules. Props to Zach
  2104. // Leatherman for calling my attention to this technique.
  2105. node.innerHTML = '@import "' + url + '";';
  2106. pollGecko(node);
  2107. }
  2108. } else {
  2109. node.onload = node.onerror = _finish;
  2110. }
  2111. nodes.push(node);
  2112. }
  2113. for (i = 0, len = nodes.length; i < len; ++i) {
  2114. head.appendChild(nodes[i]);
  2115. }
  2116. }
  2117. /**
  2118. Begins polling to determine when the specified stylesheet has finished loading
  2119. in Gecko. Polling stops when all pending stylesheets have loaded or after 10
  2120. seconds (to prevent stalls).
  2121. Thanks to Zach Leatherman for calling my attention to the @import-based
  2122. cross-domain technique used here, and to Oleg Slobodskoi for an earlier
  2123. same-domain implementation. See Zach's blog for more details:
  2124. http://www.zachleat.com/web/2010/07/29/load-css-dynamically/
  2125. @method pollGecko
  2126. @param {HTMLElement} node Style node to poll.
  2127. @private
  2128. */
  2129. function pollGecko(node) {
  2130. var hasRules;
  2131. try {
  2132. // We don't really need to store this value or ever refer to it again, but
  2133. // if we don't store it, Closure Compiler assumes the code is useless and
  2134. // removes it.
  2135. hasRules = !!node.sheet.cssRules;
  2136. } catch (ex) {
  2137. // An exception means the stylesheet is still loading.
  2138. pollCount += 1;
  2139. if (pollCount < 200) {
  2140. setTimeout(function () { pollGecko(node); }, 50);
  2141. } else {
  2142. // We've been polling for 10 seconds and nothing's happened. Stop
  2143. // polling and finish the pending requests to avoid blocking further
  2144. // requests.
  2145. hasRules && finish('css');
  2146. }
  2147. return;
  2148. }
  2149. // If we get here, the stylesheet has loaded.
  2150. finish('css');
  2151. }
  2152. /**
  2153. Begins polling to determine when pending stylesheets have finished loading
  2154. in WebKit. Polling stops when all pending stylesheets have loaded or after 10
  2155. seconds (to prevent stalls).
  2156. @method pollWebKit
  2157. @private
  2158. */
  2159. function pollWebKit() {
  2160. var css = pending.css, i;
  2161. if (css) {
  2162. i = styleSheets.length;
  2163. // Look for a stylesheet matching the pending URL.
  2164. while (--i >= 0) {
  2165. if (styleSheets[i].href === css.urls[0]) {
  2166. finish('css');
  2167. break;
  2168. }
  2169. }
  2170. pollCount += 1;
  2171. if (css) {
  2172. if (pollCount < 200) {
  2173. setTimeout(pollWebKit, 50);
  2174. } else {
  2175. // We've been polling for 10 seconds and nothing's happened, which may
  2176. // indicate that the stylesheet has been removed from the document
  2177. // before it had a chance to load. Stop polling and finish the pending
  2178. // request to prevent blocking further requests.
  2179. finish('css');
  2180. }
  2181. }
  2182. }
  2183. }
  2184. return {
  2185. /**
  2186. Requests the specified CSS URL or URLs and executes the specified
  2187. callback (if any) when they have finished loading. If an array of URLs is
  2188. specified, the stylesheets will be loaded in parallel and the callback
  2189. will be executed after all stylesheets have finished loading.
  2190. @method css
  2191. @param {String|Array} urls CSS URL or array of CSS URLs to load
  2192. @param {Function} callback (optional) callback function to execute when
  2193. the specified stylesheets are loaded
  2194. @param {Object} obj (optional) object to pass to the callback function
  2195. @param {Object} context (optional) if provided, the callback function
  2196. will be executed in this object's context
  2197. @static
  2198. */
  2199. css: function (urls, callback, obj, context) {
  2200. load('css', urls, callback, obj, context);
  2201. },
  2202. /**
  2203. Requests the specified JavaScript URL or URLs and executes the specified
  2204. callback (if any) when they have finished loading. If an array of URLs is
  2205. specified and the browser supports it, the scripts will be loaded in
  2206. parallel and the callback will be executed after all scripts have
  2207. finished loading.
  2208. Currently, only Firefox and Opera support parallel loading of scripts while
  2209. preserving execution order. In other browsers, scripts will be
  2210. queued and loaded one at a time to ensure correct execution order.
  2211. @method js
  2212. @param {String|Array} urls JS URL or array of JS URLs to load
  2213. @param {Function} callback (optional) callback function to execute when
  2214. the specified scripts are loaded
  2215. @param {Object} obj (optional) object to pass to the callback function
  2216. @param {Object} context (optional) if provided, the callback function
  2217. will be executed in this object's context
  2218. @static
  2219. */
  2220. js: function (urls, callback, obj, context) {
  2221. load('js', urls, callback, obj, context);
  2222. }
  2223. };
  2224. })(this.document);
  2225. /* **********************************************
  2226. Begin VMM.LoadLib.js
  2227. ********************************************** */
  2228. /*
  2229. LoadLib
  2230. Designed and built by Zach Wise digitalartwork.net
  2231. */
  2232. /* * CodeKit Import
  2233. * http://incident57.com/codekit/
  2234. ================================================== */
  2235. // @codekit-prepend "../Library/LazyLoad.js";
  2236. LoadLib = (function (doc) {
  2237. var loaded = [];
  2238. function isLoaded(url) {
  2239. var i = 0,
  2240. has_loaded = false;
  2241. for (i = 0; i < loaded.length; i++) {
  2242. if (loaded[i] == url) {
  2243. has_loaded = true;
  2244. }
  2245. }
  2246. if (has_loaded) {
  2247. return true;
  2248. } else {
  2249. loaded.push(url);
  2250. return false;
  2251. }
  2252. }
  2253. return {
  2254. css: function (urls, callback, obj, context) {
  2255. if (!isLoaded(urls)) {
  2256. LazyLoad.css(urls, callback, obj, context);
  2257. }
  2258. },
  2259. js: function (urls, callback, obj, context) {
  2260. if (!isLoaded(urls)) {
  2261. LazyLoad.js(urls, callback, obj, context);
  2262. }
  2263. }
  2264. };
  2265. })(this.document);
  2266. /* **********************************************
  2267. Begin VMM.Language.js
  2268. ********************************************** */
  2269. /* DEFAULT LANGUAGE
  2270. ================================================== */
  2271. if(typeof VMM != 'undefined' && typeof VMM.Language == 'undefined') {
  2272. VMM.Language = {
  2273. lang: "en",
  2274. api: {
  2275. wikipedia: "en"
  2276. },
  2277. date: {
  2278. month: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  2279. month_abbr: ["Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."],
  2280. day: ["Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  2281. day_abbr: ["Sun.","Mon.", "Tues.", "Wed.", "Thurs.", "Fri.", "Sat."]
  2282. },
  2283. dateformats: {
  2284. year: "yyyy",
  2285. month_short: "mmm",
  2286. month: "mmmm yyyy",
  2287. full_short: "mmm d",
  2288. full: "mmmm d',' yyyy",
  2289. time_short: "h:MM:ss TT",
  2290. time_no_seconds_short: "h:MM TT",
  2291. time_no_seconds_small_date: "h:MM TT'<br/><small>'mmmm d',' yyyy'</small>'",
  2292. full_long: "mmm d',' yyyy 'at' h:MM TT",
  2293. full_long_small_date: "h:MM TT'<br/><small>mmm d',' yyyy'</small>'"
  2294. },
  2295. messages: {
  2296. loading_timeline: "Loading Timeline... ",
  2297. return_to_title: "Return to Title",
  2298. expand_timeline: "Expand Timeline",
  2299. contract_timeline: "Contract Timeline",
  2300. wikipedia: "From Wikipedia, the free encyclopedia",
  2301. loading_content: "Loading Content",
  2302. loading: "Loading"
  2303. }
  2304. }
  2305. };
  2306. /* **********************************************
  2307. Begin VMM.Core.js
  2308. ********************************************** */
  2309. /* VeriteCo Core
  2310. ================================================== */
  2311. /* * CodeKit Import
  2312. * http://incident57.com/codekit/
  2313. ================================================== */
  2314. // @codekit-prepend "VMM.js";
  2315. // @codekit-prepend "VMM.Library.js";
  2316. // @codekit-prepend "VMM.Browser.js";
  2317. // @codekit-prepend "VMM.FileExtention.js";
  2318. // @codekit-prepend "VMM.Date.js";
  2319. // @codekit-prepend "VMM.Util.js";
  2320. // @codekit-prepend "VMM.LoadLib.js";
  2321. // @codekit-prepend "VMM.Language.js";
  2322. /* **********************************************
  2323. Begin VMM.ExternalAPI.js
  2324. ********************************************** */
  2325. /* External API
  2326. ================================================== */
  2327. if(typeof VMM != 'undefined' && typeof VMM.ExternalAPI == 'undefined') {
  2328. VMM.ExternalAPI = ({
  2329. keys: {
  2330. google: "",
  2331. flickr: "",
  2332. twitter: ""
  2333. },
  2334. keys_master: {
  2335. vp: "Pellentesque nibh felis, eleifend id, commodo in, interdum vitae, leo",
  2336. flickr: "RAIvxHY4hE/Elm5cieh4X5ptMyDpj7MYIxziGxi0WGCcy1s+yr7rKQ==",
  2337. google: "jwNGnYw4hE9lmAez4ll0QD+jo6SKBJFknkopLS4FrSAuGfIwyj57AusuR0s8dAo=",
  2338. twitter: ""
  2339. },
  2340. init: function() {
  2341. return this;
  2342. },
  2343. setKeys: function(d) {
  2344. VMM.ExternalAPI.keys = d;
  2345. },
  2346. pushQues: function() {
  2347. if (VMM.master_config.googlemaps.active) {
  2348. VMM.ExternalAPI.googlemaps.pushQue();
  2349. }
  2350. if (VMM.master_config.youtube.active) {
  2351. VMM.ExternalAPI.youtube.pushQue();
  2352. }
  2353. if (VMM.master_config.soundcloud.active) {
  2354. VMM.ExternalAPI.soundcloud.pushQue();
  2355. }
  2356. if (VMM.master_config.googledocs.active) {
  2357. VMM.ExternalAPI.googledocs.pushQue();
  2358. }
  2359. if (VMM.master_config.googleplus.active) {
  2360. VMM.ExternalAPI.googleplus.pushQue();
  2361. }
  2362. if (VMM.master_config.wikipedia.active) {
  2363. VMM.ExternalAPI.wikipedia.pushQue();
  2364. }
  2365. if (VMM.master_config.vimeo.active) {
  2366. VMM.ExternalAPI.vimeo.pushQue();
  2367. }
  2368. if (VMM.master_config.vine.active) {
  2369. VMM.ExternalAPI.vine.pushQue();
  2370. }
  2371. if (VMM.master_config.twitter.active) {
  2372. VMM.ExternalAPI.twitter.pushQue();
  2373. }
  2374. if (VMM.master_config.flickr.active) {
  2375. VMM.ExternalAPI.flickr.pushQue();
  2376. }
  2377. if (VMM.master_config.webthumb.active) {
  2378. VMM.ExternalAPI.webthumb.pushQue();
  2379. }
  2380. },
  2381. twitter: {
  2382. tweetArray: [],
  2383. get: function(m) {
  2384. var tweet = {mid: m.id, id: m.uid};
  2385. VMM.master_config.twitter.que.push(tweet);
  2386. VMM.master_config.twitter.active = true;
  2387. //VMM.master_config.api.pushques.push(VMM.ExternalAPI.twitter.pushQue);
  2388. },
  2389. create: function(tweet, callback) {
  2390. var id = tweet.mid.toString(),
  2391. error_obj = { twitterid: tweet.mid },
  2392. the_url = "//api.twitter.com/1/statuses/show.json?id=" + tweet.mid + "&include_entities=true&callback=?";
  2393. //twitter_timeout = setTimeout(VMM.ExternalAPI.twitter.errorTimeOut, VMM.master_config.timers.api, tweet),
  2394. //callback_timeout= setTimeout(callback, VMM.master_config.timers.api, tweet);
  2395. VMM.ExternalAPI.twitter.getOEmbed(tweet, callback);
  2396. /*
  2397. // Disabled thanks to twitter's new api
  2398. VMM.getJSON(the_url, function(d) {
  2399. var id = d.id_str,
  2400. twit = "<blockquote><p>",
  2401. td = VMM.Util.linkify_with_twitter(d.text, "_blank");
  2402. // TWEET CONTENT
  2403. twit += td;
  2404. twit += "</p></blockquote>";
  2405. // TWEET MEDIA
  2406. if (typeof d.entities.media != 'undefined') {
  2407. if (d.entities.media[0].type == "photo") {
  2408. //twit += "<img src=' " + d.entities.media[0].media_url + "' alt=''>"
  2409. }
  2410. }
  2411. // TWEET AUTHOR
  2412. twit += "<div class='vcard author'>";
  2413. twit += "<a class='screen-name url' href='https://twitter.com/" + d.user.screen_name + "' data-screen-name='" + d.user.screen_name + "' target='_blank'>";
  2414. twit += "<span class='avatar'><img src=' " + d.user.profile_image_url + "' alt=''></span>";
  2415. twit += "<span class='fn'>" + d.user.name + "</span>";
  2416. twit += "<span class='nickname'>@" + d.user.screen_name + "<span class='thumbnail-inline'></span></span>";
  2417. twit += "</a>";
  2418. twit += "</div>";
  2419. VMM.attachElement("#"+tweet.id.toString(), twit );
  2420. VMM.attachElement("#text_thumb_"+tweet.id.toString(), d.text );
  2421. VMM.attachElement("#marker_content_" + tweet.id.toString(), d.text );
  2422. })
  2423. .error(function(jqXHR, textStatus, errorThrown) {
  2424. trace("TWITTER error");
  2425. trace("TWITTER ERROR: " + textStatus + " " + jqXHR.responseText);
  2426. VMM.attachElement("#"+tweet.id, VMM.MediaElement.loadingmessage("ERROR LOADING TWEET " + tweet.mid) );
  2427. })
  2428. .success(function(d) {
  2429. clearTimeout(twitter_timeout);
  2430. clearTimeout(callback_timeout);
  2431. callback();
  2432. });
  2433. */
  2434. },
  2435. errorTimeOut: function(tweet) {
  2436. trace("TWITTER JSON ERROR TIMEOUT " + tweet.mid);
  2437. VMM.attachElement("#"+tweet.id.toString(), VMM.MediaElement.loadingmessage("Still waiting on Twitter: " + tweet.mid) );
  2438. // CHECK RATE STATUS
  2439. VMM.getJSON("//api.twitter.com/1/account/rate_limit_status.json", function(d) {
  2440. trace("REMAINING TWITTER API CALLS " + d.remaining_hits);
  2441. trace("TWITTER RATE LIMIT WILL RESET AT " + d.reset_time);
  2442. var mes = "";
  2443. if (d.remaining_hits == 0) {
  2444. mes = "<p>You've reached the maximum number of tweets you can load in an hour.</p>";
  2445. mes += "<p>You can view tweets again starting at: <br/>" + d.reset_time + "</p>";
  2446. } else {
  2447. mes = "<p>Still waiting on Twitter. " + tweet.mid + "</p>";
  2448. //mes = "<p>Tweet " + id + " was not found.</p>";
  2449. }
  2450. VMM.attachElement("#"+tweet.id.toString(), VMM.MediaElement.loadingmessage(mes) );
  2451. });
  2452. },
  2453. errorTimeOutOembed: function(tweet) {
  2454. trace("TWITTER JSON ERROR TIMEOUT " + tweet.mid);
  2455. VMM.attachElement("#"+tweet.id.toString(), VMM.MediaElement.loadingmessage("Still waiting on Twitter: " + tweet.mid) );
  2456. },
  2457. pushQue: function() {
  2458. if (VMM.master_config.twitter.que.length > 0) {
  2459. VMM.ExternalAPI.twitter.create(VMM.master_config.twitter.que[0], VMM.ExternalAPI.twitter.pushQue);
  2460. VMM.Util.removeRange(VMM.master_config.twitter.que,0);
  2461. }
  2462. },
  2463. getOEmbed: function(tweet, callback) {
  2464. var the_url = "//api.twitter.com/1/statuses/oembed.json?id=" + tweet.mid + "&omit_script=true&include_entities=true&callback=?",
  2465. twitter_timeout = setTimeout(VMM.ExternalAPI.twitter.errorTimeOutOembed, VMM.master_config.timers.api, tweet);
  2466. //callback_timeout= setTimeout(callback, VMM.master_config.timers.api, tweet);
  2467. VMM.getJSON(the_url, function(d) {
  2468. var twit = "",
  2469. tuser = "";
  2470. // TWEET CONTENT
  2471. twit += d.html.split("<\/p>\&mdash;")[0] + "</p></blockquote>";
  2472. tuser = d.author_url.split("twitter.com\/")[1];
  2473. // TWEET AUTHOR
  2474. twit += "<div class='vcard author'>";
  2475. twit += "<a class='screen-name url' href='" + d.author_url + "' target='_blank'>";
  2476. twit += "<span class='avatar'></span>";
  2477. twit += "<span class='fn'>" + d.author_name + "</span>";
  2478. twit += "<span class='nickname'>@" + tuser + "<span class='thumbnail-inline'></span></span>";
  2479. twit += "</a>";
  2480. twit += "</div>";
  2481. VMM.attachElement("#"+tweet.id.toString(), twit );
  2482. VMM.attachElement("#text_thumb_"+tweet.id.toString(), d.html );
  2483. VMM.attachElement("#marker_content_" + tweet.id.toString(), d.html );
  2484. })
  2485. .error(function(jqXHR, textStatus, errorThrown) {
  2486. trace("TWITTER error");
  2487. trace("TWITTER ERROR: " + textStatus + " " + jqXHR.responseText);
  2488. clearTimeout(twitter_timeout);
  2489. //clearTimeout(callback_timeout);
  2490. VMM.attachElement("#"+tweet.id, VMM.MediaElement.loadingmessage("ERROR LOADING TWEET " + tweet.mid) );
  2491. })
  2492. .success(function(d) {
  2493. clearTimeout(twitter_timeout);
  2494. // clearTimeout(callback_timeout);
  2495. callback();
  2496. });
  2497. },
  2498. getHTML: function(id) {
  2499. //var the_url = document.location.protocol + "//api.twitter.com/1/statuses/oembed.json?id=" + id+ "&callback=?";
  2500. var the_url = "//api.twitter.com/1/statuses/oembed.json?id=" + id+ "&omit_script=true&include_entities=true&callback=?";
  2501. VMM.getJSON(the_url, VMM.ExternalAPI.twitter.onJSONLoaded);
  2502. },
  2503. onJSONLoaded: function(d) {
  2504. trace("TWITTER JSON LOADED");
  2505. var id = d.id;
  2506. VMM.attachElement("#"+id, VMM.Util.linkify_with_twitter(d.html) );
  2507. },
  2508. parseTwitterDate: function(d) {
  2509. var date = new Date(Date.parse(d));
  2510. /*
  2511. var t = d.replace(/(\d{1,2}[:]\d{2}[:]\d{2}) (.*)/, '$2 $1');
  2512. t = t.replace(/(\+\S+) (.*)/, '$2 $1');
  2513. var date = new Date(Date.parse(t)).toLocaleDateString();
  2514. var time = new Date(Date.parse(t)).toLocaleTimeString();
  2515. */
  2516. return date;
  2517. },
  2518. prettyParseTwitterDate: function(d) {
  2519. var date = new Date(Date.parse(d));
  2520. return VMM.Date.prettyDate(date, true);
  2521. },
  2522. getTweets: function(tweets) {
  2523. var tweetArray = [];
  2524. var number_of_tweets = tweets.length;
  2525. for(var i = 0; i < tweets.length; i++) {
  2526. var twitter_id = "";
  2527. /* FIND THE TWITTER ID
  2528. ================================================== */
  2529. if (tweets[i].tweet.match("status\/")) {
  2530. twitter_id = tweets[i].tweet.split("status\/")[1];
  2531. } else if (tweets[i].tweet.match("statuses\/")) {
  2532. twitter_id = tweets[i].tweet.split("statuses\/")[1];
  2533. } else {
  2534. twitter_id = "";
  2535. }
  2536. /* FETCH THE DATA
  2537. ================================================== */
  2538. var the_url = "//api.twitter.com/1/statuses/show.json?id=" + twitter_id + "&include_entities=true&callback=?";
  2539. VMM.getJSON(the_url, function(d) {
  2540. var tweet = {}
  2541. /* FORMAT RESPONSE
  2542. ================================================== */
  2543. var twit = "<div class='twitter'><blockquote><p>";
  2544. var td = VMM.Util.linkify_with_twitter(d.text, "_blank");
  2545. twit += td;
  2546. twit += "</p>";
  2547. 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>";
  2548. tweet.content = twit;
  2549. tweet.raw = d;
  2550. tweetArray.push(tweet);
  2551. /* CHECK IF THATS ALL OF THEM
  2552. ================================================== */
  2553. if (tweetArray.length == number_of_tweets) {
  2554. var the_tweets = {tweetdata: tweetArray}
  2555. VMM.fireEvent(global, "TWEETSLOADED", the_tweets);
  2556. }
  2557. })
  2558. .success(function() { trace("second success"); })
  2559. .error(function() { trace("error"); })
  2560. .complete(function() { trace("complete"); });
  2561. }
  2562. },
  2563. getTweetSearch: function(tweets, number_of_tweets) {
  2564. var _number_of_tweets = 40;
  2565. if (number_of_tweets != null && number_of_tweets != "") {
  2566. _number_of_tweets = number_of_tweets;
  2567. }
  2568. var the_url = "//search.twitter.com/search.json?q=" + tweets + "&rpp=" + _number_of_tweets + "&include_entities=true&result_type=mixed";
  2569. var tweetArray = [];
  2570. VMM.getJSON(the_url, function(d) {
  2571. /* FORMAT RESPONSE
  2572. ================================================== */
  2573. for(var i = 0; i < d.results.length; i++) {
  2574. var tweet = {}
  2575. var twit = "<div class='twitter'><blockquote><p>";
  2576. var td = VMM.Util.linkify_with_twitter(d.results[i].text, "_blank");
  2577. twit += td;
  2578. twit += "</p>";
  2579. 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>";
  2580. tweet.content = twit;
  2581. tweet.raw = d.results[i];
  2582. tweetArray.push(tweet);
  2583. }
  2584. var the_tweets = {tweetdata: tweetArray}
  2585. VMM.fireEvent(global, "TWEETSLOADED", the_tweets);
  2586. });
  2587. },
  2588. prettyHTML: function(id, secondary) {
  2589. var id = id.toString();
  2590. var error_obj = {
  2591. twitterid: id
  2592. };
  2593. var the_url = "//api.twitter.com/1/statuses/show.json?id=" + id + "&include_entities=true&callback=?";
  2594. var twitter_timeout = setTimeout(VMM.ExternalAPI.twitter.errorTimeOut, VMM.master_config.timers.api, id);
  2595. VMM.getJSON(the_url, VMM.ExternalAPI.twitter.formatJSON)
  2596. .error(function(jqXHR, textStatus, errorThrown) {
  2597. trace("TWITTER error");
  2598. trace("TWITTER ERROR: " + textStatus + " " + jqXHR.responseText);
  2599. VMM.attachElement("#twitter_"+id, "<p>ERROR LOADING TWEET " + id + "</p>" );
  2600. })
  2601. .success(function(d) {
  2602. clearTimeout(twitter_timeout);
  2603. if (secondary) {
  2604. VMM.ExternalAPI.twitter.secondaryMedia(d);
  2605. }
  2606. });
  2607. },
  2608. formatJSON: function(d) {
  2609. var id = d.id_str;
  2610. var twit = "<blockquote><p>";
  2611. var td = VMM.Util.linkify_with_twitter(d.text, "_blank");
  2612. //td = td.replace(/(@([\w]+))/g,"<a href='http://twitter.com/$2' target='_blank'>$1</a>");
  2613. //td = td.replace(/(#([\w]+))/g,"<a href='http://twitter.com/#search?q=%23$2' target='_blank'>$1</a>");
  2614. twit += td;
  2615. twit += "</p></blockquote>";
  2616. //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>";
  2617. twit += "<div class='vcard author'>";
  2618. twit += "<a class='screen-name url' href='https://twitter.com/" + d.user.screen_name + "' data-screen-name='" + d.user.screen_name + "' target='_blank'>";
  2619. twit += "<span class='avatar'><img src=' " + d.user.profile_image_url + "' alt=''></span>";
  2620. twit += "<span class='fn'>" + d.user.name + "</span>";
  2621. twit += "<span class='nickname'>@" + d.user.screen_name + "<span class='thumbnail-inline'></span></span>";
  2622. twit += "</a>";
  2623. twit += "</div>";
  2624. if (typeof d.entities.media != 'undefined') {
  2625. if (d.entities.media[0].type == "photo") {
  2626. twit += "<img src=' " + d.entities.media[0].media_url + "' alt=''>"
  2627. }
  2628. }
  2629. VMM.attachElement("#twitter_"+id.toString(), twit );
  2630. VMM.attachElement("#text_thumb_"+id.toString(), d.text );
  2631. }
  2632. },
  2633. googlemaps: {
  2634. maptype: "TERRAIN", // see also below for default if this is a google type
  2635. setMapType: function(d) {
  2636. if (d != "") {
  2637. VMM.ExternalAPI.googlemaps.maptype = d;
  2638. }
  2639. },
  2640. get: function(m) {
  2641. var timer,
  2642. api_key,
  2643. map_url;
  2644. m.vars = VMM.Util.getUrlVars(m.id);
  2645. if (VMM.ExternalAPI.keys.google != "") {
  2646. api_key = VMM.ExternalAPI.keys.google;
  2647. } else {
  2648. api_key = Aes.Ctr.decrypt(VMM.ExternalAPI.keys_master.google, VMM.ExternalAPI.keys_master.vp, 256);
  2649. }
  2650. /*
  2651. Investigating a google map api change on the latest release that causes custom map types to stop working
  2652. http://stackoverflow.com/questions/13486271/google-map-markermanager-cannot-call-method-substr-of-undefined
  2653. soulution is to use api ver 3.9
  2654. */
  2655. map_url = "//maps.googleapis.com/maps/api/js?key=" + api_key + "&v=3.9&libraries=places&sensor=false&callback=VMM.ExternalAPI.googlemaps.onMapAPIReady";
  2656. if (VMM.master_config.googlemaps.active) {
  2657. VMM.master_config.googlemaps.que.push(m);
  2658. } else {
  2659. VMM.master_config.googlemaps.que.push(m);
  2660. if (VMM.master_config.googlemaps.api_loaded) {
  2661. } else {
  2662. LoadLib.js(map_url, function() {
  2663. trace("Google Maps API Library Loaded");
  2664. });
  2665. }
  2666. }
  2667. },
  2668. create: function(m) {
  2669. VMM.ExternalAPI.googlemaps.createAPIMap(m);
  2670. },
  2671. createiFrameMap: function(m) {
  2672. var embed_url = m.id + "&output=embed",
  2673. mc = "",
  2674. unique_map_id = m.uid.toString() + "_gmap";
  2675. mc += "<div class='google-map' id='" + unique_map_id + "' style='width=100%;height=100%;'>";
  2676. mc += "<iframe width='100%' height='100%' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='" + embed_url + "'></iframe>";
  2677. mc += "</div>";
  2678. VMM.attachElement("#" + m.uid, mc);
  2679. },
  2680. createAPIMap: function(m) {
  2681. var map_attribution = "",
  2682. layer,
  2683. map,
  2684. map_options,
  2685. unique_map_id = m.uid.toString() + "_gmap",
  2686. map_attribution_html = "",
  2687. location = new google.maps.LatLng(41.875696,-87.624207),
  2688. latlong,
  2689. zoom = 11,
  2690. has_location = false,
  2691. has_zoom = false,
  2692. api_limit = false,
  2693. map_bounds;
  2694. function mapProvider(name) {
  2695. if (name in VMM.ExternalAPI.googlemaps.map_providers) {
  2696. map_attribution = VMM.ExternalAPI.googlemaps.map_attribution[VMM.ExternalAPI.googlemaps.map_providers[name].attribution];
  2697. return VMM.ExternalAPI.googlemaps.map_providers[name];
  2698. } else {
  2699. if (VMM.ExternalAPI.googlemaps.defaultType(name)) {
  2700. trace("GOOGLE MAP DEFAULT TYPE");
  2701. return google.maps.MapTypeId[name.toUpperCase()];
  2702. } else {
  2703. trace("Not a maptype: " + name );
  2704. }
  2705. }
  2706. }
  2707. google.maps.VeriteMapType = function(name) {
  2708. if (VMM.ExternalAPI.googlemaps.defaultType(name)) {
  2709. return google.maps.MapTypeId[name.toUpperCase()];
  2710. } else {
  2711. var provider = mapProvider(name);
  2712. return google.maps.ImageMapType.call(this, {
  2713. "getTileUrl": function(coord, zoom) {
  2714. var index = (zoom + coord.x + coord.y) % VMM.ExternalAPI.googlemaps.map_subdomains.length;
  2715. var retURL = provider.url
  2716. .replace("{S}", VMM.ExternalAPI.googlemaps.map_subdomains[index])
  2717. .replace("{Z}", zoom)
  2718. .replace("{X}", coord.x)
  2719. .replace("{Y}", coord.y)
  2720. .replace("{z}", zoom)
  2721. .replace("{x}", coord.x)
  2722. .replace("{y}", coord.y);
  2723. // trace(retURL);
  2724. return retURL;
  2725. },
  2726. "tileSize": new google.maps.Size(256, 256),
  2727. "name": name,
  2728. "minZoom": provider.minZoom,
  2729. "maxZoom": provider.maxZoom
  2730. });
  2731. }
  2732. };
  2733. google.maps.VeriteMapType.prototype = new google.maps.ImageMapType("_");
  2734. /* Make the Map
  2735. ================================================== */
  2736. if (VMM.ExternalAPI.googlemaps.maptype != "") {
  2737. if (VMM.ExternalAPI.googlemaps.defaultType(VMM.ExternalAPI.googlemaps.maptype)) {
  2738. layer = google.maps.MapTypeId[VMM.ExternalAPI.googlemaps.maptype.toUpperCase()];
  2739. } else {
  2740. layer = VMM.ExternalAPI.googlemaps.maptype;
  2741. }
  2742. } else {
  2743. layer = google.maps.MapTypeId['TERRAIN'];
  2744. }
  2745. var new_google_url_regex = new RegExp(/@([0-9\.\-]+),([0-9\.\-]+),(\d+)z/);
  2746. if (m.id.match(new_google_url_regex)) {
  2747. var match = m.id.match(new_google_url_regex)
  2748. lat = parseFloat(match[1]);
  2749. lng = parseFloat(match[2]);
  2750. location = new google.maps.LatLng(lat,lng);
  2751. zoom = parseFloat(match[3]);
  2752. has_location = has_zoom = true;
  2753. } else {
  2754. if (type.of(VMM.Util.getUrlVars(m.id)["ll"]) == "string") {
  2755. has_location = true;
  2756. latlong = VMM.Util.getUrlVars(m.id)["ll"].split(",");
  2757. location = new google.maps.LatLng(parseFloat(latlong[0]),parseFloat(latlong[1]));
  2758. } else if (type.of(VMM.Util.getUrlVars(m.id)["sll"]) == "string") {
  2759. latlong = VMM.Util.getUrlVars(m.id)["sll"].split(",");
  2760. location = new google.maps.LatLng(parseFloat(latlong[0]),parseFloat(latlong[1]));
  2761. }
  2762. if (type.of(VMM.Util.getUrlVars(m.id)["z"]) == "string") {
  2763. has_zoom = true;
  2764. zoom = parseFloat(VMM.Util.getUrlVars(m.id)["z"]);
  2765. }
  2766. }
  2767. map_options = {
  2768. zoom: zoom,
  2769. draggable: false,
  2770. disableDefaultUI: true,
  2771. mapTypeControl: false,
  2772. zoomControl: true,
  2773. zoomControlOptions: {
  2774. style: google.maps.ZoomControlStyle.SMALL,
  2775. position: google.maps.ControlPosition.TOP_RIGHT
  2776. },
  2777. center: location,
  2778. mapTypeId: layer,
  2779. mapTypeControlOptions: {
  2780. mapTypeIds: [layer]
  2781. }
  2782. }
  2783. VMM.attachElement("#" + m.uid, "<div class='google-map' id='" + unique_map_id + "' style='width=100%;height=100%;'></div>");
  2784. map = new google.maps.Map(document.getElementById(unique_map_id), map_options);
  2785. if (VMM.ExternalAPI.googlemaps.defaultType(VMM.ExternalAPI.googlemaps.maptype)) {
  2786. } else {
  2787. map.mapTypes.set(layer, new google.maps.VeriteMapType(layer));
  2788. // ATTRIBUTION
  2789. map_attribution_html = "<div class='map-attribution'><div class='attribution-text'>" + map_attribution + "</div></div>";
  2790. VMM.appendElement("#"+unique_map_id, map_attribution_html);
  2791. }
  2792. // DETERMINE IF KML IS POSSIBLE
  2793. if (type.of(VMM.Util.getUrlVars(m.id)["msid"]) == "string") {
  2794. loadKML();
  2795. } else {
  2796. //loadPlaces();
  2797. if (type.of(VMM.Util.getUrlVars(m.id)["q"]) == "string") {
  2798. geocodePlace();
  2799. }
  2800. }
  2801. // GEOCODE
  2802. function geocodePlace() {
  2803. var geocoder = new google.maps.Geocoder(),
  2804. address = VMM.Util.getUrlVars(m.id)["q"],
  2805. marker;
  2806. if (address.match("loc:")) {
  2807. var address_latlon = address.split(":")[1].split("+");
  2808. location = new google.maps.LatLng(parseFloat(address_latlon[0]),parseFloat(address_latlon[1]));
  2809. has_location = true;
  2810. }
  2811. geocoder.geocode( { 'address': address}, function(results, status) {
  2812. if (status == google.maps.GeocoderStatus.OK) {
  2813. marker = new google.maps.Marker({
  2814. map: map,
  2815. position: results[0].geometry.location
  2816. });
  2817. // POSITION MAP
  2818. //map.setCenter(results[0].geometry.location);
  2819. //map.panTo(location);
  2820. if (typeof results[0].geometry.viewport != 'undefined') {
  2821. map.fitBounds(results[0].geometry.viewport);
  2822. } else if (typeof results[0].geometry.bounds != 'undefined') {
  2823. map.fitBounds(results[0].geometry.bounds);
  2824. } else {
  2825. map.setCenter(results[0].geometry.location);
  2826. }
  2827. if (has_location) {
  2828. map.panTo(location);
  2829. }
  2830. if (has_zoom) {
  2831. map.setZoom(zoom);
  2832. }
  2833. } else {
  2834. trace("Geocode for " + address + " was not successful for the following reason: " + status);
  2835. trace("TRYING PLACES SEARCH");
  2836. if (has_location) {
  2837. map.panTo(location);
  2838. }
  2839. if (has_zoom) {
  2840. map.setZoom(zoom);
  2841. }
  2842. loadPlaces();
  2843. }
  2844. });
  2845. }
  2846. // PLACES
  2847. function loadPlaces() {
  2848. var place,
  2849. search_request,
  2850. infowindow,
  2851. search_bounds,
  2852. bounds_sw,
  2853. bounds_ne;
  2854. place_search = new google.maps.places.PlacesService(map);
  2855. infowindow = new google.maps.InfoWindow();
  2856. search_request = {
  2857. query: "",
  2858. types: ['country', 'neighborhood', 'political', 'locality', 'geocode']
  2859. };
  2860. if (type.of(VMM.Util.getUrlVars(m.id)["q"]) == "string") {
  2861. search_request.query = VMM.Util.getUrlVars(m.id)["q"];
  2862. }
  2863. if (has_location) {
  2864. search_request.location = location;
  2865. search_request.radius = "15000";
  2866. } else {
  2867. bounds_sw = new google.maps.LatLng(-89.999999,-179.999999);
  2868. bounds_ne = new google.maps.LatLng(89.999999,179.999999);
  2869. search_bounds = new google.maps.LatLngBounds(bounds_sw,bounds_ne);
  2870. //search_request.location = search_bounds;
  2871. }
  2872. place_search.textSearch(search_request, placeResults);
  2873. function placeResults(results, status) {
  2874. if (status == google.maps.places.PlacesServiceStatus.OK) {
  2875. for (var i = 0; i < results.length; i++) {
  2876. //createMarker(results[i]);
  2877. }
  2878. if (has_location) {
  2879. map.panTo(location);
  2880. } else {
  2881. if (results.length >= 1) {
  2882. map.panTo(results[0].geometry.location);
  2883. if (has_zoom) {
  2884. map.setZoom(zoom);
  2885. }
  2886. }
  2887. }
  2888. } else {
  2889. trace("Place search for " + search_request.query + " was not successful for the following reason: " + status);
  2890. // IF There's a problem loading the map, load a simple iFrame version instead
  2891. trace("YOU MAY NEED A GOOGLE MAPS API KEY IN ORDER TO USE THIS FEATURE OF TIMELINEJS");
  2892. trace("FIND OUT HOW TO GET YOUR KEY HERE: https://developers.google.com/places/documentation/#Authentication");
  2893. if (has_location) {
  2894. map.panTo(location);
  2895. if (has_zoom) {
  2896. map.setZoom(zoom);
  2897. }
  2898. } else {
  2899. trace("USING SIMPLE IFRAME MAP EMBED");
  2900. if (m.id[0].match("https")) {
  2901. m.id = m.url[0].replace("https", "http");
  2902. }
  2903. VMM.ExternalAPI.googlemaps.createiFrameMap(m);
  2904. }
  2905. }
  2906. }
  2907. function createMarker(place) {
  2908. var marker, placeLoc;
  2909. placeLoc = place.geometry.location;
  2910. marker = new google.maps.Marker({
  2911. map: map,
  2912. position: place.geometry.location
  2913. });
  2914. google.maps.event.addListener(marker, 'click', function() {
  2915. infowindow.setContent(place.name);
  2916. infowindow.open(map, this);
  2917. });
  2918. }
  2919. }
  2920. function loadPlacesAlt() {
  2921. var api_key,
  2922. places_url,
  2923. has_key = false;
  2924. trace("LOADING PLACES API FOR GOOGLE MAPS");
  2925. if (VMM.ExternalAPI.keys.google != "") {
  2926. api_key = VMM.ExternalAPI.keys.google;
  2927. has_key = true;
  2928. } else {
  2929. trace("YOU NEED A GOOGLE MAPS API KEY IN ORDER TO USE THIS FEATURE OF TIMELINEJS");
  2930. trace("FIND OUT HOW TO GET YOUR KEY HERE: https://developers.google.com/places/documentation/#Authentication");
  2931. }
  2932. places_url = "https://maps.googleapis.com/maps/api/place/textsearch/json?key=" + api_key + "&sensor=false&language=" + m.lang + "&";
  2933. if (type.of(VMM.Util.getUrlVars(m.id)["q"]) == "string") {
  2934. places_url += "query=" + VMM.Util.getUrlVars(m.id)["q"];
  2935. }
  2936. if (has_location) {
  2937. places_url += "&location=" + location;
  2938. }
  2939. if (has_key) {
  2940. VMM.getJSON(places_url, function(d) {
  2941. trace("PLACES JSON");
  2942. var places_location = "",
  2943. places_bounds = "",
  2944. places_bounds_ne = "",
  2945. places_bounds_sw = "";
  2946. trace(d);
  2947. if (d.status == "OVER_QUERY_LIMIT") {
  2948. trace("OVER_QUERY_LIMIT");
  2949. if (has_location) {
  2950. map.panTo(location);
  2951. if (has_zoom) {
  2952. map.setZoom(zoom);
  2953. }
  2954. } else {
  2955. trace("DOING TRADITIONAL MAP IFRAME EMBED UNTIL QUERY LIMIT RESTORED");
  2956. api_limit = true;
  2957. VMM.ExternalAPI.googlemaps.createiFrameMap(m);
  2958. }
  2959. } else {
  2960. if (d.results.length >= 1) {
  2961. //location = new google.maps.LatLng(parseFloat(d.results[0].geometry.location.lat),parseFloat(d.results[0].geometry.location.lng));
  2962. //map.panTo(location);
  2963. places_bounds_ne = new google.maps.LatLng(parseFloat(d.results[0].geometry.viewport.northeast.lat),parseFloat(d.results[0].geometry.viewport.northeast.lng));
  2964. places_bounds_sw = new google.maps.LatLng(parseFloat(d.results[0].geometry.viewport.southwest.lat),parseFloat(d.results[0].geometry.viewport.southwest.lng));
  2965. places_bounds = new google.maps.LatLngBounds(places_bounds_sw, places_bounds_ne)
  2966. map.fitBounds(places_bounds);
  2967. } else {
  2968. trace("NO RESULTS");
  2969. }
  2970. if (has_location) {
  2971. map.panTo(location);
  2972. }
  2973. if (has_zoom) {
  2974. map.setZoom(zoom);
  2975. }
  2976. }
  2977. })
  2978. .error(function(jqXHR, textStatus, errorThrown) {
  2979. trace("PLACES JSON ERROR");
  2980. trace("PLACES JSON ERROR: " + textStatus + " " + jqXHR.responseText);
  2981. })
  2982. .success(function(d) {
  2983. trace("PLACES JSON SUCCESS");
  2984. });
  2985. } else {
  2986. if (has_location) {
  2987. map.panTo(location);
  2988. if (has_zoom) {
  2989. map.setZoom(zoom);
  2990. }
  2991. } else {
  2992. trace("DOING TRADITIONAL MAP IFRAME EMBED BECAUSE NO GOOGLE MAP API KEY WAS PROVIDED");
  2993. VMM.ExternalAPI.googlemaps.createiFrameMap(m);
  2994. }
  2995. }
  2996. }
  2997. // KML
  2998. function loadKML() {
  2999. var kml_url, kml_layer, infowindow, text;
  3000. kml_url = m.id + "&output=kml";
  3001. kml_url = kml_url.replace("&output=embed", "");
  3002. kml_layer = new google.maps.KmlLayer(kml_url, {preserveViewport:true});
  3003. infowindow = new google.maps.InfoWindow();
  3004. kml_layer.setMap(map);
  3005. google.maps.event.addListenerOnce(kml_layer, "defaultviewport_changed", function() {
  3006. if (has_location) {
  3007. map.panTo(location);
  3008. } else {
  3009. map.fitBounds(kml_layer.getDefaultViewport() );
  3010. }
  3011. if (has_zoom) {
  3012. map.setZoom(zoom);
  3013. }
  3014. });
  3015. google.maps.event.addListener(kml_layer, 'click', function(kmlEvent) {
  3016. text = kmlEvent.featureData.description;
  3017. showInfoWindow(text);
  3018. function showInfoWindow(c) {
  3019. infowindow.setContent(c);
  3020. infowindow.open(map);
  3021. }
  3022. });
  3023. }
  3024. },
  3025. pushQue: function() {
  3026. for(var i = 0; i < VMM.master_config.googlemaps.que.length; i++) {
  3027. VMM.ExternalAPI.googlemaps.create(VMM.master_config.googlemaps.que[i]);
  3028. }
  3029. VMM.master_config.googlemaps.que = [];
  3030. },
  3031. onMapAPIReady: function() {
  3032. VMM.master_config.googlemaps.map_active = true;
  3033. VMM.master_config.googlemaps.places_active = true;
  3034. VMM.ExternalAPI.googlemaps.onAPIReady();
  3035. },
  3036. onPlacesAPIReady: function() {
  3037. VMM.master_config.googlemaps.places_active = true;
  3038. VMM.ExternalAPI.googlemaps.onAPIReady();
  3039. },
  3040. onAPIReady: function() {
  3041. if (!VMM.master_config.googlemaps.active) {
  3042. if (VMM.master_config.googlemaps.map_active && VMM.master_config.googlemaps.places_active) {
  3043. VMM.master_config.googlemaps.active = true;
  3044. VMM.ExternalAPI.googlemaps.pushQue();
  3045. }
  3046. }
  3047. },
  3048. defaultType: function(name) {
  3049. if (name.toLowerCase() == "satellite" || name.toLowerCase() == "hybrid" || name.toLowerCase() == "terrain" || name.toLowerCase() == "roadmap") {
  3050. return true;
  3051. } else {
  3052. return false;
  3053. }
  3054. },
  3055. map_subdomains: ["", "a.", "b.", "c.", "d."],
  3056. map_attribution: {
  3057. "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>.",
  3058. "apple": "Map data &copy; 2012 Apple, Imagery &copy; 2012 Apple",
  3059. "osm": "&copy; <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors"
  3060. },
  3061. map_providers: {
  3062. "toner": {
  3063. "url": "//{S}tile.stamen.com/toner/{Z}/{X}/{Y}.png",
  3064. "minZoom": 0,
  3065. "maxZoom": 20,
  3066. "attribution": "stamen"
  3067. },
  3068. "toner-lines": {
  3069. "url": "//{S}tile.stamen.com/toner-lines/{Z}/{X}/{Y}.png",
  3070. "minZoom": 0,
  3071. "maxZoom": 20,
  3072. "attribution": "stamen"
  3073. },
  3074. "toner-labels": {
  3075. "url": "//{S}tile.stamen.com/toner-labels/{Z}/{X}/{Y}.png",
  3076. "minZoom": 0,
  3077. "maxZoom": 20,
  3078. "attribution": "stamen"
  3079. },
  3080. "sterrain": {
  3081. "url": "//{S}tile.stamen.com/terrain/{Z}/{X}/{Y}.jpg",
  3082. "minZoom": 4,
  3083. "maxZoom": 20,
  3084. "attribution": "stamen"
  3085. },
  3086. "apple": {
  3087. "url": "//gsp2.apple.com/tile?api=1&style=slideshow&layers=default&lang=en_US&z={z}&x={x}&y={y}&v=9",
  3088. "minZoom": 4,
  3089. "maxZoom": 14,
  3090. "attribution": "apple"
  3091. },
  3092. "watercolor": {
  3093. "url": "//{S}tile.stamen.com/watercolor/{Z}/{X}/{Y}.jpg",
  3094. "minZoom": 3,
  3095. "maxZoom": 16,
  3096. "attribution": "stamen"
  3097. },
  3098. "osm": {
  3099. "url": "//tile.openstreetmap.org/{z}/{x}/{y}.png",
  3100. "minZoom": 3,
  3101. "maxZoom": 18,
  3102. "attribution": "osm"
  3103. }
  3104. }
  3105. },
  3106. googleplus: {
  3107. get: function(m) {
  3108. var api_key;
  3109. var gplus = {user: m.user, activity: m.id, id: m.uid};
  3110. VMM.master_config.googleplus.que.push(gplus);
  3111. VMM.master_config.googleplus.active = true;
  3112. },
  3113. create: function(gplus, callback) {
  3114. var mediaElem = "",
  3115. api_key = "",
  3116. g_activity = "",
  3117. g_content = "",
  3118. g_attachments = "",
  3119. gperson_api_url,
  3120. gactivity_api_url;
  3121. googleplus_timeout = setTimeout(VMM.ExternalAPI.googleplus.errorTimeOut, VMM.master_config.timers.api, gplus),
  3122. callback_timeout = setTimeout(callback, VMM.master_config.timers.api, gplus);
  3123. if (VMM.master_config.Timeline.api_keys.google != "") {
  3124. api_key = VMM.master_config.Timeline.api_keys.google;
  3125. } else {
  3126. api_key = Aes.Ctr.decrypt(VMM.master_config.api_keys_master.google, VMM.master_config.vp, 256);
  3127. }
  3128. 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;
  3129. //mediaElem = "<iframe class='doc' frameborder='0' width='100%' height='100%' src='" + gplus.url + "&amp;embedded=true'></iframe>";
  3130. mediaElem = "GOOGLE PLUS API CALL";
  3131. VMM.getJSON(gperson_api_url, function(p_data) {
  3132. for(var i = 0; i < p_data.items.length; i++) {
  3133. trace("loop");
  3134. if (p_data.items[i].url.split("posts/")[1] == gplus.activity) {
  3135. trace("FOUND IT!!");
  3136. g_activity = p_data.items[i].id;
  3137. gactivity_api_url = "https://www.googleapis.com/plus/v1/activities/" + g_activity + "?alt=json&key=" + api_key;
  3138. VMM.getJSON(gactivity_api_url, function(a_data) {
  3139. trace(a_data);
  3140. //a_data.url
  3141. //a_data.image.url
  3142. //a_data.actor.displayName
  3143. //a_data.provider.title
  3144. //a_data.object.content
  3145. //g_content += "<h4>" + a_data.title + "</h4>";
  3146. if (typeof a_data.annotation != 'undefined') {
  3147. g_content += "<div class='googleplus-annotation'>'" + a_data.annotation + "</div>";
  3148. g_content += a_data.object.content;
  3149. } else {
  3150. g_content += a_data.object.content;
  3151. }
  3152. if (typeof a_data.object.attachments != 'undefined') {
  3153. //g_attachments += "<div class='googleplus-attachemnts'>";
  3154. for(var k = 0; k < a_data.object.attachments.length; k++) {
  3155. if (a_data.object.attachments[k].objectType == "photo") {
  3156. 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;
  3157. } else if (a_data.object.attachments[k].objectType == "video") {
  3158. g_attachments = "<img src='" + a_data.object.attachments[k].image.url + "' class='article-thumb'>" + g_attachments;
  3159. g_attachments += "<div>";
  3160. g_attachments += "<a href='" + a_data.object.attachments[k].url + "' target='_blank'>"
  3161. g_attachments += "<h5>" + a_data.object.attachments[k].displayName + "</h5>";
  3162. //g_attachments += "<p>" + a_data.object.attachments[k].content + "</p>";
  3163. g_attachments += "</a>";
  3164. g_attachments += "</div>";
  3165. } else if (a_data.object.attachments[k].objectType == "article") {
  3166. g_attachments += "<div>";
  3167. g_attachments += "<a href='" + a_data.object.attachments[k].url + "' target='_blank'>"
  3168. g_attachments += "<h5>" + a_data.object.attachments[k].displayName + "</h5>";
  3169. g_attachments += "<p>" + a_data.object.attachments[k].content + "</p>";
  3170. g_attachments += "</a>";
  3171. g_attachments += "</div>";
  3172. }
  3173. trace(a_data.object.attachments[k]);
  3174. }
  3175. g_attachments = "<div class='googleplus-attachments'>" + g_attachments + "</div>";
  3176. }
  3177. //mediaElem = "<div class='googleplus'>";
  3178. mediaElem = "<div class='googleplus-content'>" + g_content + g_attachments + "</div>";
  3179. mediaElem += "<div class='vcard author'><a class='screen-name url' href='" + a_data.url + "' target='_blank'>";
  3180. mediaElem += "<span class='avatar'><img src='" + a_data.actor.image.url + "' style='max-width: 32px; max-height: 32px;'></span>"
  3181. mediaElem += "<span class='fn'>" + a_data.actor.displayName + "</span>";
  3182. mediaElem += "<span class='nickname'><span class='thumbnail-inline'></span></span>";
  3183. mediaElem += "</a></div>";
  3184. VMM.attachElement("#googleplus_" + gplus.activity, mediaElem);
  3185. });
  3186. break;
  3187. }
  3188. }
  3189. })
  3190. .error(function(jqXHR, textStatus, errorThrown) {
  3191. var error_obj = VMM.parseJSON(jqXHR.responseText);
  3192. trace(error_obj.error.message);
  3193. VMM.attachElement("#googleplus_" + gplus.activity, VMM.MediaElement.loadingmessage("<p>ERROR LOADING GOOGLE+ </p><p>" + error_obj.error.message + "</p>"));
  3194. })
  3195. .success(function(d) {
  3196. clearTimeout(googleplus_timeout);
  3197. clearTimeout(callback_timeout);
  3198. callback();
  3199. });
  3200. },
  3201. pushQue: function() {
  3202. if (VMM.master_config.googleplus.que.length > 0) {
  3203. VMM.ExternalAPI.googleplus.create(VMM.master_config.googleplus.que[0], VMM.ExternalAPI.googleplus.pushQue);
  3204. VMM.Util.removeRange(VMM.master_config.googleplus.que,0);
  3205. }
  3206. /*
  3207. for(var i = 0; i < VMM.master_config.googleplus.que.length; i++) {
  3208. VMM.ExternalAPI.googleplus.create(VMM.master_config.googleplus.que[i]);
  3209. }
  3210. VMM.master_config.googleplus.que = [];
  3211. */
  3212. },
  3213. errorTimeOut: function(gplus) {
  3214. trace("GOOGLE+ JSON ERROR TIMEOUT " + gplus.activity);
  3215. VMM.attachElement("#googleplus_" + gplus.activity, VMM.MediaElement.loadingmessage("<p>Still waiting on GOOGLE+ </p><p>" + gplus.activity + "</p>"));
  3216. }
  3217. },
  3218. googledocs: {
  3219. get: function(m) {
  3220. VMM.master_config.googledocs.que.push(m);
  3221. VMM.master_config.googledocs.active = true;
  3222. },
  3223. create: function(m) {
  3224. var mediaElem = "";
  3225. if (m.id.match(/docs.google.com/i)) {
  3226. mediaElem = "<iframe class='doc' frameborder='0' width='100%' height='100%' src='" + m.id + "&amp;embedded=true'></iframe>";
  3227. } else {
  3228. mediaElem = "<iframe class='doc' frameborder='0' width='100%' height='100%' src='" + "//docs.google.com/viewer?url=" + m.id + "&amp;embedded=true'></iframe>";
  3229. }
  3230. VMM.attachElement("#"+m.uid, mediaElem);
  3231. },
  3232. pushQue: function() {
  3233. for(var i = 0; i < VMM.master_config.googledocs.que.length; i++) {
  3234. VMM.ExternalAPI.googledocs.create(VMM.master_config.googledocs.que[i]);
  3235. }
  3236. VMM.master_config.googledocs.que = [];
  3237. }
  3238. },
  3239. flickr: {
  3240. get: function(m) {
  3241. VMM.master_config.flickr.que.push(m);
  3242. VMM.master_config.flickr.active = true;
  3243. },
  3244. create: function(m, callback) {
  3245. var api_key,
  3246. callback_timeout= setTimeout(callback, VMM.master_config.timers.api, m);
  3247. if (typeof VMM.master_config.Timeline != 'undefined' && VMM.master_config.Timeline.api_keys.flickr != "") {
  3248. api_key = VMM.master_config.Timeline.api_keys.flickr;
  3249. } else {
  3250. api_key = Aes.Ctr.decrypt(VMM.master_config.api_keys_master.flickr, VMM.master_config.vp, 256)
  3251. }
  3252. var the_url = "https://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=" + api_key + "&photo_id=" + m.id + "&format=json&jsoncallback=?";
  3253. VMM.getJSON(the_url, function(d) {
  3254. var flickr_id = VMM.ExternalAPI.flickr.getFlickrIdFromUrl(d.sizes.size[0].url);
  3255. var flickr_large_id = "#" + m.uid,
  3256. flickr_thumb_id = "#" + m.uid + "_thumb";
  3257. //flickr_thumb_id = "flickr_" + uid + "_thumb";
  3258. var flickr_img_size,
  3259. flickr_img_thumb,
  3260. flickr_size_found = false,
  3261. flickr_best_size = "Large";
  3262. flickr_best_size = VMM.ExternalAPI.flickr.sizes(VMM.master_config.sizes.api.height);
  3263. for(var i = 0; i < d.sizes.size.length; i++) {
  3264. if (d.sizes.size[i].label == flickr_best_size) {
  3265. flickr_size_found = true;
  3266. flickr_img_size = d.sizes.size[i].source;
  3267. }
  3268. }
  3269. if (!flickr_size_found) {
  3270. flickr_img_size = d.sizes.size[d.sizes.size.length - 2].source;
  3271. }
  3272. flickr_img_thumb = d.sizes.size[0].source;
  3273. VMM.Lib.attr(flickr_large_id, "src", flickr_img_size);
  3274. //VMM.attachElement(flickr_large_id, "<a href='" + flick.link + "' target='_blank'><img src='" + flickr_img_size + "'></a>");
  3275. VMM.attachElement(flickr_thumb_id, "<img src='" + flickr_img_thumb + "'>");
  3276. })
  3277. .error(function(jqXHR, textStatus, errorThrown) {
  3278. trace("FLICKR error");
  3279. trace("FLICKR ERROR: " + textStatus + " " + jqXHR.responseText);
  3280. })
  3281. .success(function(d) {
  3282. clearTimeout(callback_timeout);
  3283. callback();
  3284. });
  3285. },
  3286. pushQue: function() {
  3287. if (VMM.master_config.flickr.que.length > 0) {
  3288. VMM.ExternalAPI.flickr.create(VMM.master_config.flickr.que[0], VMM.ExternalAPI.flickr.pushQue);
  3289. VMM.Util.removeRange(VMM.master_config.flickr.que,0);
  3290. }
  3291. },
  3292. sizes: function(s) {
  3293. var _size = "";
  3294. if (s <= 75) {
  3295. _size = "Thumbnail";
  3296. } else if (s <= 180) {
  3297. _size = "Small";
  3298. } else if (s <= 240) {
  3299. _size = "Small 320";
  3300. } else if (s <= 375) {
  3301. _size = "Medium";
  3302. } else if (s <= 480) {
  3303. _size = "Medium 640";
  3304. } else if (s <= 600) {
  3305. _size = "Large";
  3306. } else {
  3307. _size = "Large";
  3308. }
  3309. return _size;
  3310. },
  3311. getFlickrIdFromUrl: function(url) {
  3312. var idx = url.indexOf("flickr.com/photos/");
  3313. if (idx == -1) return null;
  3314. var pos = idx + "flickr.com/photos/".length;
  3315. var photo_info = url.substr(pos)
  3316. if (photo_info.indexOf('/') == -1) return null;
  3317. if (photo_info.indexOf('/') == 0) photo_info = photo_info.substr(1);
  3318. return photo_info.split("/")[1];
  3319. }
  3320. },
  3321. instagram: {
  3322. get: function(m, thumb) {
  3323. if (thumb) {
  3324. return "//instagr.am/p/" + m.id + "/media/?size=t";
  3325. } else {
  3326. return "//instagr.am/p/" + m.id + "/media/?size=" + VMM.ExternalAPI.instagram.sizes(VMM.master_config.sizes.api.height);
  3327. }
  3328. },
  3329. sizes: function(s) {
  3330. var _size = "";
  3331. if (s <= 150) {
  3332. _size = "t";
  3333. } else if (s <= 306) {
  3334. _size = "m";
  3335. } else {
  3336. _size = "l";
  3337. }
  3338. return _size;
  3339. },
  3340. isInstagramUrl: function(url) {
  3341. return url.match("instagr.am/p/") || url.match("instagram.com/p/");
  3342. },
  3343. getInstagramIdFromUrl: function(url) {
  3344. try {
  3345. return url.split("\/p\/")[1].split("/")[0];
  3346. } catch(e) {
  3347. trace("Invalid Instagram url: " + url);
  3348. return null;
  3349. }
  3350. }
  3351. },
  3352. soundcloud: {
  3353. get: function(m) {
  3354. VMM.master_config.soundcloud.que.push(m);
  3355. VMM.master_config.soundcloud.active = true;
  3356. },
  3357. create: function(m, callback) {
  3358. var the_url = "//soundcloud.com/oembed?url=" + m.id + "&maxheight=168&format=js&callback=?";
  3359. VMM.getJSON(the_url, function(d) {
  3360. VMM.attachElement("#"+m.uid, d.html);
  3361. callback();
  3362. });
  3363. },
  3364. pushQue: function() {
  3365. if (VMM.master_config.soundcloud.que.length > 0) {
  3366. VMM.ExternalAPI.soundcloud.create(VMM.master_config.soundcloud.que[0], VMM.ExternalAPI.soundcloud.pushQue);
  3367. VMM.Util.removeRange(VMM.master_config.soundcloud.que,0);
  3368. }
  3369. }
  3370. },
  3371. wikipedia: {
  3372. get: function(m) {
  3373. VMM.master_config.wikipedia.que.push(m);
  3374. VMM.master_config.wikipedia.active = true;
  3375. },
  3376. create: function(m, callback) {
  3377. var the_url = "//" + m.lang + ".wikipedia.org/w/api.php?action=query&prop=extracts&redirects=&titles=" + m.id + "&exintro=1&format=json&callback=?";
  3378. callback_timeout= setTimeout(callback, VMM.master_config.timers.api, m);
  3379. if ( VMM.Browser.browser == "Explorer" && parseInt(VMM.Browser.version, 10) >= 7 && window.XDomainRequest) {
  3380. var temp_text = "<h4><a href='http://" + VMM.master_config.language.api.wikipedia + ".wikipedia.org/wiki/" + m.id + "' target='_blank'>" + m.url + "</a></h4>";
  3381. temp_text += "<span class='wiki-source'>" + VMM.master_config.language.messages.wikipedia + "</span>";
  3382. temp_text += "<p>Wikipedia entry unable to load using Internet Explorer 8 or below.</p>";
  3383. VMM.attachElement("#"+m.uid, temp_text );
  3384. }
  3385. VMM.getJSON(the_url, function(d) {
  3386. if (d.query) {
  3387. var wiki_extract,
  3388. wiki_title,
  3389. _wiki = "",
  3390. wiki_text = "",
  3391. wiki_number_of_paragraphs = 1,
  3392. wiki_text_array = [];
  3393. wiki_extract = VMM.Util.getObjectAttributeByIndex(d.query.pages, 0).extract;
  3394. wiki_title = VMM.Util.getObjectAttributeByIndex(d.query.pages, 0).title;
  3395. if (wiki_extract.match("<p>")) {
  3396. wiki_text_array = wiki_extract.split("<p>");
  3397. } else {
  3398. wiki_text_array.push(wiki_extract);
  3399. }
  3400. for(var i = 0; i < wiki_text_array.length; i++) {
  3401. if (i+1 <= wiki_number_of_paragraphs && i+1 < wiki_text_array.length) {
  3402. wiki_text += "<p>" + wiki_text_array[i+1];
  3403. }
  3404. }
  3405. _wiki = "<h4><a href='http://" + VMM.master_config.language.api.wikipedia + ".wikipedia.org/wiki/" + wiki_title + "' target='_blank'>" + wiki_title + "</a></h4>";
  3406. _wiki += "<span class='wiki-source'>" + VMM.master_config.language.messages.wikipedia + "</span>";
  3407. _wiki += VMM.Util.linkify_wikipedia(wiki_text);
  3408. if (wiki_extract.match("REDIRECT")) {
  3409. } else {
  3410. VMM.attachElement("#"+m.uid, _wiki );
  3411. }
  3412. }
  3413. //callback();
  3414. })
  3415. .error(function(jqXHR, textStatus, errorThrown) {
  3416. trace("WIKIPEDIA error");
  3417. trace("WIKIPEDIA ERROR: " + textStatus + " " + jqXHR.responseText);
  3418. trace(errorThrown);
  3419. VMM.attachElement("#"+m.uid, VMM.MediaElement.loadingmessage("<p>Wikipedia is not responding</p>"));
  3420. // TRY AGAIN?
  3421. clearTimeout(callback_timeout);
  3422. if (VMM.master_config.wikipedia.tries < 4) {
  3423. trace("WIKIPEDIA ATTEMPT " + VMM.master_config.wikipedia.tries);
  3424. trace(m);
  3425. VMM.master_config.wikipedia.tries++;
  3426. VMM.ExternalAPI.wikipedia.create(m, callback);
  3427. } else {
  3428. callback();
  3429. }
  3430. })
  3431. .success(function(d) {
  3432. VMM.master_config.wikipedia.tries = 0;
  3433. clearTimeout(callback_timeout);
  3434. callback();
  3435. });
  3436. },
  3437. pushQue: function() {
  3438. if (VMM.master_config.wikipedia.que.length > 0) {
  3439. trace("WIKIPEDIA PUSH QUE " + VMM.master_config.wikipedia.que.length);
  3440. VMM.ExternalAPI.wikipedia.create(VMM.master_config.wikipedia.que[0], VMM.ExternalAPI.wikipedia.pushQue);
  3441. VMM.Util.removeRange(VMM.master_config.wikipedia.que,0);
  3442. }
  3443. }
  3444. },
  3445. youtube: {
  3446. get: function(m) {
  3447. var the_url = "//gdata.youtube.com/feeds/api/videos/" + m.id + "?v=2&alt=jsonc&callback=?";
  3448. VMM.master_config.youtube.que.push(m);
  3449. if (!VMM.master_config.youtube.active) {
  3450. if (!VMM.master_config.youtube.api_loaded) {
  3451. LoadLib.js('//www.youtube.com/player_api', function() {
  3452. trace("YouTube API Library Loaded");
  3453. });
  3454. }
  3455. }
  3456. // THUMBNAIL
  3457. VMM.getJSON(the_url, function(d) {
  3458. VMM.ExternalAPI.youtube.createThumb(d, m)
  3459. });
  3460. },
  3461. create: function(m) {
  3462. if (typeof(m.start) != 'undefined') {
  3463. var vidstart = m.start.toString(),
  3464. vid_start_minutes = 0,
  3465. vid_start_seconds = 0;
  3466. if (vidstart.match('m')) {
  3467. vid_start_minutes = parseInt(vidstart.split("m")[0], 10);
  3468. vid_start_seconds = parseInt(vidstart.split("m")[1].split("s")[0], 10);
  3469. m.start = (vid_start_minutes * 60) + vid_start_seconds;
  3470. } else {
  3471. m.start = 0;
  3472. }
  3473. } else {
  3474. m.start = 0;
  3475. }
  3476. var p = {
  3477. active: false,
  3478. player: {},
  3479. name: m.uid,
  3480. playing: false,
  3481. hd: false
  3482. };
  3483. if (typeof(m.hd) != 'undefined') {
  3484. p.hd = true;
  3485. }
  3486. p.player[m.id] = new YT.Player(m.uid, {
  3487. height: '390',
  3488. width: '640',
  3489. playerVars: {
  3490. enablejsapi: 1,
  3491. color: 'white',
  3492. showinfo: 0,
  3493. theme: 'light',
  3494. start: m.start,
  3495. rel: 0
  3496. },
  3497. videoId: m.id,
  3498. events: {
  3499. 'onReady': VMM.ExternalAPI.youtube.onPlayerReady,
  3500. 'onStateChange': VMM.ExternalAPI.youtube.onStateChange
  3501. }
  3502. });
  3503. VMM.master_config.youtube.array.push(p);
  3504. },
  3505. createThumb: function(d, m) {
  3506. trace("CREATE THUMB");
  3507. trace(d);
  3508. trace(m);
  3509. if (typeof d.data != 'undefined') {
  3510. var thumb_id = "#" + m.uid + "_thumb";
  3511. VMM.attachElement(thumb_id, "<img src='" + d.data.thumbnail.sqDefault + "'>");
  3512. }
  3513. },
  3514. pushQue: function() {
  3515. for(var i = 0; i < VMM.master_config.youtube.que.length; i++) {
  3516. VMM.ExternalAPI.youtube.create(VMM.master_config.youtube.que[i]);
  3517. }
  3518. VMM.master_config.youtube.que = [];
  3519. },
  3520. onAPIReady: function() {
  3521. VMM.master_config.youtube.active = true;
  3522. VMM.ExternalAPI.youtube.pushQue();
  3523. },
  3524. stopPlayers: function() {
  3525. for(var i = 0; i < VMM.master_config.youtube.array.length; i++) {
  3526. if (VMM.master_config.youtube.array[i].playing) {
  3527. if (typeof VMM.master_config.youtube.array[i].player.the_name !== 'undefined') {
  3528. VMM.master_config.youtube.array[i].player.the_name.stopVideo();
  3529. }
  3530. }
  3531. }
  3532. },
  3533. onStateChange: function(e) {
  3534. for(var i = 0; i < VMM.master_config.youtube.array.length; i++) {
  3535. for (var z in VMM.master_config.youtube.array[i].player) {
  3536. if (VMM.master_config.youtube.array[i].player[z] == e.target) {
  3537. VMM.master_config.youtube.array[i].player.the_name = VMM.master_config.youtube.array[i].player[z];
  3538. }
  3539. }
  3540. if (VMM.master_config.youtube.array[i].player.the_name == e.target) {
  3541. if (e.data == YT.PlayerState.PLAYING) {
  3542. VMM.master_config.youtube.array[i].playing = true;
  3543. if (VMM.master_config.youtube.array[i].hd === false) {
  3544. VMM.master_config.youtube.array[i].hd = true;
  3545. VMM.master_config.youtube.array[i].player.the_name.setPlaybackQuality("hd720");
  3546. }
  3547. }
  3548. }
  3549. }
  3550. },
  3551. onPlayerReady: function(e) {
  3552. }
  3553. },
  3554. vimeo: {
  3555. get: function(m) {
  3556. VMM.master_config.vimeo.que.push(m);
  3557. VMM.master_config.vimeo.active = true;
  3558. },
  3559. create: function(m, callback) {
  3560. trace("VIMEO CREATE");
  3561. // THUMBNAIL
  3562. var thumb_url = "//vimeo.com/api/v2/video/" + m.id + ".json",
  3563. video_url = "//player.vimeo.com/video/" + m.id + "?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff";
  3564. VMM.getJSON(thumb_url, function(d) {
  3565. VMM.ExternalAPI.vimeo.createThumb(d, m);
  3566. callback();
  3567. });
  3568. // VIDEO
  3569. VMM.attachElement("#" + m.uid, "<iframe autostart='false' frameborder='0' width='100%' height='100%' src='" + video_url + "'></iframe>");
  3570. },
  3571. createThumb: function(d, m) {
  3572. trace("VIMEO CREATE THUMB");
  3573. var thumb_id = "#" + m.uid + "_thumb";
  3574. VMM.attachElement(thumb_id, "<img src='" + d[0].thumbnail_small + "'>");
  3575. },
  3576. pushQue: function() {
  3577. if (VMM.master_config.vimeo.que.length > 0) {
  3578. VMM.ExternalAPI.vimeo.create(VMM.master_config.vimeo.que[0], VMM.ExternalAPI.vimeo.pushQue);
  3579. VMM.Util.removeRange(VMM.master_config.vimeo.que,0);
  3580. }
  3581. }
  3582. },
  3583. vine: {
  3584. get: function(m) {
  3585. VMM.master_config.vine.que.push(m);
  3586. VMM.master_config.vine.active = true;
  3587. },
  3588. create: function(m, callback) {
  3589. trace("VINE CREATE");
  3590. var video_url = "https://vine.co/v/" + m.id + "/embed/simple";
  3591. // VIDEO
  3592. // TODO: NEED TO ADD ASYNC SCRIPT TO TIMELINE FLOW
  3593. VMM.attachElement("#" + m.uid, "<iframe frameborder='0' width='100%' height='100%' src='" + video_url + "'></iframe><script async src='http://platform.vine.co/static/scripts/embed.js' charset='utf-8'></script>");
  3594. },
  3595. pushQue: function() {
  3596. if (VMM.master_config.vine.que.length > 0) {
  3597. VMM.ExternalAPI.vine.create(VMM.master_config.vine.que[0], VMM.ExternalAPI.vine.pushQue);
  3598. VMM.Util.removeRange(VMM.master_config.vine.que,0);
  3599. }
  3600. }
  3601. },
  3602. webthumb: {
  3603. get: function(m, thumb) {
  3604. VMM.master_config.webthumb.que.push(m);
  3605. VMM.master_config.webthumb.active = true;
  3606. },
  3607. sizes: function(s) {
  3608. var _size = "";
  3609. if (s <= 150) {
  3610. _size = "t";
  3611. } else if (s <= 306) {
  3612. _size = "m";
  3613. } else {
  3614. _size = "l";
  3615. }
  3616. return _size;
  3617. },
  3618. create: function(m) {
  3619. trace("WEB THUMB CREATE");
  3620. var thumb_url = "//api.pagepeeker.com/v2/thumbs.php?";
  3621. url = m.id.replace("http://", "");//.split("/")[0];
  3622. // Main Image
  3623. VMM.attachElement("#" + m.uid, "<a href='" + m.id + "' target='_blank'><img src='" + thumb_url + "size=x&url=" + url + "'></a>");
  3624. // Thumb
  3625. VMM.attachElement("#" + m.uid + "_thumb", "<img src='" + thumb_url + "size=t&url=" + url + "'>");
  3626. },
  3627. pushQue: function() {
  3628. for(var i = 0; i < VMM.master_config.webthumb.que.length; i++) {
  3629. VMM.ExternalAPI.webthumb.create(VMM.master_config.webthumb.que[i]);
  3630. }
  3631. VMM.master_config.webthumb.que = [];
  3632. }
  3633. }
  3634. }).init();
  3635. }
  3636. /* YOUTUBE API READY
  3637. Can't find a way to customize this callback and keep it in the VMM namespace
  3638. Youtube wants it to be this function.
  3639. ================================================== */
  3640. function onYouTubePlayerAPIReady() {
  3641. trace("GLOBAL YOUTUBE API CALLED")
  3642. VMM.ExternalAPI.youtube.onAPIReady();
  3643. }
  3644. /* **********************************************
  3645. Begin VMM.MediaElement.js
  3646. ********************************************** */
  3647. /* MediaElement
  3648. ================================================== */
  3649. if(typeof VMM != 'undefined' && typeof VMM.MediaElement == 'undefined') {
  3650. VMM.MediaElement = ({
  3651. init: function() {
  3652. return this;
  3653. },
  3654. loadingmessage: function(m) {
  3655. return "<div class='vco-loading'><div class='vco-loading-container'><div class='vco-loading-icon'></div>" + "<div class='vco-message'><p>" + m + "</p></div></div></div>";
  3656. },
  3657. thumbnail: function(data, w, h, uid) {
  3658. var _w = 16,
  3659. _h = 24,
  3660. _uid = "";
  3661. if (w != null && w != "") {_w = w};
  3662. if (h != null && h != "") {_h = h};
  3663. if (uid != null && uid != "") {_uid = uid};
  3664. if (data.thumbnail != null && data.thumbnail != "") {
  3665. trace("CUSTOM THUMB");
  3666. mediaElem = "<div class='thumbnail thumb-custom' id='" + uid + "_custom_thumb'><img src='" + data.thumbnail + "'></div>";
  3667. return mediaElem;
  3668. } else if (data.media != null && data.media != "") {
  3669. var _valid = true,
  3670. mediaElem = "",
  3671. m = VMM.MediaType(data.media); //returns an object with .type and .id
  3672. // DETERMINE THUMBNAIL OR ICON
  3673. if (m.type == "image") {
  3674. mediaElem = "<div class='thumbnail thumb-photo'></div>";
  3675. return mediaElem;
  3676. } else if (m.type == "flickr") {
  3677. mediaElem = "<div class='thumbnail thumb-photo' id='" + uid + "_thumb'></div>";
  3678. return mediaElem;
  3679. } else if (m.type == "instagram") {
  3680. mediaElem = "<div class='thumbnail thumb-instagram' id='" + uid + "_thumb'><img src='" + VMM.ExternalAPI.instagram.get(m, true) + "'></div>";
  3681. return mediaElem;
  3682. } else if (m.type == "youtube") {
  3683. mediaElem = "<div class='thumbnail thumb-youtube' id='" + uid + "_thumb'></div>";
  3684. return mediaElem;
  3685. } else if (m.type == "googledoc") {
  3686. mediaElem = "<div class='thumbnail thumb-document'></div>";
  3687. return mediaElem;
  3688. } else if (m.type == "vimeo") {
  3689. mediaElem = "<div class='thumbnail thumb-vimeo' id='" + uid + "_thumb'></div>";
  3690. return mediaElem;
  3691. } else if (m.type == "vine") {
  3692. mediaElem = "<div class='thumbnail thumb-vine'></div>";
  3693. return mediaElem;
  3694. } else if (m.type == "dailymotion") {
  3695. mediaElem = "<div class='thumbnail thumb-video'></div>";
  3696. return mediaElem;
  3697. } else if (m.type == "twitter"){
  3698. mediaElem = "<div class='thumbnail thumb-twitter'></div>";
  3699. return mediaElem;
  3700. } else if (m.type == "twitter-ready") {
  3701. mediaElem = "<div class='thumbnail thumb-twitter'></div>";
  3702. return mediaElem;
  3703. } else if (m.type == "soundcloud") {
  3704. mediaElem = "<div class='thumbnail thumb-audio'></div>";
  3705. return mediaElem;
  3706. } else if (m.type == "google-map") {
  3707. mediaElem = "<div class='thumbnail thumb-map'></div>";
  3708. return mediaElem;
  3709. } else if (m.type == "googleplus") {
  3710. mediaElem = "<div class='thumbnail thumb-googleplus'></div>";
  3711. return mediaElem;
  3712. } else if (m.type == "wikipedia") {
  3713. mediaElem = "<div class='thumbnail thumb-wikipedia'></div>";
  3714. return mediaElem;
  3715. } else if (m.type == "storify") {
  3716. mediaElem = "<div class='thumbnail thumb-storify'></div>";
  3717. return mediaElem;
  3718. } else if (m.type == "quote") {
  3719. mediaElem = "<div class='thumbnail thumb-quote'></div>";
  3720. return mediaElem;
  3721. } else if (m.type == "iframe") {
  3722. mediaElem = "<div class='thumbnail thumb-video'></div>";
  3723. return mediaElem;
  3724. } else if (m.type == "unknown") {
  3725. if (m.id.match("blockquote")) {
  3726. mediaElem = "<div class='thumbnail thumb-quote'></div>";
  3727. } else {
  3728. mediaElem = "<div class='thumbnail thumb-plaintext'></div>";
  3729. }
  3730. return mediaElem;
  3731. } else if (m.type == "website") {
  3732. mediaElem = "<div class='thumbnail thumb-website' id='" + uid + "_thumb'></div>";
  3733. return mediaElem;
  3734. } else {
  3735. mediaElem = "<div class='thumbnail thumb-plaintext'></div>";
  3736. return mediaElem;
  3737. }
  3738. }
  3739. },
  3740. create: function(data, uid) {
  3741. var _valid = false,
  3742. //loading_messege = "<span class='messege'><p>" + VMM.master_config.language.messages.loading + "</p></span>";
  3743. loading_messege = VMM.MediaElement.loadingmessage(VMM.master_config.language.messages.loading + "...");
  3744. if (data.media != null && data.media != "") {
  3745. var mediaElem = "", captionElem = "", creditElem = "", _id = "", isTextMedia = false, m;
  3746. m = VMM.MediaType(data.media); //returns an object with .type and .id
  3747. m.uid = uid;
  3748. _valid = true;
  3749. // CREDIT
  3750. if (data.credit != null && data.credit != "") {
  3751. creditElem = "<div class='credit'>" + VMM.Util.linkify_with_twitter(data.credit, "_blank") + "</div>";
  3752. }
  3753. // CAPTION
  3754. if (data.caption != null && data.caption != "") {
  3755. captionElem = "<div class='caption'>" + VMM.Util.linkify_with_twitter(data.caption, "_blank") + "</div>";
  3756. }
  3757. // IMAGE
  3758. if (m.type == "image") {
  3759. mediaElem = "<div class='media-image media-shadow'><img src='" + m.id + "' class='media-image'></div>";
  3760. // FLICKR
  3761. } else if (m.type == "flickr") {
  3762. //mediaElem = "<div class='media-image media-shadow' id='" + uid + "'>" + loading_messege + "</div>";
  3763. mediaElem = "<div class='media-image media-shadow'><a href='" + m.link + "' target='_blank'><img id='" + uid + "'></a></div>";
  3764. VMM.ExternalAPI.flickr.get(m);
  3765. // INSTAGRAM
  3766. } else if (m.type == "instagram") {
  3767. mediaElem = "<div class='media-image media-shadow'><a href='" + m.link + "' target='_blank'><img src='" + VMM.ExternalAPI.instagram.get(m) + "'></a></div>";
  3768. // GOOGLE DOCS
  3769. } else if (m.type == "googledoc") {
  3770. mediaElem = "<div class='media-frame media-shadow doc' id='" + m.uid + "'>" + loading_messege + "</div>";
  3771. VMM.ExternalAPI.googledocs.get(m);
  3772. // YOUTUBE
  3773. } else if (m.type == "youtube") {
  3774. mediaElem = "<div class='media-shadow'><div class='media-frame video youtube' id='" + m.uid + "'>" + loading_messege + "</div></div>";
  3775. VMM.ExternalAPI.youtube.get(m);
  3776. // VIMEO
  3777. } else if (m.type == "vimeo") {
  3778. mediaElem = "<div class='media-shadow media-frame video vimeo' id='" + m.uid + "'>" + loading_messege + "</div>";
  3779. VMM.ExternalAPI.vimeo.get(m);
  3780. // DAILYMOTION
  3781. } else if (m.type == "dailymotion") {
  3782. mediaElem = "<div class='media-shadow'><iframe class='media-frame video dailymotion' autostart='false' frameborder='0' width='100%' height='100%' src='http://www.dailymotion.com/embed/video/" + m.id + "'></iframe></div>";
  3783. // VINE
  3784. } else if (m.type == "vine") {
  3785. mediaElem = "<div class='media-shadow media-frame video vine' id='" + m.uid + "'>" + loading_messege + "</div>";
  3786. VMM.ExternalAPI.vine.get(m);
  3787. // TWITTER
  3788. } else if (m.type == "twitter"){
  3789. mediaElem = "<div class='twitter' id='" + m.uid + "'>" + loading_messege + "</div>";
  3790. isTextMedia = true;
  3791. VMM.ExternalAPI.twitter.get(m);
  3792. // TWITTER
  3793. } else if (m.type == "twitter-ready") {
  3794. isTextMedia = true;
  3795. mediaElem = m.id;
  3796. // SOUNDCLOUD
  3797. } else if (m.type == "soundcloud") {
  3798. mediaElem = "<div class='media-frame media-shadow soundcloud' id='" + m.uid + "'>" + loading_messege + "</div>";
  3799. VMM.ExternalAPI.soundcloud.get(m);
  3800. // GOOGLE MAPS
  3801. } else if (m.type == "google-map") {
  3802. mediaElem = "<div class='media-frame media-shadow map' id='" + m.uid + "'>" + loading_messege + "</div>";
  3803. VMM.ExternalAPI.googlemaps.get(m);
  3804. // GOOGLE PLUS
  3805. } else if (m.type == "googleplus") {
  3806. _id = "googleplus_" + m.id;
  3807. mediaElem = "<div class='googleplus' id='" + _id + "'>" + loading_messege + "</div>";
  3808. isTextMedia = true;
  3809. VMM.ExternalAPI.googleplus.get(m);
  3810. // WIKIPEDIA
  3811. } else if (m.type == "wikipedia") {
  3812. mediaElem = "<div class='wikipedia' id='" + m.uid + "'>" + loading_messege + "</div>";
  3813. isTextMedia = true;
  3814. VMM.ExternalAPI.wikipedia.get(m);
  3815. // STORIFY
  3816. } else if (m.type == "storify") {
  3817. isTextMedia = true;
  3818. mediaElem = "<div class='plain-text-quote'>" + m.id + "</div>";
  3819. // IFRAME
  3820. } else if (m.type == "iframe") {
  3821. isTextMedia = true;
  3822. mediaElem = "<div class='media-shadow'><iframe class='media-frame video' autostart='false' frameborder='0' width='100%' height='100%' src='" + m.id + "'></iframe></div>";
  3823. // QUOTE
  3824. } else if (m.type == "quote") {
  3825. isTextMedia = true;
  3826. mediaElem = "<div class='plain-text-quote'>" + m.id + "</div>";
  3827. // UNKNOWN
  3828. } else if (m.type == "unknown") {
  3829. trace("NO KNOWN MEDIA TYPE FOUND TRYING TO JUST PLACE THE HTML");
  3830. isTextMedia = true;
  3831. mediaElem = "<div class='plain-text'><div class='container'>" + VMM.Util.properQuotes(m.id) + "</div></div>";
  3832. // WEBSITE
  3833. } else if (m.type == "website") {
  3834. mediaElem = "<div class='media-shadow website' id='" + m.uid + "'>" + loading_messege + "</div>";
  3835. VMM.ExternalAPI.webthumb.get(m);
  3836. //mediaElem = "<div class='media-shadow website'><a href='" + m.id + "' target='_blank'>" + "<img src='http://api1.thumbalizr.com/?url=" + m.id.replace(/[\./]$/g, "") + "&width=300' class='media-image'></a></div>";
  3837. // NO MATCH
  3838. } else {
  3839. trace("NO KNOWN MEDIA TYPE FOUND");
  3840. trace(m.type);
  3841. }
  3842. // WRAP THE MEDIA ELEMENT
  3843. mediaElem = "<div class='media-container' >" + mediaElem + creditElem + captionElem + "</div>";
  3844. // RETURN
  3845. if (isTextMedia) {
  3846. return "<div class='text-media'><div class='media-wrapper'>" + mediaElem + "</div></div>";
  3847. } else {
  3848. return "<div class='media-wrapper'>" + mediaElem + "</div>";
  3849. }
  3850. };
  3851. }
  3852. }).init();
  3853. }
  3854. /* **********************************************
  3855. Begin VMM.MediaType.js
  3856. ********************************************** */
  3857. /* MediaType
  3858. Determines the type of media the url string is.
  3859. returns an object with .type and .id
  3860. the id is a key piece of information needed to make
  3861. the request of the api.
  3862. ================================================== */
  3863. if(typeof VMM != 'undefined' && typeof VMM.MediaType == 'undefined') {
  3864. VMM.MediaType = function(_d) {
  3865. var d = _d.replace(/^\s\s*/, '').replace(/\s\s*$/, ''),
  3866. success = false,
  3867. media = {
  3868. type: "unknown",
  3869. id: "",
  3870. start: 0,
  3871. hd: false,
  3872. link: "",
  3873. lang: VMM.Language.lang,
  3874. uniqueid: VMM.Util.unique_ID(6)
  3875. };
  3876. if (d.match("div class='twitter'")) {
  3877. media.type = "twitter-ready";
  3878. media.id = d;
  3879. success = true;
  3880. } else if (d.match('<blockquote')) {
  3881. media.type = "quote";
  3882. media.id = d;
  3883. success = true;
  3884. } else if (d.match('<iframe')) {
  3885. media.type = "iframe";
  3886. trace("IFRAME")
  3887. regex = /src=['"](\S+?)['"]/;
  3888. group = d.match(regex);
  3889. if (group) {
  3890. media.id = group[1];
  3891. }
  3892. trace( "iframe url: " + media.id );
  3893. success = Boolean(media.id);
  3894. } else if (d.match('(www.)?youtube|youtu\.be')) {
  3895. if (d.match('v=')) {
  3896. media.id = VMM.Util.getUrlVars(d)["v"];
  3897. } else if (d.match('\/embed\/')) {
  3898. // TODO Issue #618 better splitting
  3899. media.id = d.split("embed\/")[1].split(/[?&]/)[0];
  3900. } else if (d.match(/v\/|v=|youtu\.be\//)){
  3901. media.id = d.split(/v\/|v=|youtu\.be\//)[1].split(/[?&]/)[0];
  3902. } else {
  3903. trace("YOUTUBE IN URL BUT NOT A VALID VIDEO");
  3904. }
  3905. media.start = VMM.Util.getUrlVars(d)["t"];
  3906. media.hd = VMM.Util.getUrlVars(d)["hd"];
  3907. media.type = "youtube";
  3908. success = true;
  3909. } else if (d.match('(player.)?vimeo\.com')) {
  3910. media.type = "vimeo";
  3911. media.id = d.split(/video\/|\/\/vimeo\.com\//)[1].split(/[?&]/)[0];;
  3912. success = true;
  3913. } else if (d.match('(www.)?dailymotion\.com')) {
  3914. media.id = d.split(/video\/|\/\/dailymotion\.com\//)[1];
  3915. media.type = "dailymotion";
  3916. success = true;
  3917. } else if (d.match('(www.)?vine\.co')) {
  3918. trace("VINE");
  3919. //https://vine.co/v/b55LOA1dgJU
  3920. if (d.match("vine.co/v/")) {
  3921. media.id = d.split("vine.co/v/")[1];
  3922. trace(media.id);
  3923. }
  3924. trace(d);
  3925. media.type = "vine";
  3926. success = true;
  3927. } else if (d.match('(player.)?soundcloud\.com')) {
  3928. media.type = "soundcloud";
  3929. media.id = d;
  3930. success = true;
  3931. } else if (d.match('(www.)?twitter\.com') && d.match('status') ) {
  3932. if (d.match("status\/")) {
  3933. media.id = d.split("status\/")[1];
  3934. } else if (d.match("statuses\/")) {
  3935. media.id = d.split("statuses\/")[1];
  3936. } else {
  3937. media.id = "";
  3938. }
  3939. media.type = "twitter";
  3940. success = true;
  3941. } else if (d.match("maps.google") && !d.match("staticmap") && !d.match('streetview')) {
  3942. media.type = "google-map";
  3943. media.id = d;
  3944. success = true;
  3945. } else if (d.match(/www.google.\w+\/maps/)) {
  3946. media.type = "google-map";
  3947. media.id = d;
  3948. success = true;
  3949. } else if (d.match("plus.google")) {
  3950. media.type = "googleplus";
  3951. media.id = d.split("/posts/")[1];
  3952. //https://plus.google.com/u/0/112374836634096795698/posts/bRJSvCb5mUU
  3953. //https://plus.google.com/107096716333816995401/posts/J5iMpEDHWNL
  3954. if (d.split("/posts/")[0].match("u/0/")) {
  3955. media.user = d.split("u/0/")[1].split("/posts")[0];
  3956. } else {
  3957. media.user = d.split("google.com/")[1].split("/posts/")[0];
  3958. }
  3959. success = true;
  3960. } else if (d.match("flickr.com/photos/")) {
  3961. media.type = "flickr";
  3962. media.id = VMM.ExternalAPI.flickr.getFlickrIdFromUrl(d)
  3963. media.link = d;
  3964. success = Boolean(media.id);
  3965. } else if (VMM.ExternalAPI.instagram.isInstagramUrl(d)) {
  3966. media.type = "instagram";
  3967. media.link = d;
  3968. media.id = VMM.ExternalAPI.instagram.getInstagramIdFromUrl(d)
  3969. success = Boolean(media.id);
  3970. } else if (d.match(/jpg|jpeg|png|gif|svg|bmp/i) ||
  3971. d.match("staticmap") ||
  3972. d.match("yfrog.com") ||
  3973. d.match("twitpic.com") ||
  3974. d.match('maps.googleapis.com/maps/api/streetview')) {
  3975. media.type = "image";
  3976. media.id = d;
  3977. success = true;
  3978. } else if (VMM.FileExtention.googleDocType(d)) {
  3979. media.type = "googledoc";
  3980. media.id = d;
  3981. success = true;
  3982. } else if (d.match('(www.)?wikipedia\.org')) {
  3983. media.type = "wikipedia";
  3984. //media.id = d.split("wiki\/")[1];
  3985. // TODO Issue #618 better splitting
  3986. var wiki_id = d.split("wiki\/")[1].split("#")[0].replace("_", " ");
  3987. media.id = wiki_id.replace(" ", "%20");
  3988. media.lang = d.split("//")[1].split(".wikipedia")[0];
  3989. success = true;
  3990. } else if (d.indexOf('http://') == 0) {
  3991. media.type = "website";
  3992. media.id = d;
  3993. success = true;
  3994. } else if (d.match('storify')) {
  3995. media.type = "storify";
  3996. media.id = d;
  3997. success = true;
  3998. } else {
  3999. trace("unknown media");
  4000. media.type = "unknown";
  4001. media.id = d;
  4002. success = true;
  4003. }
  4004. if (success) {
  4005. return media;
  4006. } else {
  4007. trace("No valid media id detected");
  4008. trace(d);
  4009. }
  4010. return false;
  4011. }
  4012. }
  4013. /* **********************************************
  4014. Begin VMM.TextElement.js
  4015. ********************************************** */
  4016. /* TextElement
  4017. ================================================== */
  4018. if(typeof VMM != 'undefined' && typeof VMM.TextElement == 'undefined') {
  4019. VMM.TextElement = ({
  4020. init: function() {
  4021. return this;
  4022. },
  4023. create: function(data) {
  4024. return data;
  4025. }
  4026. }).init();
  4027. }
  4028. /* **********************************************
  4029. Begin VMM.Media.js
  4030. ********************************************** */
  4031. /* Media
  4032. ================================================== */
  4033. /* * CodeKit Import
  4034. * http://incident57.com/codekit/
  4035. ================================================== */
  4036. // @codekit-prepend "VMM.ExternalAPI.js";
  4037. // @codekit-prepend "VMM.MediaElement.js";
  4038. // @codekit-prepend "VMM.MediaType.js";
  4039. // @codekit-prepend "VMM.TextElement.js";
  4040. /* **********************************************
  4041. Begin VMM.DragSlider.js
  4042. ********************************************** */
  4043. /* DRAG SLIDER
  4044. ================================================== */
  4045. if(typeof VMM != 'undefined' && typeof VMM.DragSlider == 'undefined') {
  4046. VMM.DragSlider = function() {
  4047. var drag = {
  4048. element: "",
  4049. element_move: "",
  4050. constraint: "",
  4051. sliding: false,
  4052. pagex: {
  4053. start: 0,
  4054. end: 0
  4055. },
  4056. pagey: {
  4057. start: 0,
  4058. end: 0
  4059. },
  4060. left: {
  4061. start: 0,
  4062. end: 0
  4063. },
  4064. time: {
  4065. start: 0,
  4066. end: 0
  4067. },
  4068. touch: false,
  4069. ease: "easeOutExpo"
  4070. },
  4071. dragevent = {
  4072. down: "mousedown",
  4073. up: "mouseup",
  4074. leave: "mouseleave",
  4075. move: "mousemove"
  4076. },
  4077. mousedrag = {
  4078. down: "mousedown",
  4079. up: "mouseup",
  4080. leave: "mouseleave",
  4081. move: "mousemove"
  4082. },
  4083. touchdrag = {
  4084. down: "touchstart",
  4085. up: "touchend",
  4086. leave: "mouseleave",
  4087. move: "touchmove"
  4088. },
  4089. dragslider = this,
  4090. is_sticky = false;
  4091. /* PUBLIC FUNCTIONS
  4092. ================================================== */
  4093. this.createPanel = function(drag_object, move_object, constraint, touch, sticky) {
  4094. drag.element = drag_object;
  4095. drag.element_move = move_object;
  4096. //dragslider = drag_object;
  4097. if ( sticky != null && sticky != "") {
  4098. is_sticky = sticky;
  4099. }
  4100. if ( constraint != null && constraint != "") {
  4101. drag.constraint = constraint;
  4102. } else {
  4103. drag.constraint = false;
  4104. }
  4105. if ( touch) {
  4106. drag.touch = touch;
  4107. } else {
  4108. drag.touch = false;
  4109. }
  4110. trace("TOUCH" + drag.touch);
  4111. if (drag.touch) {
  4112. dragevent = touchdrag;
  4113. } else {
  4114. dragevent = mousedrag;
  4115. }
  4116. makeDraggable(drag.element, drag.element_move);
  4117. }
  4118. this.updateConstraint = function(constraint) {
  4119. trace("updateConstraint");
  4120. drag.constraint = constraint;
  4121. }
  4122. this.cancelSlide = function(e) {
  4123. VMM.unbindEvent(drag.element, onDragMove, dragevent.move);
  4124. return true;
  4125. }
  4126. /* PRIVATE FUNCTIONS
  4127. ================================================== */
  4128. function makeDraggable(drag_object, move_object) {
  4129. VMM.bindEvent(drag_object, onDragStart, dragevent.down, {element: move_object, delement: drag_object});
  4130. VMM.bindEvent(drag_object, onDragEnd, dragevent.up, {element: move_object, delement: drag_object});
  4131. VMM.bindEvent(drag_object, onDragLeave, dragevent.leave, {element: move_object, delement: drag_object});
  4132. }
  4133. function onDragLeave(e) {
  4134. VMM.unbindEvent(e.data.delement, onDragMove, dragevent.move);
  4135. if (!drag.touch) {
  4136. e.preventDefault();
  4137. }
  4138. e.stopPropagation();
  4139. if (drag.sliding) {
  4140. drag.sliding = false;
  4141. dragEnd(e.data.element, e.data.delement, e);
  4142. return false;
  4143. } else {
  4144. return true;
  4145. }
  4146. }
  4147. function onDragStart(e) {
  4148. dragStart(e.data.element, e.data.delement, e);
  4149. if (!drag.touch) {
  4150. e.preventDefault();
  4151. }
  4152. //e.stopPropagation();
  4153. return true;
  4154. }
  4155. function onDragEnd(e) {
  4156. if (!drag.touch) {
  4157. e.preventDefault();
  4158. }
  4159. //e.stopPropagation();
  4160. if (drag.sliding) {
  4161. drag.sliding = false;
  4162. dragEnd(e.data.element, e.data.delement, e);
  4163. return false;
  4164. } else {
  4165. return true;
  4166. }
  4167. }
  4168. function onDragMove(e) {
  4169. dragMove(e.data.element, e);
  4170. }
  4171. function dragStart(elem, delem, e) {
  4172. if (drag.touch) {
  4173. trace("IS TOUCH")
  4174. VMM.Lib.css(elem, '-webkit-transition-duration', '0');
  4175. drag.pagex.start = e.originalEvent.touches[0].screenX;
  4176. drag.pagey.start = e.originalEvent.touches[0].screenY;
  4177. } else {
  4178. drag.pagex.start = e.pageX;
  4179. drag.pagey.start = e.pageY;
  4180. }
  4181. drag.left.start = getLeft(elem);
  4182. drag.time.start = new Date().getTime();
  4183. VMM.Lib.stop(elem);
  4184. VMM.bindEvent(delem, onDragMove, dragevent.move, {element: elem});
  4185. }
  4186. function dragEnd(elem, delem, e) {
  4187. VMM.unbindEvent(delem, onDragMove, dragevent.move);
  4188. dragMomentum(elem, e);
  4189. }
  4190. function dragMove(elem, e) {
  4191. var drag_to, drag_to_y;
  4192. drag.sliding = true;
  4193. if (drag.touch) {
  4194. drag.pagex.end = e.originalEvent.touches[0].screenX;
  4195. drag.pagey.end = e.originalEvent.touches[0].screenY;
  4196. } else {
  4197. drag.pagex.end = e.pageX;
  4198. drag.pagey.end = e.pageY;
  4199. }
  4200. drag.left.end = getLeft(elem);
  4201. drag_to = -(drag.pagex.start - drag.pagex.end - drag.left.start);
  4202. if (Math.abs(drag.pagey.start) - Math.abs(drag.pagey.end) > 10) {
  4203. trace("SCROLLING Y")
  4204. trace(Math.abs(drag.pagey.start) - Math.abs(drag.pagey.end));
  4205. }
  4206. if (Math.abs(drag_to - drag.left.start) > 10) {
  4207. VMM.Lib.css(elem, 'left', drag_to);
  4208. e.preventDefault();
  4209. e.stopPropagation();
  4210. }
  4211. }
  4212. function dragMomentum(elem, e) {
  4213. var drag_info = {
  4214. left: drag.left.end,
  4215. left_adjust: 0,
  4216. change: {
  4217. x: 0
  4218. },
  4219. time: (new Date().getTime() - drag.time.start) * 10,
  4220. time_adjust: (new Date().getTime() - drag.time.start) * 10
  4221. },
  4222. multiplier = 3000;
  4223. if (drag.touch) {
  4224. multiplier = 6000;
  4225. }
  4226. drag_info.change.x = multiplier * (Math.abs(drag.pagex.end) - Math.abs(drag.pagex.start));
  4227. drag_info.left_adjust = Math.round(drag_info.change.x / drag_info.time);
  4228. drag_info.left = Math.min(drag_info.left + drag_info.left_adjust);
  4229. if (drag.constraint) {
  4230. if (drag_info.left > drag.constraint.left) {
  4231. drag_info.left = drag.constraint.left;
  4232. if (drag_info.time > 5000) {
  4233. drag_info.time = 5000;
  4234. }
  4235. } else if (drag_info.left < drag.constraint.right) {
  4236. drag_info.left = drag.constraint.right;
  4237. if (drag_info.time > 5000) {
  4238. drag_info.time = 5000;
  4239. }
  4240. }
  4241. }
  4242. VMM.fireEvent(dragslider, "DRAGUPDATE", [drag_info]);
  4243. if (!is_sticky) {
  4244. if (drag_info.time > 0) {
  4245. if (drag.touch) {
  4246. VMM.Lib.animate(elem, drag_info.time, "easeOutCirc", {"left": drag_info.left});
  4247. } else {
  4248. VMM.Lib.animate(elem, drag_info.time, drag.ease, {"left": drag_info.left});
  4249. }
  4250. }
  4251. }
  4252. }
  4253. function getLeft(elem) {
  4254. return parseInt(VMM.Lib.css(elem, 'left').substring(0, VMM.Lib.css(elem, 'left').length - 2), 10);
  4255. }
  4256. }
  4257. }
  4258. /* **********************************************
  4259. Begin VMM.Slider.js
  4260. ********************************************** */
  4261. /* Slider
  4262. ================================================== */
  4263. /* * CodeKit Import
  4264. * http://incident57.com/codekit/
  4265. ================================================== */
  4266. // @codekit-append "VMM.Slider.Slide.js";
  4267. if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') {
  4268. VMM.Slider = function(parent, parent_config) {
  4269. var config,
  4270. timer,
  4271. $slider,
  4272. $slider_mask,
  4273. $slider_container,
  4274. $slides_items,
  4275. $dragslide,
  4276. $explainer,
  4277. events = {},
  4278. data = [],
  4279. slides = [],
  4280. slide_positions = [],
  4281. slides_content = "",
  4282. current_slide = 0,
  4283. current_width = 960,
  4284. touch = {
  4285. move: false,
  4286. x: 10,
  4287. y: 0,
  4288. off: 0,
  4289. dampen: 48
  4290. },
  4291. content = "",
  4292. _active = false,
  4293. layout = parent,
  4294. navigation = {
  4295. nextBtn: "",
  4296. prevBtn: "",
  4297. nextDate: "",
  4298. prevDate: "",
  4299. nextTitle: "",
  4300. prevTitle: ""
  4301. };
  4302. // CONFIG
  4303. if(typeof parent_config != 'undefined') {
  4304. config = parent_config;
  4305. } else {
  4306. config = {
  4307. preload: 4,
  4308. current_slide: 0,
  4309. interval: 10,
  4310. something: 0,
  4311. width: 720,
  4312. height: 400,
  4313. ease: "easeInOutExpo",
  4314. duration: 1000,
  4315. timeline: false,
  4316. spacing: 15,
  4317. slider: {
  4318. width: 720,
  4319. height: 400,
  4320. content: {
  4321. width: 720,
  4322. height: 400,
  4323. padding: 120,
  4324. padding_default: 120
  4325. },
  4326. nav: {
  4327. width: 100,
  4328. height: 200
  4329. }
  4330. }
  4331. };
  4332. }
  4333. /* PUBLIC VARS
  4334. ================================================== */
  4335. this.ver = "0.6";
  4336. config.slider.width = config.width;
  4337. config.slider.height = config.height;
  4338. /* PUBLIC FUNCTIONS
  4339. ================================================== */
  4340. this.init = function(d) {
  4341. slides = [];
  4342. slide_positions = [];
  4343. if(typeof d != 'undefined') {
  4344. this.setData(d);
  4345. } else {
  4346. trace("WAITING ON DATA");
  4347. }
  4348. };
  4349. this.width = function(w) {
  4350. if (w != null && w != "") {
  4351. config.slider.width = w;
  4352. reSize();
  4353. } else {
  4354. return config.slider.width;
  4355. }
  4356. }
  4357. this.height = function(h) {
  4358. if (h != null && h != "") {
  4359. config.slider.height = h;
  4360. reSize();
  4361. } else {
  4362. return config.slider.height;
  4363. }
  4364. }
  4365. /* GETTERS AND SETTERS
  4366. ================================================== */
  4367. this.setData = function(d) {
  4368. if(typeof d != 'undefined') {
  4369. data = d;
  4370. build();
  4371. } else{
  4372. trace("NO DATA");
  4373. }
  4374. };
  4375. this.getData = function() {
  4376. return data;
  4377. };
  4378. this.setConfig = function(d) {
  4379. if(typeof d != 'undefined') {
  4380. config = d;
  4381. } else{
  4382. trace("NO CONFIG DATA");
  4383. }
  4384. }
  4385. this.getConfig = function() {
  4386. return config;
  4387. };
  4388. this.setSize = function(w, h) {
  4389. if (w != null) {config.slider.width = w};
  4390. if (h != null) {config.slider.height = h};
  4391. if (_active) {
  4392. reSize();
  4393. }
  4394. }
  4395. this.active = function() {
  4396. return _active;
  4397. };
  4398. this.getCurrentNumber = function() {
  4399. return current_slide;
  4400. };
  4401. this.setSlide = function(n) {
  4402. goToSlide(n);
  4403. };
  4404. /* ON EVENT
  4405. ================================================== */
  4406. function onConfigSet() {
  4407. trace("onConfigSet");
  4408. };
  4409. function reSize(go_to_slide, from_start) {
  4410. var _go_to_slide = true,
  4411. _from_start = false;
  4412. if (go_to_slide != null) {_go_to_slide = go_to_slide};
  4413. if (from_start != null) {_from_start = from_start};
  4414. current_width = config.slider.width;
  4415. config.slider.nav.height = VMM.Lib.height(navigation.prevBtnContainer);
  4416. // Handle smaller sizes
  4417. if (VMM.Browser.device == "mobile" || current_width <= 640) {
  4418. config.slider.content.padding = 10;
  4419. } else {
  4420. config.slider.content.padding = config.slider.content.padding_default;
  4421. }
  4422. config.slider.content.width = current_width - (config.slider.content.padding *2);
  4423. VMM.Lib.width($slides_items, (slides.length * config.slider.content.width));
  4424. if (_from_start) {
  4425. VMM.Lib.css($slider_container, "left", slides[current_slide].leftpos());
  4426. }
  4427. // RESIZE SLIDES
  4428. sizeSlides();
  4429. // POSITION SLIDES
  4430. positionSlides();
  4431. // POSITION NAV
  4432. VMM.Lib.css(navigation.nextBtn, "left", (current_width - config.slider.nav.width));
  4433. VMM.Lib.height(navigation.prevBtn, config.slider.height);
  4434. VMM.Lib.height(navigation.nextBtn, config.slider.height);
  4435. VMM.Lib.css(navigation.nextBtnContainer, "top", ( (config.slider.height/2) - (config.slider.nav.height/2) ) + 10 );
  4436. VMM.Lib.css(navigation.prevBtnContainer, "top", ( (config.slider.height/2) - (config.slider.nav.height/2) ) + 10 );
  4437. // Animate Changes
  4438. VMM.Lib.height($slider_mask, config.slider.height);
  4439. VMM.Lib.width($slider_mask, current_width);
  4440. if (_go_to_slide) {
  4441. goToSlide(current_slide, "linear", 1);
  4442. };
  4443. if (current_slide == 0) {
  4444. VMM.Lib.visible(navigation.prevBtn, false);
  4445. }
  4446. }
  4447. function onDragFinish(e, d) {
  4448. trace("DRAG FINISH");
  4449. trace(d.left_adjust);
  4450. trace((config.slider.width / 2));
  4451. if (d.left_adjust < 0 ) {
  4452. if (Math.abs(d.left_adjust) > (config.slider.width / 2) ) {
  4453. //onNextClick(e);
  4454. if (current_slide == slides.length - 1) {
  4455. backToCurrentSlide();
  4456. } else {
  4457. goToSlide(current_slide+1, "easeOutExpo");
  4458. upDate();
  4459. }
  4460. } else {
  4461. backToCurrentSlide();
  4462. }
  4463. } else if (Math.abs(d.left_adjust) > (config.slider.width / 2) ) {
  4464. if (current_slide == 0) {
  4465. backToCurrentSlide();
  4466. } else {
  4467. goToSlide(current_slide-1, "easeOutExpo");
  4468. upDate();
  4469. }
  4470. } else {
  4471. backToCurrentSlide();
  4472. }
  4473. }
  4474. /* NAVIGATION
  4475. ================================================== */
  4476. function onNextClick(e) {
  4477. if (current_slide == slides.length - 1) {
  4478. backToCurrentSlide();
  4479. } else {
  4480. goToSlide(current_slide+1);
  4481. upDate();
  4482. }
  4483. }
  4484. function onPrevClick(e) {
  4485. if (current_slide == 0) {
  4486. backToCurrentSlide();
  4487. } else {
  4488. goToSlide(current_slide-1);
  4489. upDate();
  4490. }
  4491. }
  4492. function onKeypressNav(e) {
  4493. switch(e.keyCode) {
  4494. case 39:
  4495. // RIGHT ARROW
  4496. onNextClick(e);
  4497. break;
  4498. case 37:
  4499. // LEFT ARROW
  4500. onPrevClick(e);
  4501. break;
  4502. }
  4503. }
  4504. function onTouchUpdate(e, b) {
  4505. if (slide_positions.length == 0) {
  4506. for(var i = 0; i < slides.length; i++) {
  4507. slide_positions.push( slides[i].leftpos() );
  4508. }
  4509. }
  4510. if (typeof b.left == "number") {
  4511. var _pos = b.left;
  4512. var _slide_pos = -(slides[current_slide].leftpos());
  4513. if (_pos < _slide_pos - (config.slider_width/3)) {
  4514. onNextClick();
  4515. } else if (_pos > _slide_pos + (config.slider_width/3)) {
  4516. onPrevClick();
  4517. } else {
  4518. VMM.Lib.animate($slider_container, config.duration, config.ease, {"left": _slide_pos });
  4519. }
  4520. } else {
  4521. VMM.Lib.animate($slider_container, config.duration, config.ease, {"left": _slide_pos });
  4522. }
  4523. if (typeof b.top == "number") {
  4524. VMM.Lib.animate($slider_container, config.duration, config.ease, {"top": -b.top});
  4525. } else {
  4526. }
  4527. };
  4528. function onExplainerClick(e) {
  4529. detachMessege();
  4530. }
  4531. /* UPDATE
  4532. ================================================== */
  4533. function upDate() {
  4534. config.current_slide = current_slide;
  4535. VMM.fireEvent(layout, "UPDATE");
  4536. };
  4537. /* GET DATA
  4538. ================================================== */
  4539. function getData(d) {
  4540. data = d;
  4541. };
  4542. /* BUILD SLIDES
  4543. ================================================== */
  4544. function buildSlides(d) {
  4545. var i = 0;
  4546. VMM.attachElement($slides_items, "");
  4547. slides = [];
  4548. for(i = 0; i < d.length; i++) {
  4549. var _slide = new VMM.Slider.Slide(d[i], $slides_items);
  4550. //_slide.show();
  4551. slides.push(_slide);
  4552. }
  4553. }
  4554. function preloadSlides(skip) {
  4555. var i = 0;
  4556. if (skip) {
  4557. preloadTimeOutSlides();
  4558. } else {
  4559. for(i = 0; i < slides.length; i++) {
  4560. slides[i].clearTimers();
  4561. }
  4562. timer = setTimeout(preloadTimeOutSlides, config.duration);
  4563. }
  4564. }
  4565. function preloadTimeOutSlides() {
  4566. var i = 0;
  4567. for(i = 0; i < slides.length; i++) {
  4568. slides[i].enqueue = true;
  4569. }
  4570. for(i = 0; i < config.preload; i++) {
  4571. if ( !((current_slide + i) > slides.length - 1)) {
  4572. slides[current_slide + i].show();
  4573. slides[current_slide + i].enqueue = false;
  4574. }
  4575. if ( !( (current_slide - i) < 0 ) ) {
  4576. slides[current_slide - i].show();
  4577. slides[current_slide - i].enqueue = false;
  4578. }
  4579. }
  4580. if (slides.length > 50) {
  4581. for(i = 0; i < slides.length; i++) {
  4582. if (slides[i].enqueue) {
  4583. slides[i].hide();
  4584. }
  4585. }
  4586. }
  4587. sizeSlides();
  4588. }
  4589. function sizeSlide(slide_id) {
  4590. }
  4591. /* SIZE SLIDES
  4592. ================================================== */
  4593. function sizeSlides() {
  4594. var i = 0,
  4595. layout_text_media = ".slider-item .layout-text-media .media .media-container ",
  4596. layout_media = ".slider-item .layout-media .media .media-container ",
  4597. layout_both = ".slider-item .media .media-container",
  4598. layout_caption = ".slider-item .media .media-container .media-shadow .caption",
  4599. is_skinny = false,
  4600. mediasize = {
  4601. text_media: {
  4602. width: (config.slider.content.width/100) * 60,
  4603. height: config.slider.height - 60,
  4604. video: {
  4605. width: 0,
  4606. height: 0
  4607. },
  4608. text: {
  4609. width: ((config.slider.content.width/100) * 40) - 30,
  4610. height: config.slider.height
  4611. }
  4612. },
  4613. media: {
  4614. width: config.slider.content.width,
  4615. height: config.slider.height - 110,
  4616. video: {
  4617. width: 0,
  4618. height: 0
  4619. }
  4620. }
  4621. };
  4622. // Handle smaller sizes
  4623. if (VMM.Browser.device == "mobile" || current_width < 641) {
  4624. is_skinny = true;
  4625. }
  4626. VMM.master_config.sizes.api.width = mediasize.media.width;
  4627. VMM.master_config.sizes.api.height = mediasize.media.height;
  4628. mediasize.text_media.video = VMM.Util.ratio.fit(mediasize.text_media.width, mediasize.text_media.height, 16, 9);
  4629. mediasize.media.video = VMM.Util.ratio.fit(mediasize.media.width, mediasize.media.height, 16, 9);
  4630. VMM.Lib.css(".slider-item", "width", config.slider.content.width );
  4631. VMM.Lib.height(".slider-item", config.slider.height);
  4632. if (is_skinny) {
  4633. mediasize.text_media.width = config.slider.content.width - (config.slider.content.padding*2);
  4634. mediasize.media.width = config.slider.content.width - (config.slider.content.padding*2);
  4635. mediasize.text_media.height = ((config.slider.height/100) * 50 ) - 50;
  4636. mediasize.media.height = ((config.slider.height/100) * 70 ) - 40;
  4637. mediasize.text_media.video = VMM.Util.ratio.fit(mediasize.text_media.width, mediasize.text_media.height, 16, 9);
  4638. mediasize.media.video = VMM.Util.ratio.fit(mediasize.media.width, mediasize.media.height, 16, 9);
  4639. VMM.Lib.css(".slider-item .layout-text-media .text", "width", "100%" );
  4640. VMM.Lib.css(".slider-item .layout-text-media .text", "display", "block" );
  4641. VMM.Lib.css(".slider-item .layout-text-media .text .container", "display", "block" );
  4642. VMM.Lib.css(".slider-item .layout-text-media .text .container", "width", mediasize.media.width );
  4643. VMM.Lib.css(".slider-item .layout-text-media .text .container .start", "width", "auto" );
  4644. VMM.Lib.css(".slider-item .layout-text-media .media", "float", "none" );
  4645. VMM.Lib.addClass(".slider-item .content-container", "pad-top");
  4646. VMM.Lib.css(".slider-item .media blockquote p", "line-height", "18px" );
  4647. VMM.Lib.css(".slider-item .media blockquote p", "font-size", "16px" );
  4648. VMM.Lib.css(".slider-item", "overflow-y", "auto" );
  4649. } else {
  4650. VMM.Lib.css(".slider-item .layout-text-media .text", "width", "40%" );
  4651. VMM.Lib.css(".slider-item .layout-text-media .text", "display", "table-cell" );
  4652. VMM.Lib.css(".slider-item .layout-text-media .text .container", "display", "table-cell" );
  4653. VMM.Lib.css(".slider-item .layout-text-media .text .container", "width", "auto" );
  4654. VMM.Lib.css(".slider-item .layout-text-media .text .container .start", "width", mediasize.text_media.text.width );
  4655. //VMM.Lib.addClass(".slider-item .content-container", "pad-left");
  4656. VMM.Lib.removeClass(".slider-item .content-container", "pad-top");
  4657. VMM.Lib.css(".slider-item .layout-text-media .media", "float", "left" );
  4658. VMM.Lib.css(".slider-item .layout-text-media", "display", "table" );
  4659. VMM.Lib.css(".slider-item .media blockquote p", "line-height", "36px" );
  4660. VMM.Lib.css(".slider-item .media blockquote p", "font-size", "28px" );
  4661. VMM.Lib.css(".slider-item", "display", "table" );
  4662. VMM.Lib.css(".slider-item", "overflow-y", "auto" );
  4663. }
  4664. // MEDIA FRAME
  4665. VMM.Lib.css( layout_text_media + ".media-frame", "max-width", mediasize.text_media.width);
  4666. VMM.Lib.height( layout_text_media + ".media-frame", mediasize.text_media.height);
  4667. VMM.Lib.width( layout_text_media + ".media-frame", mediasize.text_media.width);
  4668. // WEBSITES
  4669. //VMM.Lib.css( layout_both + ".website", "max-width", 300 );
  4670. // IMAGES
  4671. VMM.Lib.css( layout_text_media + "img", "max-height", mediasize.text_media.height );
  4672. VMM.Lib.css( layout_media + "img", "max-height", mediasize.media.height );
  4673. // FIX FOR NON-WEBKIT BROWSERS
  4674. VMM.Lib.css( layout_text_media + "img", "max-width", mediasize.text_media.width );
  4675. VMM.Lib.css( layout_text_media + ".avatar img", "max-width", 32 );
  4676. VMM.Lib.css( layout_text_media + ".avatar img", "max-height", 32 );
  4677. VMM.Lib.css( layout_media + ".avatar img", "max-width", 32 );
  4678. VMM.Lib.css( layout_media + ".avatar img", "max-height", 32 );
  4679. VMM.Lib.css( layout_text_media + ".article-thumb", "max-width", "50%" );
  4680. //VMM.Lib.css( layout_text_media + ".article-thumb", "max-height", 100 );
  4681. VMM.Lib.css( layout_media + ".article-thumb", "max-width", 200 );
  4682. //VMM.Lib.css( layout_media + ".article-thumb", "max-height", 100 );
  4683. // IFRAME FULL SIZE VIDEO
  4684. VMM.Lib.width( layout_text_media + ".media-frame", mediasize.text_media.video.width);
  4685. VMM.Lib.height( layout_text_media + ".media-frame", mediasize.text_media.video.height);
  4686. VMM.Lib.width( layout_media + ".media-frame", mediasize.media.video.width);
  4687. VMM.Lib.height( layout_media + ".media-frame", mediasize.media.video.height);
  4688. VMM.Lib.css( layout_media + ".media-frame", "max-height", mediasize.media.video.height);
  4689. VMM.Lib.css( layout_media + ".media-frame", "max-width", mediasize.media.video.width);
  4690. // SOUNDCLOUD
  4691. VMM.Lib.height( layout_media + ".soundcloud", 168);
  4692. VMM.Lib.height( layout_text_media + ".soundcloud", 168);
  4693. VMM.Lib.width( layout_media + ".soundcloud", mediasize.media.width);
  4694. VMM.Lib.width( layout_text_media + ".soundcloud", mediasize.text_media.width);
  4695. VMM.Lib.css( layout_both + ".soundcloud", "max-height", 168 );
  4696. // MAPS
  4697. VMM.Lib.height( layout_text_media + ".map", mediasize.text_media.height);
  4698. VMM.Lib.width( layout_text_media + ".map", mediasize.text_media.width);
  4699. VMM.Lib.css( layout_media + ".map", "max-height", mediasize.media.height);
  4700. VMM.Lib.width( layout_media + ".map", mediasize.media.width);
  4701. // DOCS
  4702. VMM.Lib.height( layout_text_media + ".doc", mediasize.text_media.height);
  4703. VMM.Lib.width( layout_text_media + ".doc", mediasize.text_media.width);
  4704. VMM.Lib.height( layout_media + ".doc", mediasize.media.height);
  4705. VMM.Lib.width( layout_media + ".doc", mediasize.media.width);
  4706. // IE8 NEEDS THIS
  4707. VMM.Lib.width( layout_media + ".wikipedia", mediasize.media.width);
  4708. VMM.Lib.width( layout_media + ".twitter", mediasize.media.width);
  4709. VMM.Lib.width( layout_media + ".plain-text-quote", mediasize.media.width);
  4710. VMM.Lib.width( layout_media + ".plain-text", mediasize.media.width);
  4711. VMM.Lib.css( layout_both, "max-width", mediasize.media.width);
  4712. // CAPTION WIDTH
  4713. VMM.Lib.css( layout_text_media + ".caption", "max-width", mediasize.text_media.video.width);
  4714. VMM.Lib.css( layout_media + ".caption", "max-width", mediasize.media.video.width);
  4715. //VMM.Lib.css( layout_text_media + ".caption", "max-width", mediasize.text_media.width);
  4716. //VMM.Lib.css( layout_media + ".caption", "max-width", mediasize.media.width);
  4717. // MAINTAINS VERTICAL CENTER IF IT CAN
  4718. for(i = 0; i < slides.length; i++) {
  4719. slides[i].layout(is_skinny);
  4720. if (slides[i].content_height() > config.slider.height + 20) {
  4721. slides[i].css("display", "block");
  4722. } else {
  4723. slides[i].css("display", "table");
  4724. }
  4725. }
  4726. }
  4727. /* POSITION SLIDES
  4728. ================================================== */
  4729. function positionSlides() {
  4730. var pos = 0,
  4731. i = 0;
  4732. for(i = 0; i < slides.length; i++) {
  4733. pos = i * (config.slider.width+config.spacing);
  4734. slides[i].leftpos(pos);
  4735. }
  4736. }
  4737. /* OPACITY SLIDES
  4738. ================================================== */
  4739. function opacitySlides(n) {
  4740. var _ease = "linear",
  4741. i = 0;
  4742. for(i = 0; i < slides.length; i++) {
  4743. if (i == current_slide) {
  4744. slides[i].animate(config.duration, _ease, {"opacity": 1});
  4745. } else if (i == current_slide - 1 || i == current_slide + 1) {
  4746. slides[i].animate(config.duration, _ease, {"opacity": 0.1});
  4747. } else {
  4748. slides[i].opacity(n);
  4749. }
  4750. }
  4751. }
  4752. /* GO TO SLIDE
  4753. goToSlide(n, ease, duration);
  4754. ================================================== */
  4755. function goToSlide(n, ease, duration, fast, firstrun) {
  4756. var _ease = config.ease,
  4757. _duration = config.duration,
  4758. is_last = false,
  4759. is_first = false,
  4760. _title = "",
  4761. _pos;
  4762. /* STOP ANY VIDEO PLAYERS ACTIVE
  4763. ================================================== */
  4764. VMM.ExternalAPI.youtube.stopPlayers();
  4765. // Set current slide
  4766. current_slide = n;
  4767. _pos = slides[current_slide].leftpos();
  4768. if (current_slide == 0) {is_first = true};
  4769. if (current_slide +1 >= slides.length) {is_last = true};
  4770. if (ease != null && ease != "") {_ease = ease};
  4771. if (duration != null && duration != "") {_duration = duration};
  4772. /* NAVIGATION
  4773. set proper nav titles and dates etc.
  4774. ================================================== */
  4775. // Handle smaller sizes
  4776. if (VMM.Browser.device == "mobile") {
  4777. //if (VMM.Browser.device == "mobile" || current_width <= 640) {
  4778. VMM.Lib.visible(navigation.prevBtn, false);
  4779. VMM.Lib.visible(navigation.nextBtn, false);
  4780. } else {
  4781. if (is_first) {
  4782. VMM.Lib.visible(navigation.prevBtn, false);
  4783. } else {
  4784. VMM.Lib.visible(navigation.prevBtn, true);
  4785. _title = VMM.Util.unlinkify(data[current_slide - 1].title)
  4786. if (config.type == "timeline") {
  4787. if(typeof data[current_slide - 1].date === "undefined") {
  4788. VMM.attachElement(navigation.prevDate, _title);
  4789. VMM.attachElement(navigation.prevTitle, "");
  4790. } else {
  4791. VMM.attachElement(navigation.prevDate, VMM.Date.prettyDate(data[current_slide - 1].startdate, false, data[current_slide - 1].precisiondate));
  4792. VMM.attachElement(navigation.prevTitle, _title);
  4793. }
  4794. } else {
  4795. VMM.attachElement(navigation.prevTitle, _title);
  4796. }
  4797. }
  4798. if (is_last) {
  4799. VMM.Lib.visible(navigation.nextBtn, false);
  4800. } else {
  4801. VMM.Lib.visible(navigation.nextBtn, true);
  4802. _title = VMM.Util.unlinkify(data[current_slide + 1].title);
  4803. if (config.type == "timeline") {
  4804. if(typeof data[current_slide + 1].date === "undefined") {
  4805. VMM.attachElement(navigation.nextDate, _title);
  4806. VMM.attachElement(navigation.nextTitle, "");
  4807. } else {
  4808. VMM.attachElement(navigation.nextDate, VMM.Date.prettyDate(data[current_slide + 1].startdate, false, data[current_slide + 1].precisiondate) );
  4809. VMM.attachElement(navigation.nextTitle, _title);
  4810. }
  4811. } else {
  4812. VMM.attachElement(navigation.nextTitle, _title);
  4813. }
  4814. }
  4815. }
  4816. /* ANIMATE SLIDE
  4817. ================================================== */
  4818. if (fast) {
  4819. VMM.Lib.css($slider_container, "left", -(_pos - config.slider.content.padding));
  4820. } else{
  4821. VMM.Lib.stop($slider_container);
  4822. VMM.Lib.animate($slider_container, _duration, _ease, {"left": -(_pos - config.slider.content.padding)});
  4823. }
  4824. if (firstrun) {
  4825. VMM.fireEvent(layout, "LOADED");
  4826. }
  4827. /* SET Vertical Scoll
  4828. ================================================== */
  4829. if (slides[current_slide].height() > config.slider_height) {
  4830. VMM.Lib.css(".slider", "overflow-y", "scroll" );
  4831. } else {
  4832. VMM.Lib.css(layout, "overflow-y", "hidden" );
  4833. var scroll_height = 0;
  4834. try {
  4835. scroll_height = VMM.Lib.prop(layout, "scrollHeight");
  4836. VMM.Lib.animate(layout, _duration, _ease, {scrollTop: scroll_height - VMM.Lib.height(layout) });
  4837. }
  4838. catch(err) {
  4839. scroll_height = VMM.Lib.height(layout);
  4840. }
  4841. }
  4842. preloadSlides();
  4843. VMM.fireEvent($slider, "MESSAGE", "TEST");
  4844. }
  4845. function backToCurrentSlide() {
  4846. VMM.Lib.stop($slider_container);
  4847. VMM.Lib.animate($slider_container, config.duration, "easeOutExpo", {"left": -(slides[current_slide].leftpos()) + config.slider.content.padding} );
  4848. }
  4849. /* MESSEGES
  4850. ================================================== */
  4851. function showMessege(e, msg, other) {
  4852. trace("showMessege " + msg);
  4853. //VMM.attachElement($timeline, $feedback);
  4854. VMM.attachElement($explainer, "<div class='vco-explainer'><div class='vco-explainer-container'><div class='vco-bezel'><div class='vco-gesture-icon'></div>" + "<div class='vco-message'><p>" + msg + "</p></div></div></div></div>");
  4855. };
  4856. function hideMessege() {
  4857. VMM.Lib.animate($explainer, config.duration, config.ease, {"opacity": 0}, detachMessege);
  4858. };
  4859. function detachMessege() {
  4860. VMM.Lib.detach($explainer);
  4861. }
  4862. /* BUILD NAVIGATION
  4863. ================================================== */
  4864. function buildNavigation() {
  4865. var temp_icon = "<div class='icon'>&nbsp;</div>";
  4866. navigation.nextBtn = VMM.appendAndGetElement($slider, "<div>", "nav-next");
  4867. navigation.prevBtn = VMM.appendAndGetElement($slider, "<div>", "nav-previous");
  4868. navigation.nextBtnContainer = VMM.appendAndGetElement(navigation.nextBtn, "<div>", "nav-container", temp_icon);
  4869. navigation.prevBtnContainer = VMM.appendAndGetElement(navigation.prevBtn, "<div>", "nav-container", temp_icon);
  4870. if (config.type == "timeline") {
  4871. navigation.nextDate = VMM.appendAndGetElement(navigation.nextBtnContainer, "<div>", "date", "");
  4872. navigation.prevDate = VMM.appendAndGetElement(navigation.prevBtnContainer, "<div>", "date", "");
  4873. }
  4874. navigation.nextTitle = VMM.appendAndGetElement(navigation.nextBtnContainer, "<div>", "title", "");
  4875. navigation.prevTitle = VMM.appendAndGetElement(navigation.prevBtnContainer, "<div>", "title", "");
  4876. VMM.bindEvent(".nav-next", onNextClick);
  4877. VMM.bindEvent(".nav-previous", onPrevClick);
  4878. VMM.bindEvent(window, onKeypressNav, 'keydown');
  4879. }
  4880. /* BUILD
  4881. ================================================== */
  4882. function build() {
  4883. var __duration = 3000;
  4884. // Clear out existing content
  4885. VMM.attachElement(layout, "");
  4886. // Get DOM Objects to local objects
  4887. $slider = VMM.getElement(layout);
  4888. $slider_mask = VMM.appendAndGetElement($slider, "<div>", "slider-container-mask");
  4889. $slider_container = VMM.appendAndGetElement($slider_mask, "<div>", "slider-container");
  4890. $slides_items = VMM.appendAndGetElement($slider_container, "<div>", "slider-item-container");
  4891. // BUILD NAVIGATION
  4892. buildNavigation();
  4893. // ATTACH SLIDES
  4894. buildSlides(data);
  4895. /* MAKE SLIDER DRAGGABLE/TOUCHABLE
  4896. ================================================== */
  4897. if (VMM.Browser.device == "tablet" || VMM.Browser.device == "mobile") {
  4898. // Different Animation duration for touch
  4899. config.duration = 500;
  4900. __duration = 1000;
  4901. // Make touchable
  4902. $dragslide = new VMM.DragSlider();
  4903. $dragslide.createPanel($slider, $slider_container, "", config.touch, true);
  4904. VMM.bindEvent($dragslide, onDragFinish, 'DRAGUPDATE');
  4905. // EXPLAINER
  4906. $explainer = VMM.appendAndGetElement($slider_mask, "<div>", "vco-feedback", "");
  4907. showMessege(null, "Swipe to Navigate");
  4908. VMM.Lib.height($explainer, config.slider.height);
  4909. VMM.bindEvent($explainer, onExplainerClick);
  4910. VMM.bindEvent($explainer, onExplainerClick, 'touchend');
  4911. }
  4912. reSize(false, true);
  4913. VMM.Lib.visible(navigation.prevBtn, false);
  4914. goToSlide(config.current_slide, "easeOutExpo", __duration, true, true);
  4915. _active = true;
  4916. };
  4917. };
  4918. }
  4919. /* **********************************************
  4920. Begin VMM.Slider.Slide.js
  4921. ********************************************** */
  4922. /* Slider Slide
  4923. ================================================== */
  4924. if (typeof VMM.Slider != 'undefined') {
  4925. VMM.Slider.Slide = function(d, _parent) {
  4926. var $media, $text, $slide, $wrap, element, c,
  4927. data = d,
  4928. slide = {},
  4929. element = "",
  4930. media = "",
  4931. loaded = false,
  4932. preloaded = false,
  4933. is_skinny = false,
  4934. _enqueue = true,
  4935. _removeque = false,
  4936. _id = "slide_",
  4937. _class = 0,
  4938. timer = {pushque:"", render:"", relayout:"", remove:"", skinny:false},
  4939. times = {pushque:500, render:100, relayout:100, remove:30000};
  4940. _id = _id + data.uniqueid;
  4941. this.enqueue = _enqueue;
  4942. this.id = _id;
  4943. element = VMM.appendAndGetElement(_parent, "<div>", "slider-item");
  4944. if (typeof data.classname != 'undefined') {
  4945. trace("HAS CLASSNAME");
  4946. VMM.Lib.addClass(element, data.classname);
  4947. } else {
  4948. trace("NO CLASSNAME");
  4949. trace(data);
  4950. }
  4951. c = {slide:"", text: "", media: "", media_element: "", layout: "content-container layout", has: { headline: false, text: false, media: false }};
  4952. /* PUBLIC
  4953. ================================================== */
  4954. this.show = function(skinny) {
  4955. _enqueue = false;
  4956. timer.skinny = skinny;
  4957. _removeque = false;
  4958. clearTimeout(timer.remove);
  4959. if (!loaded) {
  4960. if (preloaded) {
  4961. clearTimeout(timer.relayout);
  4962. timer.relayout = setTimeout(reloadLayout, times.relayout);
  4963. } else {
  4964. render(skinny);
  4965. }
  4966. }
  4967. };
  4968. this.hide = function() {
  4969. if (loaded && !_removeque) {
  4970. _removeque = true;
  4971. clearTimeout(timer.remove);
  4972. timer.remove = setTimeout(removeSlide, times.remove);
  4973. }
  4974. };
  4975. this.clearTimers = function() {
  4976. //clearTimeout(timer.remove);
  4977. clearTimeout(timer.relayout);
  4978. clearTimeout(timer.pushque);
  4979. clearTimeout(timer.render);
  4980. };
  4981. this.layout = function(skinny) {
  4982. if (loaded && preloaded) {
  4983. reLayout(skinny);
  4984. }
  4985. };
  4986. this.elem = function() {
  4987. return element;
  4988. };
  4989. this.position = function() {
  4990. return VMM.Lib.position(element);
  4991. };
  4992. this.leftpos = function(p) {
  4993. if(typeof p != 'undefined') {
  4994. VMM.Lib.css(element, "left", p);
  4995. } else {
  4996. return VMM.Lib.position(element).left
  4997. }
  4998. };
  4999. this.animate = function(d, e, p) {
  5000. VMM.Lib.animate(element, d, e, p);
  5001. };
  5002. this.css = function(p, v) {
  5003. VMM.Lib.css(element, p, v );
  5004. }
  5005. this.opacity = function(p) {
  5006. VMM.Lib.css(element, "opacity", p);
  5007. }
  5008. this.width = function() {
  5009. return VMM.Lib.width(element);
  5010. };
  5011. this.height = function() {
  5012. return VMM.Lib.height(element);
  5013. };
  5014. this.content_height = function () {
  5015. var ch = VMM.Lib.find( element, ".content")[0];
  5016. if (ch != 'undefined' && ch != null) {
  5017. return VMM.Lib.height(ch);
  5018. } else {
  5019. return 0;
  5020. }
  5021. }
  5022. /* PRIVATE
  5023. ================================================== */
  5024. var render = function(skinny) {
  5025. trace("RENDER " + _id);
  5026. loaded = true;
  5027. preloaded = true;
  5028. timer.skinny = skinny;
  5029. buildSlide();
  5030. clearTimeout(timer.pushque);
  5031. clearTimeout(timer.render);
  5032. timer.pushque = setTimeout(VMM.ExternalAPI.pushQues, times.pushque);
  5033. };
  5034. var removeSlide = function() {
  5035. //VMM.attachElement(element, "");
  5036. trace("REMOVE SLIDE TIMER FINISHED");
  5037. loaded = false;
  5038. VMM.Lib.detach($text);
  5039. VMM.Lib.detach($media);
  5040. };
  5041. var reloadLayout = function() {
  5042. loaded = true;
  5043. reLayout(timer.skinny, true);
  5044. };
  5045. var reLayout = function(skinny, reload) {
  5046. if (c.has.text) {
  5047. if (skinny) {
  5048. if (!is_skinny || reload) {
  5049. VMM.Lib.removeClass($slide, "pad-left");
  5050. VMM.Lib.detach($text);
  5051. VMM.Lib.detach($media);
  5052. VMM.Lib.append($slide, $text);
  5053. VMM.Lib.append($slide, $media);
  5054. is_skinny = true;
  5055. }
  5056. } else {
  5057. if (is_skinny || reload) {
  5058. VMM.Lib.addClass($slide, "pad-left");
  5059. VMM.Lib.detach($text);
  5060. VMM.Lib.detach($media);
  5061. VMM.Lib.append($slide, $media);
  5062. VMM.Lib.append($slide, $text);
  5063. is_skinny = false;
  5064. }
  5065. }
  5066. } else if (reload) {
  5067. if (c.has.headline) {
  5068. VMM.Lib.detach($text);
  5069. VMM.Lib.append($slide, $text);
  5070. }
  5071. VMM.Lib.detach($media);
  5072. VMM.Lib.append($slide, $media);
  5073. }
  5074. }
  5075. var buildSlide = function() {
  5076. trace("BUILDSLIDE");
  5077. $wrap = VMM.appendAndGetElement(element, "<div>", "content");
  5078. $slide = VMM.appendAndGetElement($wrap, "<div>");
  5079. /* DATE
  5080. ================================================== */
  5081. if (data.startdate != null && data.startdate != "") {
  5082. if (type.of(data.startdate) == "date") {
  5083. if (data.type != "start") {
  5084. var st = VMM.Date.prettyDate(data.startdate, false, data.precisiondate);
  5085. var en = VMM.Date.prettyDate(data.enddate, false, data.precisiondate);
  5086. var tag = "";
  5087. /* TAG / CATEGORY
  5088. ================================================== */
  5089. if (data.tag != null && data.tag != "") {
  5090. tag = VMM.createElement("span", data.tag, "slide-tag");
  5091. }
  5092. if (st != en) {
  5093. c.text += VMM.createElement("h2", st + " &mdash; " + en + tag, "date");
  5094. } else {
  5095. c.text += VMM.createElement("h2", st + tag, "date");
  5096. }
  5097. }
  5098. }
  5099. }
  5100. /* HEADLINE
  5101. ================================================== */
  5102. if (data.headline != null && data.headline != "") {
  5103. c.has.headline = true;
  5104. if (data.type == "start") {
  5105. c.text += VMM.createElement("h2", VMM.Util.linkify_with_twitter(data.headline, "_blank"), "start");
  5106. } else {
  5107. c.text += VMM.createElement("h3", VMM.Util.linkify_with_twitter(data.headline, "_blank"));
  5108. }
  5109. }
  5110. /* TEXT
  5111. ================================================== */
  5112. if (data.text != null && data.text != "") {
  5113. c.has.text = true;
  5114. c.text += VMM.createElement("p", VMM.Util.linkify_with_twitter(data.text, "_blank"));
  5115. }
  5116. if (c.has.text || c.has.headline) {
  5117. c.text = VMM.createElement("div", c.text, "container");
  5118. //$text = VMM.appendAndGetElement($slide, "<div>", "text", c.text);
  5119. $text = VMM.appendAndGetElement($slide, "<div>", "text", VMM.TextElement.create(c.text));
  5120. }
  5121. /* SLUG
  5122. ================================================== */
  5123. if (data.needs_slug) {
  5124. }
  5125. /* MEDIA
  5126. ================================================== */
  5127. if (data.asset != null && data.asset != "") {
  5128. if (data.asset.media != null && data.asset.media != "") {
  5129. c.has.media = true;
  5130. $media = VMM.appendAndGetElement($slide, "<div>", "media", VMM.MediaElement.create(data.asset, data.uniqueid));
  5131. }
  5132. }
  5133. /* COMBINE
  5134. ================================================== */
  5135. if (c.has.text) { c.layout += "-text" };
  5136. if (c.has.media){ c.layout += "-media" };
  5137. if (c.has.text) {
  5138. if (timer.skinny) {
  5139. VMM.Lib.addClass($slide, c.layout);
  5140. is_skinny = true;
  5141. } else {
  5142. VMM.Lib.addClass($slide, c.layout);
  5143. VMM.Lib.addClass($slide, "pad-left");
  5144. VMM.Lib.detach($text);
  5145. VMM.Lib.append($slide, $text);
  5146. }
  5147. } else {
  5148. VMM.Lib.addClass($slide, c.layout);
  5149. }
  5150. };
  5151. }
  5152. };
  5153. /* **********************************************
  5154. Begin AES.js
  5155. ********************************************** */
  5156. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  5157. /* AES implementation in JavaScript (c) Chris Veness 2005-2011 */
  5158. /* - see http://csrc.nist.gov/publications/PubsFIPS.html#197 */
  5159. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  5160. var Aes = {}; // Aes namespace
  5161. /**
  5162. * AES Cipher function: encrypt 'input' state with Rijndael algorithm
  5163. * applies Nr rounds (10/12/14) using key schedule w for 'add round key' stage
  5164. *
  5165. * @param {Number[]} input 16-byte (128-bit) input state array
  5166. * @param {Number[][]} w Key schedule as 2D byte-array (Nr+1 x Nb bytes)
  5167. * @returns {Number[]} Encrypted output state array
  5168. */
  5169. Aes.cipher = function(input, w) { // main Cipher function [§5.1]
  5170. var Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)
  5171. var Nr = w.length/Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys
  5172. var state = [[],[],[],[]]; // initialise 4xNb byte-array 'state' with input [§3.4]
  5173. for (var i=0; i<4*Nb; i++) state[i%4][Math.floor(i/4)] = input[i];
  5174. state = Aes.addRoundKey(state, w, 0, Nb);
  5175. for (var round=1; round<Nr; round++) {
  5176. state = Aes.subBytes(state, Nb);
  5177. state = Aes.shiftRows(state, Nb);
  5178. state = Aes.mixColumns(state, Nb);
  5179. state = Aes.addRoundKey(state, w, round, Nb);
  5180. }
  5181. state = Aes.subBytes(state, Nb);
  5182. state = Aes.shiftRows(state, Nb);
  5183. state = Aes.addRoundKey(state, w, Nr, Nb);
  5184. var output = new Array(4*Nb); // convert state to 1-d array before returning [§3.4]
  5185. for (var i=0; i<4*Nb; i++) output[i] = state[i%4][Math.floor(i/4)];
  5186. return output;
  5187. }
  5188. /**
  5189. * Perform Key Expansion to generate a Key Schedule
  5190. *
  5191. * @param {Number[]} key Key as 16/24/32-byte array
  5192. * @returns {Number[][]} Expanded key schedule as 2D byte-array (Nr+1 x Nb bytes)
  5193. */
  5194. Aes.keyExpansion = function(key) { // generate Key Schedule (byte-array Nr+1 x Nb) from Key [§5.2]
  5195. var Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)
  5196. var Nk = key.length/4 // key length (in words): 4/6/8 for 128/192/256-bit keys
  5197. var Nr = Nk + 6; // no of rounds: 10/12/14 for 128/192/256-bit keys
  5198. var w = new Array(Nb*(Nr+1));
  5199. var temp = new Array(4);
  5200. for (var i=0; i<Nk; i++) {
  5201. var r = [key[4*i], key[4*i+1], key[4*i+2], key[4*i+3]];
  5202. w[i] = r;
  5203. }
  5204. for (var i=Nk; i<(Nb*(Nr+1)); i++) {
  5205. w[i] = new Array(4);
  5206. for (var t=0; t<4; t++) temp[t] = w[i-1][t];
  5207. if (i % Nk == 0) {
  5208. temp = Aes.subWord(Aes.rotWord(temp));
  5209. for (var t=0; t<4; t++) temp[t] ^= Aes.rCon[i/Nk][t];
  5210. } else if (Nk > 6 && i%Nk == 4) {
  5211. temp = Aes.subWord(temp);
  5212. }
  5213. for (var t=0; t<4; t++) w[i][t] = w[i-Nk][t] ^ temp[t];
  5214. }
  5215. return w;
  5216. }
  5217. /*
  5218. * ---- remaining routines are private, not called externally ----
  5219. */
  5220. Aes.subBytes = function(s, Nb) { // apply SBox to state S [§5.1.1]
  5221. for (var r=0; r<4; r++) {
  5222. for (var c=0; c<Nb; c++) s[r][c] = Aes.sBox[s[r][c]];
  5223. }
  5224. return s;
  5225. }
  5226. Aes.shiftRows = function(s, Nb) { // shift row r of state S left by r bytes [§5.1.2]
  5227. var t = new Array(4);
  5228. for (var r=1; r<4; r++) {
  5229. for (var c=0; c<4; c++) t[c] = s[r][(c+r)%Nb]; // shift into temp copy
  5230. for (var c=0; c<4; c++) s[r][c] = t[c]; // and copy back
  5231. } // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES):
  5232. return s; // see asmaes.sourceforge.net/rijndael/rijndaelImplementation.pdf
  5233. }
  5234. Aes.mixColumns = function(s, Nb) { // combine bytes of each col of state S [§5.1.3]
  5235. for (var c=0; c<4; c++) {
  5236. var a = new Array(4); // 'a' is a copy of the current column from 's'
  5237. var b = new Array(4); // 'b' is a•{02} in GF(2^8)
  5238. for (var i=0; i<4; i++) {
  5239. a[i] = s[i][c];
  5240. b[i] = s[i][c]&0x80 ? s[i][c]<<1 ^ 0x011b : s[i][c]<<1;
  5241. }
  5242. // a[n] ^ b[n] is a•{03} in GF(2^8)
  5243. s[0][c] = b[0] ^ a[1] ^ b[1] ^ a[2] ^ a[3]; // 2*a0 + 3*a1 + a2 + a3
  5244. s[1][c] = a[0] ^ b[1] ^ a[2] ^ b[2] ^ a[3]; // a0 * 2*a1 + 3*a2 + a3
  5245. s[2][c] = a[0] ^ a[1] ^ b[2] ^ a[3] ^ b[3]; // a0 + a1 + 2*a2 + 3*a3
  5246. s[3][c] = a[0] ^ b[0] ^ a[1] ^ a[2] ^ b[3]; // 3*a0 + a1 + a2 + 2*a3
  5247. }
  5248. return s;
  5249. }
  5250. Aes.addRoundKey = function(state, w, rnd, Nb) { // xor Round Key into state S [§5.1.4]
  5251. for (var r=0; r<4; r++) {
  5252. for (var c=0; c<Nb; c++) state[r][c] ^= w[rnd*4+c][r];
  5253. }
  5254. return state;
  5255. }
  5256. Aes.subWord = function(w) { // apply SBox to 4-byte word w
  5257. for (var i=0; i<4; i++) w[i] = Aes.sBox[w[i]];
  5258. return w;
  5259. }
  5260. Aes.rotWord = function(w) { // rotate 4-byte word w left by one byte
  5261. var tmp = w[0];
  5262. for (var i=0; i<3; i++) w[i] = w[i+1];
  5263. w[3] = tmp;
  5264. return w;
  5265. }
  5266. // sBox is pre-computed multiplicative inverse in GF(2^8) used in subBytes and keyExpansion [§5.1.1]
  5267. Aes.sBox = [0x63,0x7c,0x77,0x7b,0xf2,0x6b,0x6f,0xc5,0x30,0x01,0x67,0x2b,0xfe,0xd7,0xab,0x76,
  5268. 0xca,0x82,0xc9,0x7d,0xfa,0x59,0x47,0xf0,0xad,0xd4,0xa2,0xaf,0x9c,0xa4,0x72,0xc0,
  5269. 0xb7,0xfd,0x93,0x26,0x36,0x3f,0xf7,0xcc,0x34,0xa5,0xe5,0xf1,0x71,0xd8,0x31,0x15,
  5270. 0x04,0xc7,0x23,0xc3,0x18,0x96,0x05,0x9a,0x07,0x12,0x80,0xe2,0xeb,0x27,0xb2,0x75,
  5271. 0x09,0x83,0x2c,0x1a,0x1b,0x6e,0x5a,0xa0,0x52,0x3b,0xd6,0xb3,0x29,0xe3,0x2f,0x84,
  5272. 0x53,0xd1,0x00,0xed,0x20,0xfc,0xb1,0x5b,0x6a,0xcb,0xbe,0x39,0x4a,0x4c,0x58,0xcf,
  5273. 0xd0,0xef,0xaa,0xfb,0x43,0x4d,0x33,0x85,0x45,0xf9,0x02,0x7f,0x50,0x3c,0x9f,0xa8,
  5274. 0x51,0xa3,0x40,0x8f,0x92,0x9d,0x38,0xf5,0xbc,0xb6,0xda,0x21,0x10,0xff,0xf3,0xd2,
  5275. 0xcd,0x0c,0x13,0xec,0x5f,0x97,0x44,0x17,0xc4,0xa7,0x7e,0x3d,0x64,0x5d,0x19,0x73,
  5276. 0x60,0x81,0x4f,0xdc,0x22,0x2a,0x90,0x88,0x46,0xee,0xb8,0x14,0xde,0x5e,0x0b,0xdb,
  5277. 0xe0,0x32,0x3a,0x0a,0x49,0x06,0x24,0x5c,0xc2,0xd3,0xac,0x62,0x91,0x95,0xe4,0x79,
  5278. 0xe7,0xc8,0x37,0x6d,0x8d,0xd5,0x4e,0xa9,0x6c,0x56,0xf4,0xea,0x65,0x7a,0xae,0x08,
  5279. 0xba,0x78,0x25,0x2e,0x1c,0xa6,0xb4,0xc6,0xe8,0xdd,0x74,0x1f,0x4b,0xbd,0x8b,0x8a,
  5280. 0x70,0x3e,0xb5,0x66,0x48,0x03,0xf6,0x0e,0x61,0x35,0x57,0xb9,0x86,0xc1,0x1d,0x9e,
  5281. 0xe1,0xf8,0x98,0x11,0x69,0xd9,0x8e,0x94,0x9b,0x1e,0x87,0xe9,0xce,0x55,0x28,0xdf,
  5282. 0x8c,0xa1,0x89,0x0d,0xbf,0xe6,0x42,0x68,0x41,0x99,0x2d,0x0f,0xb0,0x54,0xbb,0x16];
  5283. // rCon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)] [§5.2]
  5284. Aes.rCon = [ [0x00, 0x00, 0x00, 0x00],
  5285. [0x01, 0x00, 0x00, 0x00],
  5286. [0x02, 0x00, 0x00, 0x00],
  5287. [0x04, 0x00, 0x00, 0x00],
  5288. [0x08, 0x00, 0x00, 0x00],
  5289. [0x10, 0x00, 0x00, 0x00],
  5290. [0x20, 0x00, 0x00, 0x00],
  5291. [0x40, 0x00, 0x00, 0x00],
  5292. [0x80, 0x00, 0x00, 0x00],
  5293. [0x1b, 0x00, 0x00, 0x00],
  5294. [0x36, 0x00, 0x00, 0x00] ];
  5295. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  5296. /* AES Counter-mode implementation in JavaScript (c) Chris Veness 2005-2011 */
  5297. /* - see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf */
  5298. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  5299. Aes.Ctr = {}; // Aes.Ctr namespace: a subclass or extension of Aes
  5300. /**
  5301. * Encrypt a text using AES encryption in Counter mode of operation
  5302. *
  5303. * Unicode multi-byte character safe
  5304. *
  5305. * @param {String} plaintext Source text to be encrypted
  5306. * @param {String} password The password to use to generate a key
  5307. * @param {Number} nBits Number of bits to be used in the key (128, 192, or 256)
  5308. * @returns {string} Encrypted text
  5309. */
  5310. Aes.Ctr.encrypt = function(plaintext, password, nBits) {
  5311. var blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
  5312. if (!(nBits==128 || nBits==192 || nBits==256)) return ''; // standard allows 128/192/256 bit keys
  5313. plaintext = Utf8.encode(plaintext);
  5314. password = Utf8.encode(password);
  5315. //var t = new Date(); // timer
  5316. // use AES itself to encrypt password to get cipher key (using plain password as source for key
  5317. // expansion) - gives us well encrypted key (though hashed key might be preferred for prod'n use)
  5318. var nBytes = nBits/8; // no bytes in key (16/24/32)
  5319. var pwBytes = new Array(nBytes);
  5320. for (var i=0; i<nBytes; i++) { // use 1st 16/24/32 chars of password for key
  5321. pwBytes[i] = isNaN(password.charCodeAt(i)) ? 0 : password.charCodeAt(i);
  5322. }
  5323. var key = Aes.cipher(pwBytes, Aes.keyExpansion(pwBytes)); // gives us 16-byte key
  5324. key = key.concat(key.slice(0, nBytes-16)); // expand key to 16/24/32 bytes long
  5325. // initialise 1st 8 bytes of counter block with nonce (NIST SP800-38A §B.2): [0-1] = millisec,
  5326. // [2-3] = random, [4-7] = seconds, together giving full sub-millisec uniqueness up to Feb 2106
  5327. var counterBlock = new Array(blockSize);
  5328. var nonce = (new Date()).getTime(); // timestamp: milliseconds since 1-Jan-1970
  5329. var nonceMs = nonce%1000;
  5330. var nonceSec = Math.floor(nonce/1000);
  5331. var nonceRnd = Math.floor(Math.random()*0xffff);
  5332. for (var i=0; i<2; i++) counterBlock[i] = (nonceMs >>> i*8) & 0xff;
  5333. for (var i=0; i<2; i++) counterBlock[i+2] = (nonceRnd >>> i*8) & 0xff;
  5334. for (var i=0; i<4; i++) counterBlock[i+4] = (nonceSec >>> i*8) & 0xff;
  5335. // and convert it to a string to go on the front of the ciphertext
  5336. var ctrTxt = '';
  5337. for (var i=0; i<8; i++) ctrTxt += String.fromCharCode(counterBlock[i]);
  5338. // generate key schedule - an expansion of the key into distinct Key Rounds for each round
  5339. var keySchedule = Aes.keyExpansion(key);
  5340. var blockCount = Math.ceil(plaintext.length/blockSize);
  5341. var ciphertxt = new Array(blockCount); // ciphertext as array of strings
  5342. for (var b=0; b<blockCount; b++) {
  5343. // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
  5344. // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB)
  5345. for (var c=0; c<4; c++) counterBlock[15-c] = (b >>> c*8) & 0xff;
  5346. for (var c=0; c<4; c++) counterBlock[15-c-4] = (b/0x100000000 >>> c*8)
  5347. var cipherCntr = Aes.cipher(counterBlock, keySchedule); // -- encrypt counter block --
  5348. // block size is reduced on final block
  5349. var blockLength = b<blockCount-1 ? blockSize : (plaintext.length-1)%blockSize+1;
  5350. var cipherChar = new Array(blockLength);
  5351. for (var i=0; i<blockLength; i++) { // -- xor plaintext with ciphered counter char-by-char --
  5352. cipherChar[i] = cipherCntr[i] ^ plaintext.charCodeAt(b*blockSize+i);
  5353. cipherChar[i] = String.fromCharCode(cipherChar[i]);
  5354. }
  5355. ciphertxt[b] = cipherChar.join('');
  5356. }
  5357. // Array.join is more efficient than repeated string concatenation in IE
  5358. var ciphertext = ctrTxt + ciphertxt.join('');
  5359. ciphertext = Base64.encode(ciphertext); // encode in base64
  5360. //alert((new Date()) - t);
  5361. return ciphertext;
  5362. }
  5363. /**
  5364. * Decrypt a text encrypted by AES in counter mode of operation
  5365. *
  5366. * @param {String} ciphertext Source text to be encrypted
  5367. * @param {String} password The password to use to generate a key
  5368. * @param {Number} nBits Number of bits to be used in the key (128, 192, or 256)
  5369. * @returns {String} Decrypted text
  5370. */
  5371. Aes.Ctr.decrypt = function(ciphertext, password, nBits) {
  5372. var blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
  5373. if (!(nBits==128 || nBits==192 || nBits==256)) return ''; // standard allows 128/192/256 bit keys
  5374. ciphertext = Base64.decode(ciphertext);
  5375. password = Utf8.encode(password);
  5376. //var t = new Date(); // timer
  5377. // use AES to encrypt password (mirroring encrypt routine)
  5378. var nBytes = nBits/8; // no bytes in key
  5379. var pwBytes = new Array(nBytes);
  5380. for (var i=0; i<nBytes; i++) {
  5381. pwBytes[i] = isNaN(password.charCodeAt(i)) ? 0 : password.charCodeAt(i);
  5382. }
  5383. var key = Aes.cipher(pwBytes, Aes.keyExpansion(pwBytes));
  5384. key = key.concat(key.slice(0, nBytes-16)); // expand key to 16/24/32 bytes long
  5385. // recover nonce from 1st 8 bytes of ciphertext
  5386. var counterBlock = new Array(8);
  5387. ctrTxt = ciphertext.slice(0, 8);
  5388. for (var i=0; i<8; i++) counterBlock[i] = ctrTxt.charCodeAt(i);
  5389. // generate key schedule
  5390. var keySchedule = Aes.keyExpansion(key);
  5391. // separate ciphertext into blocks (skipping past initial 8 bytes)
  5392. var nBlocks = Math.ceil((ciphertext.length-8) / blockSize);
  5393. var ct = new Array(nBlocks);
  5394. for (var b=0; b<nBlocks; b++) ct[b] = ciphertext.slice(8+b*blockSize, 8+b*blockSize+blockSize);
  5395. ciphertext = ct; // ciphertext is now array of block-length strings
  5396. // plaintext will get generated block-by-block into array of block-length strings
  5397. var plaintxt = new Array(ciphertext.length);
  5398. for (var b=0; b<nBlocks; b++) {
  5399. // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
  5400. for (var c=0; c<4; c++) counterBlock[15-c] = ((b) >>> c*8) & 0xff;
  5401. for (var c=0; c<4; c++) counterBlock[15-c-4] = (((b+1)/0x100000000-1) >>> c*8) & 0xff;
  5402. var cipherCntr = Aes.cipher(counterBlock, keySchedule); // encrypt counter block
  5403. var plaintxtByte = new Array(ciphertext[b].length);
  5404. for (var i=0; i<ciphertext[b].length; i++) {
  5405. // -- xor plaintxt with ciphered counter byte-by-byte --
  5406. plaintxtByte[i] = cipherCntr[i] ^ ciphertext[b].charCodeAt(i);
  5407. plaintxtByte[i] = String.fromCharCode(plaintxtByte[i]);
  5408. }
  5409. plaintxt[b] = plaintxtByte.join('');
  5410. }
  5411. // join array of blocks into single plaintext string
  5412. var plaintext = plaintxt.join('');
  5413. plaintext = Utf8.decode(plaintext); // decode from UTF8 back to Unicode multi-byte chars
  5414. //alert((new Date()) - t);
  5415. return plaintext;
  5416. }
  5417. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  5418. /* Base64 class: Base 64 encoding / decoding (c) Chris Veness 2002-2011 */
  5419. /* note: depends on Utf8 class */
  5420. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  5421. var Base64 = {}; // Base64 namespace
  5422. Base64.code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  5423. /**
  5424. * Encode string into Base64, as defined by RFC 4648 [http://tools.ietf.org/html/rfc4648]
  5425. * (instance method extending String object). As per RFC 4648, no newlines are added.
  5426. *
  5427. * @param {String} str The string to be encoded as base-64
  5428. * @param {Boolean} [utf8encode=false] Flag to indicate whether str is Unicode string to be encoded
  5429. * to UTF8 before conversion to base64; otherwise string is assumed to be 8-bit characters
  5430. * @returns {String} Base64-encoded string
  5431. */
  5432. Base64.encode = function(str, utf8encode) { // http://tools.ietf.org/html/rfc4648
  5433. utf8encode = (typeof utf8encode == 'undefined') ? false : utf8encode;
  5434. var o1, o2, o3, bits, h1, h2, h3, h4, e=[], pad = '', c, plain, coded;
  5435. var b64 = Base64.code;
  5436. plain = utf8encode ? str.encodeUTF8() : str;
  5437. c = plain.length % 3; // pad string to length of multiple of 3
  5438. if (c > 0) { while (c++ < 3) { pad += '='; plain += '\0'; } }
  5439. // note: doing padding here saves us doing special-case packing for trailing 1 or 2 chars
  5440. for (c=0; c<plain.length; c+=3) { // pack three octets into four hexets
  5441. o1 = plain.charCodeAt(c);
  5442. o2 = plain.charCodeAt(c+1);
  5443. o3 = plain.charCodeAt(c+2);
  5444. bits = o1<<16 | o2<<8 | o3;
  5445. h1 = bits>>18 & 0x3f;
  5446. h2 = bits>>12 & 0x3f;
  5447. h3 = bits>>6 & 0x3f;
  5448. h4 = bits & 0x3f;
  5449. // use hextets to index into code string
  5450. e[c/3] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
  5451. }
  5452. coded = e.join(''); // join() is far faster than repeated string concatenation in IE
  5453. // replace 'A's from padded nulls with '='s
  5454. coded = coded.slice(0, coded.length-pad.length) + pad;
  5455. return coded;
  5456. }
  5457. /**
  5458. * Decode string from Base64, as defined by RFC 4648 [http://tools.ietf.org/html/rfc4648]
  5459. * (instance method extending String object). As per RFC 4648, newlines are not catered for.
  5460. *
  5461. * @param {String} str The string to be decoded from base-64
  5462. * @param {Boolean} [utf8decode=false] Flag to indicate whether str is Unicode string to be decoded
  5463. * from UTF8 after conversion from base64
  5464. * @returns {String} decoded string
  5465. */
  5466. Base64.decode = function(str, utf8decode) {
  5467. utf8decode = (typeof utf8decode == 'undefined') ? false : utf8decode;
  5468. var o1, o2, o3, h1, h2, h3, h4, bits, d=[], plain, coded;
  5469. var b64 = Base64.code;
  5470. coded = utf8decode ? str.decodeUTF8() : str;
  5471. for (var c=0; c<coded.length; c+=4) { // unpack four hexets into three octets
  5472. h1 = b64.indexOf(coded.charAt(c));
  5473. h2 = b64.indexOf(coded.charAt(c+1));
  5474. h3 = b64.indexOf(coded.charAt(c+2));
  5475. h4 = b64.indexOf(coded.charAt(c+3));
  5476. bits = h1<<18 | h2<<12 | h3<<6 | h4;
  5477. o1 = bits>>>16 & 0xff;
  5478. o2 = bits>>>8 & 0xff;
  5479. o3 = bits & 0xff;
  5480. d[c/4] = String.fromCharCode(o1, o2, o3);
  5481. // check for padding
  5482. if (h4 == 0x40) d[c/4] = String.fromCharCode(o1, o2);
  5483. if (h3 == 0x40) d[c/4] = String.fromCharCode(o1);
  5484. }
  5485. plain = d.join(''); // join() is far faster than repeated string concatenation in IE
  5486. return utf8decode ? plain.decodeUTF8() : plain;
  5487. }
  5488. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  5489. /* Utf8 class: encode / decode between multi-byte Unicode characters and UTF-8 multiple */
  5490. /* single-byte character encoding (c) Chris Veness 2002-2011 */
  5491. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  5492. var Utf8 = {}; // Utf8 namespace
  5493. /**
  5494. * Encode multi-byte Unicode string into utf-8 multiple single-byte characters
  5495. * (BMP / basic multilingual plane only)
  5496. *
  5497. * Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars
  5498. *
  5499. * @param {String} strUni Unicode string to be encoded as UTF-8
  5500. * @returns {String} encoded string
  5501. */
  5502. Utf8.encode = function(strUni) {
  5503. // use regular expressions & String.replace callback function for better efficiency
  5504. // than procedural approaches
  5505. var strUtf = strUni.replace(
  5506. /[\u0080-\u07ff]/g, // U+0080 - U+07FF => 2 bytes 110yyyyy, 10zzzzzz
  5507. function(c) {
  5508. var cc = c.charCodeAt(0);
  5509. return String.fromCharCode(0xc0 | cc>>6, 0x80 | cc&0x3f); }
  5510. );
  5511. strUtf = strUtf.replace(
  5512. /[\u0800-\uffff]/g, // U+0800 - U+FFFF => 3 bytes 1110xxxx, 10yyyyyy, 10zzzzzz
  5513. function(c) {
  5514. var cc = c.charCodeAt(0);
  5515. return String.fromCharCode(0xe0 | cc>>12, 0x80 | cc>>6&0x3F, 0x80 | cc&0x3f); }
  5516. );
  5517. return strUtf;
  5518. }
  5519. /**
  5520. * Decode utf-8 encoded string back into multi-byte Unicode characters
  5521. *
  5522. * @param {String} strUtf UTF-8 string to be decoded back to Unicode
  5523. * @returns {String} decoded string
  5524. */
  5525. Utf8.decode = function(strUtf) {
  5526. // note: decode 3-byte chars first as decoded 2-byte strings could appear to be 3-byte char!
  5527. var strUni = strUtf.replace(
  5528. /[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, // 3-byte chars
  5529. function(c) { // (note parentheses for precence)
  5530. var cc = ((c.charCodeAt(0)&0x0f)<<12) | ((c.charCodeAt(1)&0x3f)<<6) | ( c.charCodeAt(2)&0x3f);
  5531. return String.fromCharCode(cc); }
  5532. );
  5533. strUni = strUni.replace(
  5534. /[\u00c0-\u00df][\u0080-\u00bf]/g, // 2-byte chars
  5535. function(c) { // (note parentheses for precence)
  5536. var cc = (c.charCodeAt(0)&0x1f)<<6 | c.charCodeAt(1)&0x3f;
  5537. return String.fromCharCode(cc); }
  5538. );
  5539. return strUni;
  5540. }
  5541. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  5542. /* **********************************************
  5543. Begin bootstrap-tooltip.js
  5544. ********************************************** */
  5545. /* ===========================================================
  5546. * bootstrap-tooltip.js v2.0.1
  5547. * http://twitter.github.com/bootstrap/javascript.html#tooltips
  5548. * Inspired by the original jQuery.tipsy by Jason Frame
  5549. * ===========================================================
  5550. * Copyright 2012 Twitter, Inc.
  5551. *
  5552. * Licensed under the Apache License, Version 2.0 (the "License");
  5553. * you may not use this file except in compliance with the License.
  5554. * You may obtain a copy of the License at
  5555. *
  5556. * http://www.apache.org/licenses/LICENSE-2.0
  5557. *
  5558. * Unless required by applicable law or agreed to in writing, software
  5559. * distributed under the License is distributed on an "AS IS" BASIS,
  5560. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5561. * See the License for the specific language governing permissions and
  5562. * limitations under the License.
  5563. * ========================================================== */
  5564. !function( $ ) {
  5565. "use strict"
  5566. /* TOOLTIP PUBLIC CLASS DEFINITION
  5567. * =============================== */
  5568. var Tooltip = function ( element, options ) {
  5569. this.init('tooltip', element, options)
  5570. }
  5571. Tooltip.prototype = {
  5572. constructor: Tooltip
  5573. , init: function ( type, element, options ) {
  5574. var eventIn
  5575. , eventOut
  5576. this.type = type
  5577. this.$element = $(element)
  5578. this.options = this.getOptions(options)
  5579. this.enabled = true
  5580. if (this.options.trigger != 'manual') {
  5581. eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
  5582. eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
  5583. this.$element.on(eventIn, this.options.selector, $.proxy(this.enter, this))
  5584. this.$element.on(eventOut, this.options.selector, $.proxy(this.leave, this))
  5585. }
  5586. this.options.selector ?
  5587. (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
  5588. this.fixTitle()
  5589. }
  5590. , getOptions: function ( options ) {
  5591. options = $.extend({}, $.fn[this.type].defaults, options, this.$element.data())
  5592. if (options.delay && typeof options.delay == 'number') {
  5593. options.delay = {
  5594. show: options.delay
  5595. , hide: options.delay
  5596. }
  5597. }
  5598. return options
  5599. }
  5600. , enter: function ( e ) {
  5601. var self = $(e.currentTarget)[this.type](this._options).data(this.type)
  5602. if (!self.options.delay || !self.options.delay.show) {
  5603. self.show()
  5604. } else {
  5605. self.hoverState = 'in'
  5606. setTimeout(function() {
  5607. if (self.hoverState == 'in') {
  5608. self.show()
  5609. }
  5610. }, self.options.delay.show)
  5611. }
  5612. }
  5613. , leave: function ( e ) {
  5614. var self = $(e.currentTarget)[this.type](this._options).data(this.type)
  5615. if (!self.options.delay || !self.options.delay.hide) {
  5616. self.hide()
  5617. } else {
  5618. self.hoverState = 'out'
  5619. setTimeout(function() {
  5620. if (self.hoverState == 'out') {
  5621. self.hide()
  5622. }
  5623. }, self.options.delay.hide)
  5624. }
  5625. }
  5626. , show: function () {
  5627. var $tip
  5628. , inside
  5629. , pos
  5630. , actualWidth
  5631. , actualHeight
  5632. , placement
  5633. , tp
  5634. if (this.hasContent() && this.enabled) {
  5635. $tip = this.tip()
  5636. this.setContent()
  5637. if (this.options.animation) {
  5638. $tip.addClass('fade')
  5639. }
  5640. placement = typeof this.options.placement == 'function' ?
  5641. this.options.placement.call(this, $tip[0], this.$element[0]) :
  5642. this.options.placement
  5643. inside = /in/.test(placement)
  5644. $tip
  5645. .remove()
  5646. .css({ top: 0, left: 0, display: 'block' })
  5647. .appendTo(inside ? this.$element : document.body)
  5648. pos = this.getPosition(inside)
  5649. actualWidth = $tip[0].offsetWidth
  5650. actualHeight = $tip[0].offsetHeight
  5651. switch (inside ? placement.split(' ')[1] : placement) {
  5652. case 'bottom':
  5653. tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
  5654. break
  5655. case 'top':
  5656. tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}
  5657. break
  5658. case 'left':
  5659. tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}
  5660. break
  5661. case 'right':
  5662. tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}
  5663. break
  5664. }
  5665. $tip
  5666. .css(tp)
  5667. .addClass(placement)
  5668. .addClass('in')
  5669. }
  5670. }
  5671. , setContent: function () {
  5672. var $tip = this.tip()
  5673. $tip.find('.timeline-tooltip-inner').html(this.getTitle())
  5674. $tip.removeClass('fade in top bottom left right')
  5675. }
  5676. , hide: function () {
  5677. var that = this
  5678. , $tip = this.tip()
  5679. $tip.removeClass('in')
  5680. function removeWithAnimation() {
  5681. var timeout = setTimeout(function () {
  5682. $tip.off($.support.transition.end).remove()
  5683. }, 500)
  5684. $tip.one($.support.transition.end, function () {
  5685. clearTimeout(timeout)
  5686. $tip.remove()
  5687. })
  5688. }
  5689. $.support.transition && this.$tip.hasClass('fade') ?
  5690. removeWithAnimation() :
  5691. $tip.remove()
  5692. }
  5693. , fixTitle: function () {
  5694. var $e = this.$element
  5695. if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
  5696. $e.attr('data-original-title', $e.attr('title') || '').removeAttr('title')
  5697. }
  5698. }
  5699. , hasContent: function () {
  5700. return this.getTitle()
  5701. }
  5702. , getPosition: function (inside) {
  5703. return $.extend({}, (inside ? {top: 0, left: 0} : this.$element.offset()), {
  5704. width: this.$element[0].offsetWidth
  5705. , height: this.$element[0].offsetHeight
  5706. })
  5707. }
  5708. , getTitle: function () {
  5709. var title
  5710. , $e = this.$element
  5711. , o = this.options
  5712. title = $e.attr('data-original-title')
  5713. || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
  5714. title = title.toString().replace(/(^\s*|\s*$)/, "")
  5715. return title
  5716. }
  5717. , tip: function () {
  5718. return this.$tip = this.$tip || $(this.options.template)
  5719. }
  5720. , validate: function () {
  5721. if (!this.$element[0].parentNode) {
  5722. this.hide()
  5723. this.$element = null
  5724. this.options = null
  5725. }
  5726. }
  5727. , enable: function () {
  5728. this.enabled = true
  5729. }
  5730. , disable: function () {
  5731. this.enabled = false
  5732. }
  5733. , toggleEnabled: function () {
  5734. this.enabled = !this.enabled
  5735. }
  5736. , toggle: function () {
  5737. this[this.tip().hasClass('in') ? 'hide' : 'show']()
  5738. }
  5739. }
  5740. /* TOOLTIP PLUGIN DEFINITION
  5741. * ========================= */
  5742. $.fn.tooltip = function ( option ) {
  5743. return this.each(function () {
  5744. var $this = $(this)
  5745. , data = $this.data('tooltip')
  5746. , options = typeof option == 'object' && option
  5747. if (!data) $this.data('tooltip', (data = new Tooltip(this, options)))
  5748. if (typeof option == 'string') data[option]()
  5749. })
  5750. }
  5751. $.fn.tooltip.Constructor = Tooltip
  5752. $.fn.tooltip.defaults = {
  5753. animation: true
  5754. , delay: 0
  5755. , selector: false
  5756. , placement: 'top'
  5757. , trigger: 'hover'
  5758. , title: ''
  5759. , template: '<div class="timeline-tooltip"><div class="timeline-tooltip-arrow"></div><div class="timeline-tooltip-inner"></div></div>'
  5760. }
  5761. }( window.jQuery );
  5762. /* **********************************************
  5763. Begin VMM.StoryJS.js
  5764. ********************************************** */
  5765. /* VeriteCo StoryJS
  5766. ================================================== */
  5767. /* * CodeKit Import
  5768. * http://incident57.com/codekit/
  5769. ================================================== */
  5770. // @codekit-prepend "Core/VMM.Core.js";
  5771. // @codekit-prepend "Language/VMM.Language.js";
  5772. // @codekit-prepend "Media/VMM.Media.js";
  5773. // @codekit-prepend "Slider/VMM.DragSlider.js";
  5774. // @codekit-prepend "Slider/VMM.Slider.js";
  5775. // @codekit-prepend "Library/AES.js";
  5776. // @codekit-prepend "Library/bootstrap-tooltip.js";
  5777. if(typeof VMM != 'undefined' && typeof VMM.StoryJS == 'undefined') {
  5778. VMM.StoryJS = function() {
  5779. /* PRIVATE VARS
  5780. ================================================== */
  5781. /* PUBLIC FUNCTIONS
  5782. ================================================== */
  5783. this.init = function(d) {
  5784. };
  5785. }
  5786. }
  5787. /* **********************************************
  5788. Begin VMM.Timeline.js
  5789. ********************************************** */
  5790. // VMM.Timeline.js
  5791. /* * CodeKit Import
  5792. * http://incident57.com/codekit/
  5793. ================================================== */
  5794. // @codekit-prepend "Core/VMM.StoryJS.js";
  5795. // @codekit-append "VMM.Timeline.TimeNav.js";
  5796. // @codekit-append "VMM.Timeline.DataObj.js";
  5797. /* Timeline
  5798. ================================================== */
  5799. if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
  5800. VMM.Timeline = function(_timeline_id, w, h) {
  5801. var $timeline,
  5802. $container,
  5803. $feature,
  5804. $feedback,
  5805. $slider,
  5806. $navigation,
  5807. slider,
  5808. timenav,
  5809. version = "2.x",
  5810. timeline_id = "#timelinejs",
  5811. events = {},
  5812. data = {},
  5813. _dates = [],
  5814. config = {},
  5815. has_width = false,
  5816. has_height = false,
  5817. ie7 = false,
  5818. is_moving = false;
  5819. if (type.of(_timeline_id) == "string") {
  5820. if (_timeline_id.match("#")) {
  5821. timeline_id = _timeline_id;
  5822. } else {
  5823. timeline_id = "#" + _timeline_id;
  5824. }
  5825. } else {
  5826. timeline_id = "#timelinejs";
  5827. }
  5828. /* CONFIG
  5829. ================================================== */
  5830. config = {
  5831. embed: false,
  5832. events: {
  5833. data_ready: "DATAREADY",
  5834. messege: "MESSEGE",
  5835. headline: "HEADLINE",
  5836. slide_change: "SLIDE_CHANGE",
  5837. resize: "resize"
  5838. },
  5839. id: timeline_id,
  5840. source: "nothing",
  5841. type: "timeline",
  5842. touch: false,
  5843. orientation: "normal",
  5844. maptype: "",
  5845. version: "2.x",
  5846. preload: 4,
  5847. current_slide: 0,
  5848. hash_bookmark: false,
  5849. start_at_end: false,
  5850. start_at_slide: 0,
  5851. start_zoom_adjust: 0,
  5852. start_page: false,
  5853. api_keys: {
  5854. google: "",
  5855. flickr: "",
  5856. twitter: ""
  5857. },
  5858. interval: 10,
  5859. something: 0,
  5860. width: 960,
  5861. height: 540,
  5862. spacing: 15,
  5863. loaded: {
  5864. slider: false,
  5865. timenav: false,
  5866. percentloaded: 0
  5867. },
  5868. nav: {
  5869. start_page: false,
  5870. interval_width: 200,
  5871. density: 4,
  5872. minor_width: 0,
  5873. minor_left: 0,
  5874. constraint: {
  5875. left: 0,
  5876. right: 0,
  5877. right_min: 0,
  5878. right_max: 0
  5879. },
  5880. zoom: {
  5881. adjust: 0
  5882. },
  5883. multiplier: {
  5884. current: 6,
  5885. min: .1,
  5886. max: 50
  5887. },
  5888. rows: [1, 1, 1],
  5889. width: 960,
  5890. height: 200,
  5891. marker: {
  5892. width: 150,
  5893. height: 50
  5894. }
  5895. },
  5896. feature: {
  5897. width: 960,
  5898. height: 540
  5899. },
  5900. slider: {
  5901. width: 720,
  5902. height: 400,
  5903. content: {
  5904. width: 720,
  5905. height: 400,
  5906. padding: 130,
  5907. padding_default:130
  5908. },
  5909. nav: {
  5910. width: 100,
  5911. height: 200
  5912. }
  5913. },
  5914. ease: "easeInOutExpo",
  5915. duration: 1000,
  5916. gmap_key: "",
  5917. language: VMM.Language
  5918. };
  5919. if ( w != null && w != "") {
  5920. config.width = w;
  5921. has_width = true;
  5922. }
  5923. if ( h != null && h != "") {
  5924. config.height = h;
  5925. has_height = true;
  5926. }
  5927. if(window.location.hash) {
  5928. var hash = window.location.hash.substring(1);
  5929. if (!isNaN(hash)) {
  5930. config.current_slide = parseInt(hash);
  5931. }
  5932. }
  5933. window.onhashchange = function () {
  5934. var hash = window.location.hash.substring(1);
  5935. if (config.hash_bookmark) {
  5936. if (is_moving) {
  5937. goToEvent(parseInt(hash));
  5938. } else {
  5939. is_moving = false;
  5940. }
  5941. } else {
  5942. goToEvent(parseInt(hash));
  5943. }
  5944. }
  5945. /* CREATE CONFIG
  5946. ================================================== */
  5947. function createConfig(conf) {
  5948. // APPLY SUPPLIED CONFIG TO TIMELINE CONFIG
  5949. if (typeof embed_config == 'object') {
  5950. timeline_config = embed_config;
  5951. }
  5952. if (typeof timeline_config == 'object') {
  5953. trace("HAS TIMELINE CONFIG");
  5954. config = VMM.Util.mergeConfig(config, timeline_config);
  5955. } else if (typeof conf == 'object') {
  5956. config = VMM.Util.mergeConfig(config, conf);
  5957. }
  5958. if (VMM.Browser.device == "mobile" || VMM.Browser.device == "tablet") {
  5959. config.touch = true;
  5960. }
  5961. config.nav.width = config.width;
  5962. config.nav.height = 200;
  5963. config.feature.width = config.width;
  5964. config.feature.height = config.height - config.nav.height;
  5965. config.nav.zoom.adjust = parseInt(config.start_zoom_adjust, 10);
  5966. VMM.Timeline.Config = config;
  5967. VMM.master_config.Timeline = VMM.Timeline.Config;
  5968. this.events = config.events;
  5969. if (config.gmap_key != "") {
  5970. config.api_keys.google = config.gmap_key;
  5971. }
  5972. trace("VERSION " + config.version);
  5973. version = config.version;
  5974. }
  5975. /* CREATE TIMELINE STRUCTURE
  5976. ================================================== */
  5977. function createStructure() {
  5978. // CREATE DOM STRUCTURE
  5979. $timeline = VMM.getElement(timeline_id);
  5980. VMM.Lib.addClass($timeline, "vco-timeline");
  5981. VMM.Lib.addClass($timeline, "vco-storyjs");
  5982. $container = VMM.appendAndGetElement($timeline, "<div>", "vco-container vco-main");
  5983. $feature = VMM.appendAndGetElement($container, "<div>", "vco-feature");
  5984. $slider = VMM.appendAndGetElement($feature, "<div>", "vco-slider");
  5985. $navigation = VMM.appendAndGetElement($container, "<div>", "vco-navigation");
  5986. $feedback = VMM.appendAndGetElement($timeline, "<div>", "vco-feedback", "");
  5987. if (typeof config.language.right_to_left != 'undefined') {
  5988. VMM.Lib.addClass($timeline, "vco-right-to-left");
  5989. }
  5990. slider = new VMM.Slider($slider, config);
  5991. timenav = new VMM.Timeline.TimeNav($navigation);
  5992. if (!has_width) {
  5993. config.width = VMM.Lib.width($timeline);
  5994. } else {
  5995. VMM.Lib.width($timeline, config.width);
  5996. }
  5997. if (!has_height) {
  5998. config.height = VMM.Lib.height($timeline);
  5999. } else {
  6000. VMM.Lib.height($timeline, config.height);
  6001. }
  6002. if (config.touch) {
  6003. VMM.Lib.addClass($timeline, "vco-touch");
  6004. } else {
  6005. VMM.Lib.addClass($timeline, "vco-notouch");
  6006. }
  6007. }
  6008. /* ON EVENT
  6009. ================================================== */
  6010. function onDataReady(e, d) {
  6011. trace("onDataReady");
  6012. data = d.timeline;
  6013. if (type.of(data.era) != "array") {
  6014. data.era = [];
  6015. }
  6016. buildDates();
  6017. };
  6018. function onDatesProcessed() {
  6019. build();
  6020. }
  6021. function reSize() {
  6022. updateSize();
  6023. slider.setSize(config.feature.width, config.feature.height);
  6024. timenav.setSize(config.width, config.height);
  6025. if (orientationChange()) {
  6026. setViewport();
  6027. }
  6028. };
  6029. function onSliderLoaded(e) {
  6030. config.loaded.slider = true;
  6031. onComponentLoaded();
  6032. };
  6033. function onComponentLoaded(e) {
  6034. config.loaded.percentloaded = config.loaded.percentloaded + 25;
  6035. if (config.loaded.slider && config.loaded.timenav) {
  6036. hideMessege();
  6037. }
  6038. }
  6039. function onTimeNavLoaded(e) {
  6040. config.loaded.timenav = true;
  6041. onComponentLoaded();
  6042. }
  6043. function onSlideUpdate(e) {
  6044. is_moving = true;
  6045. config.current_slide = slider.getCurrentNumber();
  6046. setHash(config.current_slide);
  6047. timenav.setMarker(config.current_slide, config.ease,config.duration);
  6048. };
  6049. function onMarkerUpdate(e) {
  6050. is_moving = true;
  6051. config.current_slide = timenav.getCurrentNumber();
  6052. setHash(config.current_slide);
  6053. slider.setSlide(config.current_slide);
  6054. };
  6055. function goToEvent(n) {
  6056. if (n <= _dates.length - 1 && n >= 0) {
  6057. config.current_slide = n;
  6058. slider.setSlide(config.current_slide);
  6059. timenav.setMarker(config.current_slide, config.ease,config.duration);
  6060. }
  6061. }
  6062. function setHash(n) {
  6063. if (config.hash_bookmark) {
  6064. window.location.hash = "#" + n.toString();
  6065. }
  6066. }
  6067. function getViewport() {
  6068. }
  6069. function setViewport() {
  6070. var viewport_content = "",
  6071. viewport_orientation = searchOrientation(window.orientation);
  6072. if (VMM.Browser.device == "mobile") {
  6073. if (viewport_orientation == "portrait") {
  6074. //viewport_content = "width=device-width; initial-scale=0.75, maximum-scale=0.75";
  6075. viewport_content = "width=device-width; initial-scale=0.5, maximum-scale=0.5";
  6076. } else if (viewport_orientation == "landscape") {
  6077. viewport_content = "width=device-width; initial-scale=0.5, maximum-scale=0.5";
  6078. } else {
  6079. viewport_content = "width=device-width, initial-scale=1, maximum-scale=1.0";
  6080. }
  6081. } else if (VMM.Browser.device == "tablet") {
  6082. //viewport_content = "width=device-width, initial-scale=1, maximum-scale=1.0";
  6083. }
  6084. if (document.getElementById("viewport")) {
  6085. //VMM.Lib.attr("#viewport", "content", viewport_content);
  6086. } else {
  6087. //VMM.appendElement("head", "<meta id='viewport' name='viewport' content=" + viewport_content + "/>");
  6088. }
  6089. }
  6090. /* ORIENTATION
  6091. ================================================== */
  6092. function searchOrientation(orientation) {
  6093. var orient = "";
  6094. if ( orientation == 0 || orientation == 180) {
  6095. orient = "portrait";
  6096. } else if ( orientation == 90 || orientation == -90) {
  6097. orient = "landscape";
  6098. } else {
  6099. orient = "normal";
  6100. }
  6101. return orient;
  6102. }
  6103. function orientationChange() {
  6104. var orientation = searchOrientation(window.orientation);
  6105. if (orientation == config.orientation) {
  6106. return false;
  6107. } else {
  6108. config.orientation = orientation;
  6109. return true;
  6110. }
  6111. }
  6112. /* PUBLIC FUNCTIONS
  6113. ================================================== */
  6114. this.init = function(c, _data) {
  6115. trace('INIT');
  6116. setViewport();
  6117. createConfig(c);
  6118. createStructure();
  6119. if (type.of(_data) == "string") {
  6120. config.source = _data;
  6121. }
  6122. // LANGUAGE
  6123. VMM.Date.setLanguage(config.language);
  6124. VMM.master_config.language = config.language;
  6125. // EXTERNAL API
  6126. VMM.ExternalAPI.setKeys(config.api_keys);
  6127. VMM.ExternalAPI.googlemaps.setMapType(config.maptype);
  6128. // EVENTS
  6129. VMM.bindEvent(global, onDataReady, config.events.data_ready);
  6130. VMM.bindEvent(global, showMessege, config.events.messege);
  6131. VMM.fireEvent(global, config.events.messege, config.language.messages.loading_timeline);
  6132. /* GET DATA
  6133. ================================================== */
  6134. if (VMM.Browser.browser == "Explorer" || VMM.Browser.browser == "MSIE") {
  6135. if (parseInt(VMM.Browser.version, 10) <= 7 && (VMM.Browser.tridentVersion == null || VMM.Browser.tridentVersion < 4)) {
  6136. ie7 = true;
  6137. }
  6138. }
  6139. if (type.of(config.source) == "string" || type.of(config.source) == "object") {
  6140. VMM.Timeline.DataObj.getData(config.source);
  6141. } else {
  6142. VMM.fireEvent(global, config.events.messege, "No data source provided");
  6143. //VMM.Timeline.DataObj.getData(VMM.getElement(timeline_id));
  6144. }
  6145. };
  6146. this.iframeLoaded = function() {
  6147. trace("iframeLoaded");
  6148. };
  6149. this.reload = function(_d) {
  6150. trace("Load new timeline data" + _d);
  6151. VMM.fireEvent(global, config.events.messege, config.language.messages.loading_timeline);
  6152. data = {};
  6153. VMM.Timeline.DataObj.getData(_d);
  6154. config.current_slide = 0;
  6155. slider.setSlide(0);
  6156. timenav.setMarker(0, config.ease,config.duration);
  6157. };
  6158. /* DATA
  6159. ================================================== */
  6160. function getData(url) {
  6161. VMM.getJSON(url, function(d) {
  6162. data = VMM.Timeline.DataObj.getData(d);
  6163. VMM.fireEvent(global, config.events.data_ready);
  6164. });
  6165. };
  6166. /* MESSEGES
  6167. ================================================== */
  6168. function showMessege(e, msg, other) {
  6169. trace("showMessege " + msg);
  6170. //VMM.attachElement($timeline, $feedback);
  6171. if (other) {
  6172. VMM.attachElement($feedback, msg);
  6173. } else{
  6174. VMM.attachElement($feedback, VMM.MediaElement.loadingmessage(msg));
  6175. }
  6176. };
  6177. function hideMessege() {
  6178. VMM.Lib.animate($feedback, config.duration, config.ease*4, {"opacity": 0}, detachMessege);
  6179. };
  6180. function detachMessege() {
  6181. VMM.Lib.detach($feedback);
  6182. }
  6183. /* BUILD DISPLAY
  6184. ================================================== */
  6185. function build() {
  6186. // START AT SLIDE
  6187. if (parseInt(config.start_at_slide) > 0 && config.current_slide == 0) {
  6188. config.current_slide = parseInt(config.start_at_slide);
  6189. }
  6190. // START AT END
  6191. if (config.start_at_end && config.current_slide == 0) {
  6192. config.current_slide = _dates.length - 1;
  6193. }
  6194. // IE7
  6195. if (ie7) {
  6196. ie7 = true;
  6197. VMM.fireEvent(global, config.events.messege, "Internet Explorer " + VMM.Browser.version + " is not supported by TimelineJS. Please update your browser to version 8 or higher. If you are using a recent version of Internet Explorer you may need to disable compatibility mode in your browser.");
  6198. } else {
  6199. detachMessege();
  6200. reSize();
  6201. // EVENT LISTENERS
  6202. VMM.bindEvent($slider, onSliderLoaded, "LOADED");
  6203. VMM.bindEvent($navigation, onTimeNavLoaded, "LOADED");
  6204. VMM.bindEvent($slider, onSlideUpdate, "UPDATE");
  6205. VMM.bindEvent($navigation, onMarkerUpdate, "UPDATE");
  6206. // INITIALIZE COMPONENTS
  6207. slider.init(_dates);
  6208. timenav.init(_dates, data.era);
  6209. // RESIZE EVENT LISTENERS
  6210. VMM.bindEvent(global, reSize, config.events.resize);
  6211. }
  6212. };
  6213. function updateSize() {
  6214. trace("UPDATE SIZE");
  6215. config.width = VMM.Lib.width($timeline);
  6216. config.height = VMM.Lib.height($timeline);
  6217. config.nav.width = config.width;
  6218. config.feature.width = config.width;
  6219. config.feature.height = config.height - config.nav.height - 3;
  6220. if (VMM.Browser.device == "mobile") {
  6221. /*
  6222. if (VMM.Browser.orientation == "portrait") {
  6223. config.feature.height = 480;
  6224. config.height = 480 + config.nav.height;
  6225. } else if(VMM.Browser.orientation == "landscape") {
  6226. config.feature.height = 320;
  6227. config.height = 320 + config.nav.height;
  6228. } else {
  6229. config.feature.height = config.height - config.nav.height - 3;
  6230. }
  6231. */
  6232. }
  6233. if (config.width < 641) {
  6234. VMM.Lib.addClass($timeline, "vco-skinny");
  6235. } else {
  6236. VMM.Lib.removeClass($timeline, "vco-skinny");
  6237. }
  6238. };
  6239. // BUILD DATE OBJECTS
  6240. function buildDates() {
  6241. _dates = [];
  6242. VMM.fireEvent(global, config.events.messege, "Building Dates");
  6243. updateSize();
  6244. for(var i = 0; i < data.date.length; i++) {
  6245. if (data.date[i].startDate != null && data.date[i].startDate != "") {
  6246. var _date = {},
  6247. do_start = VMM.Date.parse(data.date[i].startDate, true),
  6248. do_end;
  6249. _date.startdate = do_start.date;
  6250. _date.precisiondate = do_start.precision;
  6251. if (!isNaN(_date.startdate)) {
  6252. // END DATE
  6253. if (data.date[i].endDate != null && data.date[i].endDate != "") {
  6254. _date.enddate = VMM.Date.parse(data.date[i].endDate);
  6255. } else {
  6256. _date.enddate = _date.startdate;
  6257. }
  6258. _date.needs_slug = false;
  6259. if (data.date[i].headline == "") {
  6260. if (data.date[i].slug != null && data.date[i].slug != "") {
  6261. _date.needs_slug = true;
  6262. }
  6263. }
  6264. _date.title = data.date[i].headline;
  6265. _date.headline = data.date[i].headline;
  6266. _date.type = data.date[i].type;
  6267. _date.date = VMM.Date.prettyDate(_date.startdate, false, _date.precisiondate);
  6268. _date.asset = data.date[i].asset;
  6269. _date.fulldate = _date.startdate.getTime();
  6270. _date.text = data.date[i].text;
  6271. _date.content = "";
  6272. _date.tag = data.date[i].tag;
  6273. _date.slug = data.date[i].slug;
  6274. _date.uniqueid = VMM.Util.unique_ID(7);
  6275. _date.classname = data.date[i].classname;
  6276. _dates.push(_date);
  6277. }
  6278. }
  6279. };
  6280. /* CUSTOM SORT
  6281. ================================================== */
  6282. if (data.type != "storify") {
  6283. _dates.sort(function(a, b){
  6284. return a.fulldate - b.fulldate
  6285. });
  6286. }
  6287. /* CREATE START PAGE IF AVAILABLE
  6288. ================================================== */
  6289. if (data.headline != null && data.headline != "" && data.text != null && data.text != "") {
  6290. var startpage_date,
  6291. do_start,
  6292. _date = {},
  6293. td_num = 0,
  6294. td;
  6295. if (typeof data.startDate != 'undefined') {
  6296. do_start = VMM.Date.parse(data.startDate, true);
  6297. startpage_date = do_start.date;
  6298. } else {
  6299. startpage_date = false;
  6300. }
  6301. trace("HAS STARTPAGE");
  6302. trace(startpage_date);
  6303. if (startpage_date && startpage_date < _dates[0].startdate) {
  6304. _date.startdate = new Date(startpage_date);
  6305. } else {
  6306. td = _dates[0].startdate;
  6307. _date.startdate = new Date(_dates[0].startdate);
  6308. if (td.getMonth() === 0 && td.getDate() == 1 && td.getHours() === 0 && td.getMinutes() === 0 ) {
  6309. // trace("YEAR ONLY");
  6310. _date.startdate.setFullYear(td.getFullYear() - 1);
  6311. } else if (td.getDate() <= 1 && td.getHours() === 0 && td.getMinutes() === 0) {
  6312. // trace("YEAR MONTH");
  6313. _date.startdate.setMonth(td.getMonth() - 1);
  6314. } else if (td.getHours() === 0 && td.getMinutes() === 0) {
  6315. // trace("YEAR MONTH DAY");
  6316. _date.startdate.setDate(td.getDate() - 1);
  6317. } else if (td.getMinutes() === 0) {
  6318. // trace("YEAR MONTH DAY HOUR");
  6319. _date.startdate.setHours(td.getHours() - 1);
  6320. } else {
  6321. // trace("YEAR MONTH DAY HOUR MINUTE");
  6322. _date.startdate.setMinutes(td.getMinutes() - 1);
  6323. }
  6324. }
  6325. _date.uniqueid = VMM.Util.unique_ID(7);
  6326. _date.enddate = _date.startdate;
  6327. _date.precisiondate = do_start.precision;
  6328. _date.title = data.headline;
  6329. _date.headline = data.headline;
  6330. _date.text = data.text;
  6331. _date.type = "start";
  6332. _date.date = VMM.Date.prettyDate(data.startDate, false, _date.precisiondate);
  6333. _date.asset = data.asset;
  6334. _date.slug = false;
  6335. _date.needs_slug = false;
  6336. _date.fulldate = _date.startdate.getTime();
  6337. if (config.embed) {
  6338. VMM.fireEvent(global, config.events.headline, _date.headline);
  6339. }
  6340. _dates.unshift(_date);
  6341. }
  6342. /* CUSTOM SORT
  6343. ================================================== */
  6344. if (data.type != "storify") {
  6345. _dates.sort(function(a, b){
  6346. return a.fulldate - b.fulldate
  6347. });
  6348. }
  6349. onDatesProcessed();
  6350. }
  6351. };
  6352. VMM.Timeline.Config = {};
  6353. };
  6354. /* **********************************************
  6355. Begin VMM.Timeline.TimeNav.js
  6356. ********************************************** */
  6357. /* VMM.Timeline.TimeNav.js
  6358. TimeNav
  6359. This class handles the bottom timeline navigation.
  6360. It requires the VMM.Util class and VMM.Date class
  6361. ================================================== */
  6362. if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefined') {
  6363. VMM.Timeline.TimeNav = function(parent, content_width, content_height) {
  6364. trace("VMM.Timeline.TimeNav");
  6365. var $timenav, $content, $time, $timeintervalminor, $timeinterval, $timeintervalmajor, $timebackground,
  6366. $timeintervalbackground, $timenavline, $timenavindicator, $timeintervalminor_minor, $toolbar, $zoomin, $zoomout, $dragslide,
  6367. config = VMM.Timeline.Config,
  6368. row_height,
  6369. events = {},
  6370. timespan = {},
  6371. layout = parent,
  6372. data = [],
  6373. era_markers = [],
  6374. markers = [],
  6375. interval_array = [],
  6376. interval_major_array = [],
  6377. tags = [],
  6378. current_marker = 0,
  6379. _active = false,
  6380. eras,
  6381. content,
  6382. timeouts = {
  6383. interval_position: ""
  6384. },
  6385. timenav_pos = {
  6386. left: "",
  6387. visible: {
  6388. left: "",
  6389. right: ""
  6390. }
  6391. },
  6392. timelookup = {
  6393. day: 24,
  6394. month: 12,
  6395. year: 10,
  6396. hour: 60,
  6397. minute: 60,
  6398. second: 1000,
  6399. decade: 10,
  6400. century: 100,
  6401. millenium: 1000,
  6402. age: 1000000,
  6403. epoch: 10000000,
  6404. era: 100000000,
  6405. eon: 500000000,
  6406. week: 4.34812141,
  6407. days_in_month: 30.4368499,
  6408. days_in_week: 7,
  6409. weeks_in_month: 4.34812141,
  6410. weeks_in_year: 52.177457,
  6411. days_in_year: 365.242199,
  6412. hours_in_day: 24
  6413. },
  6414. dateFractionBrowser = {
  6415. day: 86400000,
  6416. week: 7,
  6417. month: 30.4166666667,
  6418. year: 12,
  6419. hour: 24,
  6420. minute: 1440,
  6421. second: 86400,
  6422. decade: 10,
  6423. century: 100,
  6424. millenium: 1000,
  6425. age: 1000000,
  6426. epoch: 10000000,
  6427. era: 100000000,
  6428. eon: 500000000
  6429. },
  6430. interval = {
  6431. type: "year",
  6432. number: 10,
  6433. first: 1970,
  6434. last: 2011,
  6435. multiplier: 100,
  6436. classname: "_idd",
  6437. interval_type: "interval"
  6438. },
  6439. interval_major = {
  6440. type: "year",
  6441. number: 10,
  6442. first: 1970,
  6443. last: 2011,
  6444. multiplier: 100,
  6445. classname: "major",
  6446. interval_type: "interval major"
  6447. },
  6448. interval_macro = {
  6449. type: "year",
  6450. number: 10,
  6451. first: 1970,
  6452. last: 2011,
  6453. multiplier: 100,
  6454. classname: "_dd_minor",
  6455. interval_type: "interval minor"
  6456. },
  6457. interval_calc = {
  6458. day: {},
  6459. month: {},
  6460. year: {},
  6461. hour: {},
  6462. minute: {},
  6463. second: {},
  6464. decade: {},
  6465. century: {},
  6466. millenium: {},
  6467. week: {},
  6468. age: {},
  6469. epoch: {},
  6470. era: {},
  6471. eon: {}
  6472. };
  6473. /* ADD to Config
  6474. ================================================== */
  6475. row_height = config.nav.marker.height/2;
  6476. config.nav.rows = {
  6477. full: [1, row_height*2, row_height*4],
  6478. half: [1, row_height, row_height*2, row_height*3, row_height*4, row_height*5],
  6479. current: []
  6480. }
  6481. if (content_width != null && content_width != "") {
  6482. config.nav.width = content_width;
  6483. }
  6484. if (content_height != null && content_height != "") {
  6485. config.nav.height = content_height;
  6486. }
  6487. /* INIT
  6488. ================================================== */
  6489. this.init = function(d,e) {
  6490. trace('VMM.Timeline.TimeNav init');
  6491. // need to evaluate d
  6492. // some function to determine type of data and prepare it
  6493. if(typeof d != 'undefined') {
  6494. this.setData(d, e);
  6495. } else {
  6496. trace("WAITING ON DATA");
  6497. }
  6498. };
  6499. /* GETTERS AND SETTERS
  6500. ================================================== */
  6501. this.setData = function(d,e) {
  6502. if(typeof d != 'undefined') {
  6503. data = {};
  6504. data = d;
  6505. eras = e;
  6506. build();
  6507. } else{
  6508. trace("NO DATA");
  6509. }
  6510. };
  6511. this.setSize = function(w, h) {
  6512. if (w != null) {config.width = w};
  6513. if (h != null) {config.height = h};
  6514. if (_active) {
  6515. reSize();
  6516. }
  6517. }
  6518. this.setMarker = function(n, ease, duration, fast) {
  6519. goToMarker(n, ease, duration);
  6520. }
  6521. this.getCurrentNumber = function() {
  6522. return current_marker;
  6523. }
  6524. /* ON EVENT
  6525. ================================================== */
  6526. function onConfigSet() {
  6527. trace("onConfigSet");
  6528. };
  6529. function reSize(firstrun) {
  6530. config.nav.constraint.left = (config.width/2);
  6531. config.nav.constraint.right = config.nav.constraint.right_min - (config.width/2);
  6532. $dragslide.updateConstraint(config.nav.constraint);
  6533. VMM.Lib.css($timenavline, "left", Math.round(config.width/2)+2);
  6534. VMM.Lib.css($timenavindicator, "left", Math.round(config.width/2)-8);
  6535. goToMarker(config.current_slide, config.ease, config.duration, true, firstrun);
  6536. };
  6537. function upDate() {
  6538. VMM.fireEvent(layout, "UPDATE");
  6539. }
  6540. function onZoomIn() {
  6541. $dragslide.cancelSlide();
  6542. if (config.nav.multiplier.current > config.nav.multiplier.min) {
  6543. if (config.nav.multiplier.current <= 1) {
  6544. config.nav.multiplier.current = config.nav.multiplier.current - .25;
  6545. } else {
  6546. if (config.nav.multiplier.current > 5) {
  6547. if (config.nav.multiplier.current > 16) {
  6548. config.nav.multiplier.current = Math.round(config.nav.multiplier.current - 10);
  6549. } else {
  6550. config.nav.multiplier.current = Math.round(config.nav.multiplier.current - 4);
  6551. }
  6552. } else {
  6553. config.nav.multiplier.current = Math.round(config.nav.multiplier.current - 1);
  6554. }
  6555. }
  6556. if (config.nav.multiplier.current <= 0) {
  6557. config.nav.multiplier.current = config.nav.multiplier.min;
  6558. }
  6559. refreshTimeline();
  6560. }
  6561. }
  6562. function onZoomOut() {
  6563. $dragslide.cancelSlide();
  6564. if (config.nav.multiplier.current < config.nav.multiplier.max) {
  6565. if (config.nav.multiplier.current > 4) {
  6566. if (config.nav.multiplier.current > 16) {
  6567. config.nav.multiplier.current = Math.round(config.nav.multiplier.current + 10);
  6568. } else {
  6569. config.nav.multiplier.current = Math.round(config.nav.multiplier.current + 4);
  6570. }
  6571. } else {
  6572. config.nav.multiplier.current = Math.round(config.nav.multiplier.current + 1);
  6573. }
  6574. if (config.nav.multiplier.current >= config.nav.multiplier.max) {
  6575. config.nav.multiplier.current = config.nav.multiplier.max;
  6576. }
  6577. refreshTimeline();
  6578. }
  6579. }
  6580. function onBackHome(e) {
  6581. $dragslide.cancelSlide();
  6582. goToMarker(0);
  6583. upDate();
  6584. }
  6585. function onMouseScroll(e) {
  6586. var delta = 0,
  6587. scroll_to = 0;
  6588. if (!e) {
  6589. e = window.event;
  6590. }
  6591. if (e.originalEvent) {
  6592. e = e.originalEvent;
  6593. }
  6594. // Browsers unable to differntiate between up/down and left/right scrolling
  6595. /*
  6596. if (e.wheelDelta) {
  6597. delta = e.wheelDelta/6;
  6598. } else if (e.detail) {
  6599. delta = -e.detail*12;
  6600. }
  6601. */
  6602. // Webkit and browsers able to differntiate between up/down and left/right scrolling
  6603. if (typeof e.wheelDeltaX != 'undefined' ) {
  6604. delta = e.wheelDeltaY/6;
  6605. if (Math.abs(e.wheelDeltaX) > Math.abs(e.wheelDeltaY)) {
  6606. delta = e.wheelDeltaX/6;
  6607. } else {
  6608. //delta = e.wheelDeltaY/6;
  6609. delta = 0;
  6610. }
  6611. }
  6612. if (delta) {
  6613. if (e.preventDefault) {
  6614. e.preventDefault();
  6615. }
  6616. e.returnValue = false;
  6617. }
  6618. // Stop from scrolling too far
  6619. scroll_to = VMM.Lib.position($timenav).left + delta;
  6620. if (scroll_to > config.nav.constraint.left) {
  6621. scroll_to = config.width/2;
  6622. } else if (scroll_to < config.nav.constraint.right) {
  6623. scroll_to = config.nav.constraint.right;
  6624. }
  6625. //VMM.Lib.stop($timenav);
  6626. //VMM.Lib.animate($timenav, config.duration/2, "linear", {"left": scroll_to});
  6627. VMM.Lib.css($timenav, "left", scroll_to);
  6628. }
  6629. function refreshTimeline() {
  6630. trace("config.nav.multiplier " + config.nav.multiplier.current);
  6631. positionMarkers(true);
  6632. positionEras(true);
  6633. positionInterval($timeinterval, interval_array, true, true);
  6634. positionInterval($timeintervalmajor, interval_major_array, true);
  6635. config.nav.constraint.left = (config.width/2);
  6636. config.nav.constraint.right = config.nav.constraint.right_min - (config.width/2);
  6637. $dragslide.updateConstraint(config.nav.constraint);
  6638. };
  6639. /* MARKER EVENTS
  6640. ================================================== */
  6641. function onMarkerClick(e) {
  6642. $dragslide.cancelSlide();
  6643. goToMarker(e.data.number);
  6644. upDate();
  6645. };
  6646. function onMarkerHover(e) {
  6647. VMM.Lib.toggleClass(e.data.elem, "zFront");
  6648. };
  6649. function goToMarker(n, ease, duration, fast, firstrun) {
  6650. trace("GO TO MARKER");
  6651. var _ease = config.ease,
  6652. _duration = config.duration,
  6653. is_last = false,
  6654. is_first = false;
  6655. current_marker = n;
  6656. timenav_pos.left = (config.width/2) - markers[current_marker].pos_left
  6657. timenav_pos.visible.left = Math.abs(timenav_pos.left) - 100;
  6658. timenav_pos.visible.right = Math.abs(timenav_pos.left) + config.width + 100;
  6659. if (current_marker == 0) {
  6660. is_first = true;
  6661. }
  6662. if (current_marker +1 == markers.length) {
  6663. is_last = true
  6664. }
  6665. if (ease != null && ease != "") {_ease = ease};
  6666. if (duration != null && duration != "") {_duration = duration};
  6667. // set marker style
  6668. for(var i = 0; i < markers.length; i++) {
  6669. VMM.Lib.removeClass(markers[i].marker, "active");
  6670. }
  6671. if (config.start_page && markers[0].type == "start") {
  6672. VMM.Lib.visible(markers[0].marker, false);
  6673. VMM.Lib.addClass(markers[0].marker, "start");
  6674. }
  6675. VMM.Lib.addClass(markers[current_marker].marker, "active");
  6676. // ANIMATE MARKER
  6677. VMM.Lib.stop($timenav);
  6678. VMM.Lib.animate($timenav, _duration, _ease, {"left": timenav_pos.left});
  6679. }
  6680. /* TOUCH EVENTS
  6681. ================================================== */
  6682. function onTouchUpdate(e, b) {
  6683. VMM.Lib.animate($timenav, b.time/2, config.ease, {"left": b.left});
  6684. };
  6685. /* CALCULATIONS
  6686. ================================================== */
  6687. function averageMarkerPositionDistance() {
  6688. var last_pos = 0,
  6689. pos = 0,
  6690. pos_dif = 0,
  6691. mp_diff = [],
  6692. i = 0;
  6693. for(i = 0; i < markers.length; i++) {
  6694. if (data[i].type == "start") {
  6695. } else {
  6696. var _pos = positionOnTimeline(interval, markers[i].relative_pos),
  6697. last_pos = pos;
  6698. pos = _pos.begin;
  6699. pos_dif = pos - last_pos;
  6700. mp_diff.push(pos_dif);
  6701. }
  6702. }
  6703. return VMM.Util.average(mp_diff).mean;
  6704. }
  6705. function averageDateDistance() {
  6706. var last_dd = 0,
  6707. dd = 0,
  6708. _dd = "",
  6709. date_dif = 0,
  6710. date_diffs = [],
  6711. is_first_date = true,
  6712. i = 0;
  6713. for(i = 0; i < data.length; i++) {
  6714. if (data[i].type == "start") {
  6715. trace("DATA DATE IS START")
  6716. } else {
  6717. _dd = data[i].startdate;
  6718. last_dd = dd;
  6719. dd = _dd;
  6720. date_dif = dd - last_dd;
  6721. date_diffs.push(date_dif);
  6722. }
  6723. }
  6724. return VMM.Util.average(date_diffs);
  6725. }
  6726. function calculateMultiplier() {
  6727. var temp_multiplier = config.nav.multiplier.current,
  6728. i = 0;
  6729. for(i = 0; i < temp_multiplier; i++) {
  6730. if (averageMarkerPositionDistance() < 75) {
  6731. if (config.nav.multiplier.current > 1) {
  6732. config.nav.multiplier.current = (config.nav.multiplier.current - 1);
  6733. }
  6734. }
  6735. }
  6736. }
  6737. function calculateInterval() {
  6738. // NEED TO REWRITE ALL OF THIS
  6739. var _first = getDateFractions(data[0].startdate),
  6740. _last = getDateFractions(data[data.length - 1].enddate);
  6741. // EON
  6742. interval_calc.eon.type = "eon";
  6743. interval_calc.eon.first = _first.eons;
  6744. interval_calc.eon.base = Math.floor(_first.eons);
  6745. interval_calc.eon.last = _last.eons;
  6746. interval_calc.eon.number = timespan.eons;
  6747. interval_calc.eon.multiplier = timelookup.eons;
  6748. interval_calc.eon.minor = timelookup.eons;
  6749. // ERA
  6750. interval_calc.era.type = "era";
  6751. interval_calc.era.first = _first.eras;
  6752. interval_calc.era.base = Math.floor(_first.eras);
  6753. interval_calc.era.last = _last.eras;
  6754. interval_calc.era.number = timespan.eras;
  6755. interval_calc.era.multiplier = timelookup.eras;
  6756. interval_calc.era.minor = timelookup.eras;
  6757. // EPOCH
  6758. interval_calc.epoch.type = "epoch";
  6759. interval_calc.epoch.first = _first.epochs;
  6760. interval_calc.epoch.base = Math.floor(_first.epochs);
  6761. interval_calc.epoch.last = _last.epochs;
  6762. interval_calc.epoch.number = timespan.epochs;
  6763. interval_calc.epoch.multiplier = timelookup.epochs;
  6764. interval_calc.epoch.minor = timelookup.epochs;
  6765. // AGE
  6766. interval_calc.age.type = "age";
  6767. interval_calc.age.first = _first.ages;
  6768. interval_calc.age.base = Math.floor(_first.ages);
  6769. interval_calc.age.last = _last.ages;
  6770. interval_calc.age.number = timespan.ages;
  6771. interval_calc.age.multiplier = timelookup.ages;
  6772. interval_calc.age.minor = timelookup.ages;
  6773. // MILLENIUM
  6774. interval_calc.millenium.type = "millenium";
  6775. interval_calc.millenium.first = _first.milleniums;
  6776. interval_calc.millenium.base = Math.floor(_first.milleniums);
  6777. interval_calc.millenium.last = _last.milleniums;
  6778. interval_calc.millenium.number = timespan.milleniums;
  6779. interval_calc.millenium.multiplier = timelookup.millenium;
  6780. interval_calc.millenium.minor = timelookup.millenium;
  6781. // CENTURY
  6782. interval_calc.century.type = "century";
  6783. interval_calc.century.first = _first.centuries;
  6784. interval_calc.century.base = Math.floor(_first.centuries);
  6785. interval_calc.century.last = _last.centuries;
  6786. interval_calc.century.number = timespan.centuries;
  6787. interval_calc.century.multiplier = timelookup.century;
  6788. interval_calc.century.minor = timelookup.century;
  6789. // DECADE
  6790. interval_calc.decade.type = "decade";
  6791. interval_calc.decade.first = _first.decades;
  6792. interval_calc.decade.base = Math.floor(_first.decades);
  6793. interval_calc.decade.last = _last.decades;
  6794. interval_calc.decade.number = timespan.decades;
  6795. interval_calc.decade.multiplier = timelookup.decade;
  6796. interval_calc.decade.minor = timelookup.decade;
  6797. // YEAR
  6798. interval_calc.year.type = "year";
  6799. interval_calc.year.first = _first.years;
  6800. interval_calc.year.base = Math.floor(_first.years);
  6801. interval_calc.year.last = _last.years;
  6802. interval_calc.year.number = timespan.years;
  6803. interval_calc.year.multiplier = 1;
  6804. interval_calc.year.minor = timelookup.month;
  6805. // MONTH
  6806. interval_calc.month.type = "month";
  6807. interval_calc.month.first = _first.months;
  6808. interval_calc.month.base = Math.floor(_first.months);
  6809. interval_calc.month.last = _last.months;
  6810. interval_calc.month.number = timespan.months;
  6811. interval_calc.month.multiplier = 1;
  6812. interval_calc.month.minor = Math.round(timelookup.week);
  6813. // WEEK
  6814. // NOT DONE
  6815. interval_calc.week.type = "week";
  6816. interval_calc.week.first = _first.weeks;
  6817. interval_calc.week.base = Math.floor(_first.weeks);
  6818. interval_calc.week.last = _last.weeks;
  6819. interval_calc.week.number = timespan.weeks;
  6820. interval_calc.week.multiplier = 1;
  6821. interval_calc.week.minor = 7;
  6822. // DAY
  6823. interval_calc.day.type = "day";
  6824. interval_calc.day.first = _first.days;
  6825. interval_calc.day.base = Math.floor(_first.days);
  6826. interval_calc.day.last = _last.days;
  6827. interval_calc.day.number = timespan.days;
  6828. interval_calc.day.multiplier = 1;
  6829. interval_calc.day.minor = 24;
  6830. // HOUR
  6831. interval_calc.hour.type = "hour";
  6832. interval_calc.hour.first = _first.hours;
  6833. interval_calc.hour.base = Math.floor(_first.hours);
  6834. interval_calc.hour.last = _last.hours;
  6835. interval_calc.hour.number = timespan.hours;
  6836. interval_calc.hour.multiplier = 1;
  6837. interval_calc.hour.minor = 60;
  6838. // MINUTE
  6839. interval_calc.minute.type = "minute";
  6840. interval_calc.minute.first = _first.minutes;
  6841. interval_calc.minute.base = Math.floor(_first.minutes);
  6842. interval_calc.minute.last = _last.minutes;
  6843. interval_calc.minute.number = timespan.minutes;
  6844. interval_calc.minute.multiplier = 1;
  6845. interval_calc.minute.minor = 60;
  6846. // SECOND
  6847. interval_calc.second.type = "decade";
  6848. interval_calc.second.first = _first.seconds;
  6849. interval_calc.second.base = Math.floor(_first.seconds);
  6850. interval_calc.second.last = _last.seconds;
  6851. interval_calc.second.number = timespan.seconds;
  6852. interval_calc.second.multiplier = 1;
  6853. interval_calc.second.minor = 10;
  6854. }
  6855. function getDateFractions(the_date, is_utc) {
  6856. var _time = {};
  6857. _time.days = the_date / dateFractionBrowser.day;
  6858. _time.weeks = _time.days / dateFractionBrowser.week;
  6859. _time.months = _time.days / dateFractionBrowser.month;
  6860. _time.years = _time.months / dateFractionBrowser.year;
  6861. _time.hours = _time.days * dateFractionBrowser.hour;
  6862. _time.minutes = _time.days * dateFractionBrowser.minute;
  6863. _time.seconds = _time.days * dateFractionBrowser.second;
  6864. _time.decades = _time.years / dateFractionBrowser.decade;
  6865. _time.centuries = _time.years / dateFractionBrowser.century;
  6866. _time.milleniums = _time.years / dateFractionBrowser.millenium;
  6867. _time.ages = _time.years / dateFractionBrowser.age;
  6868. _time.epochs = _time.years / dateFractionBrowser.epoch;
  6869. _time.eras = _time.years / dateFractionBrowser.era;
  6870. _time.eons = _time.years / dateFractionBrowser.eon;
  6871. /*
  6872. trace("AGES " + _time.ages);
  6873. trace("EPOCHS " + _time.epochs);
  6874. trace("MILLENIUMS " + _time.milleniums);
  6875. trace("CENTURIES " + _time.centuries);
  6876. trace("DECADES " + _time.decades);
  6877. trace("YEARS " + _time.years);
  6878. trace("MONTHS " + _time.months);
  6879. trace("WEEKS " + _time.weeks);
  6880. trace("DAYS " + _time.days);
  6881. trace("HOURS " + _time.hours);
  6882. trace("MINUTES " + _time.minutes);
  6883. trace("SECONDS " + _time.seconds);
  6884. */
  6885. return _time;
  6886. }
  6887. /* POSITION
  6888. Positions elements on the timeline based on date
  6889. relative to the calculated interval
  6890. ================================================== */
  6891. function positionRelative(_interval, first, last) {
  6892. var _first,
  6893. _last,
  6894. _type = _interval.type,
  6895. timerelative = {
  6896. start: "",
  6897. end: "",
  6898. type: _type
  6899. };
  6900. /* FIRST
  6901. ================================================== */
  6902. _first = getDateFractions(first);
  6903. timerelative.start = first.months;
  6904. if (_type == "eon") {
  6905. timerelative.start = _first.eons;
  6906. } else if (_type == "era") {
  6907. timerelative.start = _first.eras;
  6908. } else if (_type == "epoch") {
  6909. timerelative.start = _first.epochs;
  6910. } else if (_type == "age") {
  6911. timerelative.start = _first.ages;
  6912. } else if (_type == "millenium") {
  6913. timerelative.start = first.milleniums;
  6914. } else if (_type == "century") {
  6915. timerelative.start = _first.centuries;
  6916. } else if (_type == "decade") {
  6917. timerelative.start = _first.decades;
  6918. } else if (_type == "year") {
  6919. timerelative.start = _first.years;
  6920. } else if (_type == "month") {
  6921. timerelative.start = _first.months;
  6922. } else if (_type == "week") {
  6923. timerelative.start = _first.weeks;
  6924. } else if (_type == "day") {
  6925. timerelative.start = _first.days;
  6926. } else if (_type == "hour") {
  6927. timerelative.start = _first.hours;
  6928. } else if (_type == "minute") {
  6929. timerelative.start = _first.minutes;
  6930. }
  6931. /* LAST
  6932. ================================================== */
  6933. if (type.of(last) == "date") {
  6934. _last = getDateFractions(last);
  6935. timerelative.end = last.months;
  6936. if (_type == "eon") {
  6937. timerelative.end = _last.eons;
  6938. } else if (_type == "era") {
  6939. timerelative.end = _last.eras;
  6940. } else if (_type == "epoch") {
  6941. timerelative.end = _last.epochs;
  6942. } else if (_type == "age") {
  6943. timerelative.end = _last.ages;
  6944. } else if (_type == "millenium") {
  6945. timerelative.end = last.milleniums;
  6946. } else if (_type == "century") {
  6947. timerelative.end = _last.centuries;
  6948. } else if (_type == "decade") {
  6949. timerelative.end = _last.decades;
  6950. } else if (_type == "year") {
  6951. timerelative.end = _last.years;
  6952. } else if (_type == "month") {
  6953. timerelative.end = _last.months;
  6954. } else if (_type == "week") {
  6955. timerelative.end = _last.weeks;
  6956. } else if (_type == "day") {
  6957. timerelative.end = _last.days;
  6958. } else if (_type == "hour") {
  6959. timerelative.end = _last.hours;
  6960. } else if (_type == "minute") {
  6961. timerelative.end = _last.minutes;
  6962. }
  6963. } else {
  6964. timerelative.end = timerelative.start;
  6965. }
  6966. return timerelative
  6967. }
  6968. function positionOnTimeline(the_interval, timerelative) {
  6969. return {
  6970. begin: (timerelative.start - interval.base) * (config.nav.interval_width / config.nav.multiplier.current),
  6971. end: (timerelative.end - interval.base) * (config.nav.interval_width / config.nav.multiplier.current)
  6972. };
  6973. }
  6974. function positionMarkers(is_animated) {
  6975. var row = 2,
  6976. previous_pos = 0,
  6977. pos_offset = -2,
  6978. row_depth = 0,
  6979. row_depth_sub = 0,
  6980. line_last_height_pos = 150,
  6981. line_height = 6,
  6982. cur_mark = 0,
  6983. in_view_margin = config.width,
  6984. pos_cache_array = [],
  6985. pos_cache_max = 6,
  6986. in_view = {
  6987. left: timenav_pos.visible.left - in_view_margin,
  6988. right: timenav_pos.visible.right + in_view_margin
  6989. },
  6990. i = 0,
  6991. k = 0;
  6992. config.nav.minor_width = config.width;
  6993. VMM.Lib.removeClass(".flag", "row1");
  6994. VMM.Lib.removeClass(".flag", "row2");
  6995. VMM.Lib.removeClass(".flag", "row3");
  6996. for(i = 0; i < markers.length; i++) {
  6997. var line,
  6998. marker = markers[i],
  6999. pos = positionOnTimeline(interval, markers[i].relative_pos),
  7000. row_pos = 0,
  7001. is_in_view = false,
  7002. pos_cache_obj = {id: i, pos: 0, row: 0},
  7003. pos_cache_close = 0;
  7004. // COMPENSATE FOR DATES BEING POITIONED IN THE MIDDLE
  7005. pos.begin = Math.round(pos.begin + pos_offset);
  7006. pos.end = Math.round(pos.end + pos_offset);
  7007. line = Math.round(pos.end - pos.begin);
  7008. marker.pos_left = pos.begin;
  7009. if (current_marker == i) {
  7010. timenav_pos.left = (config.width/2) - pos;
  7011. timenav_pos.visible.left = Math.abs(timenav_pos.left);
  7012. timenav_pos.visible.right = Math.abs(timenav_pos.left) + config.width;
  7013. in_view.left = timenav_pos.visible.left - in_view_margin;
  7014. in_view.right = timenav_pos.visible.right + in_view_margin;
  7015. }
  7016. if (Math.abs(pos.begin) >= in_view.left && Math.abs(pos.begin) <= in_view.right ) {
  7017. is_in_view = true;
  7018. }
  7019. // APPLY POSITION TO MARKER
  7020. if (is_animated) {
  7021. VMM.Lib.stop(marker.marker);
  7022. VMM.Lib.animate(marker.marker, config.duration/2, config.ease, {"left": pos.begin});
  7023. } else {
  7024. VMM.Lib.stop(marker.marker);
  7025. VMM.Lib.css(marker.marker, "left", pos.begin);
  7026. }
  7027. if (i == current_marker) {
  7028. cur_mark = pos.begin;
  7029. }
  7030. // EVENT LENGTH LINE
  7031. if (line > 5) {
  7032. VMM.Lib.css(marker.lineevent, "height", line_height);
  7033. VMM.Lib.css(marker.lineevent, "top", line_last_height_pos);
  7034. if (is_animated) {
  7035. VMM.Lib.animate(marker.lineevent, config.duration/2, config.ease, {"width": line});
  7036. } else {
  7037. VMM.Lib.css(marker.lineevent, "width", line);
  7038. }
  7039. }
  7040. // CONTROL ROW POSITION
  7041. if (tags.length > 0) {
  7042. for (k = 0; k < tags.length; k++) {
  7043. if (k < config.nav.rows.current.length) {
  7044. if (marker.tag == tags[k]) {
  7045. row = k;
  7046. if (k == config.nav.rows.current.length - 1) {
  7047. trace("ON LAST ROW");
  7048. VMM.Lib.addClass(marker.flag, "flag-small-last");
  7049. }
  7050. }
  7051. }
  7052. }
  7053. row_pos = config.nav.rows.current[row];
  7054. } else {
  7055. if (pos.begin - previous_pos.begin < (config.nav.marker.width + config.spacing)) {
  7056. if (row < config.nav.rows.current.length - 1) {
  7057. row ++;
  7058. } else {
  7059. row = 0;
  7060. row_depth ++;
  7061. }
  7062. } else {
  7063. row_depth = 1;
  7064. row = 1;
  7065. }
  7066. row_pos = config.nav.rows.current[row];
  7067. }
  7068. // SET LAST MARKER POSITION
  7069. previous_pos = pos;
  7070. // POSITION CACHE
  7071. pos_cache_obj.pos = pos;
  7072. pos_cache_obj.row = row;
  7073. pos_cache_array.push(pos_cache_obj);
  7074. if (pos_cache_array.length > pos_cache_max) {
  7075. VMM.Util.removeRange(pos_cache_array,0);
  7076. }
  7077. //if (is_animated && is_in_view) {
  7078. if (is_animated) {
  7079. VMM.Lib.stop(marker.flag);
  7080. VMM.Lib.animate(marker.flag, config.duration, config.ease, {"top": row_pos});
  7081. } else {
  7082. VMM.Lib.stop(marker.flag);
  7083. VMM.Lib.css(marker.flag, "top", row_pos);
  7084. }
  7085. // IS THE MARKER A REPRESENTATION OF A START SCREEN?
  7086. if (config.start_page && markers[i].type == "start") {
  7087. VMM.Lib.visible(marker.marker, false);
  7088. }
  7089. if (pos > config.nav.minor_width) {
  7090. config.nav.minor_width = pos;
  7091. }
  7092. if (pos < config.nav.minor_left) {
  7093. config.nav.minor_left = pos;
  7094. }
  7095. }
  7096. // ANIMATE THE TIMELINE TO ADJUST TO CHANGES
  7097. if (is_animated) {
  7098. VMM.Lib.stop($timenav);
  7099. VMM.Lib.animate($timenav, config.duration/2, config.ease, {"left": (config.width/2) - (cur_mark)});
  7100. } else {
  7101. }
  7102. //VMM.Lib.delay_animate(config.duration, $timenav, config.duration/2, config.ease, {"left": (config.width/2) - (cur_mark)});
  7103. }
  7104. function positionEras(is_animated) {
  7105. var i = 0,
  7106. p = 0;
  7107. for(i = 0; i < era_markers.length; i++) {
  7108. var era = era_markers[i],
  7109. pos = positionOnTimeline(interval, era.relative_pos),
  7110. row_pos = 0,
  7111. row = 0,
  7112. era_height = config.nav.marker.height * config.nav.rows.full.length,
  7113. era_length = pos.end - pos.begin;
  7114. // CONTROL ROW POSITION
  7115. if (era.tag != "") {
  7116. era_height = (config.nav.marker.height * config.nav.rows.full.length) / config.nav.rows.current.length;
  7117. for (p = 0; p < tags.length; p++) {
  7118. if (p < config.nav.rows.current.length) {
  7119. if (era.tag == tags[p]) {
  7120. row = p;
  7121. }
  7122. }
  7123. }
  7124. row_pos = config.nav.rows.current[row];
  7125. } else {
  7126. row_pos = -1;
  7127. }
  7128. // APPLY POSITION TO MARKER
  7129. if (is_animated) {
  7130. VMM.Lib.stop(era.content);
  7131. VMM.Lib.stop(era.text_content);
  7132. VMM.Lib.animate(era.content, config.duration/2, config.ease, {"top": row_pos, "left": pos.begin, "width": era_length, "height":era_height});
  7133. VMM.Lib.animate(era.text_content, config.duration/2, config.ease, {"left": pos.begin});
  7134. } else {
  7135. VMM.Lib.stop(era.content);
  7136. VMM.Lib.stop(era.text_content);
  7137. VMM.Lib.css(era.content, "left", pos.begin);
  7138. VMM.Lib.css(era.content, "width", era_length);
  7139. VMM.Lib.css(era.content, "height", era_height);
  7140. VMM.Lib.css(era.content, "top", row_pos);
  7141. VMM.Lib.css(era.text_content, "left", pos.begin);
  7142. }
  7143. }
  7144. }
  7145. function positionInterval(the_main_element, the_intervals, is_animated, is_minor) {
  7146. var last_position = 0,
  7147. last_position_major = 0,
  7148. //in_view_margin = (config.nav.minor_width/config.nav.multiplier.current)/2,
  7149. in_view_margin = config.width,
  7150. in_view = {
  7151. left: timenav_pos.visible.left - in_view_margin,
  7152. right: timenav_pos.visible.right + in_view_margin
  7153. }
  7154. not_too_many = true,
  7155. i = 0;
  7156. config.nav.minor_left = 0;
  7157. if (the_intervals.length > 100) {
  7158. not_too_many = false;
  7159. trace("TOO MANY " + the_intervals.length);
  7160. }
  7161. for(i = 0; i < the_intervals.length; i++) {
  7162. var _interval = the_intervals[i].element,
  7163. _interval_date = the_intervals[i].date,
  7164. _interval_visible = the_intervals[i].visible,
  7165. _pos = positionOnTimeline(interval, the_intervals[i].relative_pos),
  7166. pos = _pos.begin,
  7167. _animation = the_intervals[i].animation,
  7168. is_visible = true,
  7169. is_in_view = false,
  7170. pos_offset = 50;
  7171. _animation.pos = pos;
  7172. _animation.animate = false;
  7173. if (Math.abs(pos) >= in_view.left && Math.abs(pos) <= in_view.right ) {
  7174. is_in_view = true;
  7175. }
  7176. if (true) {
  7177. // CONDENSE WHAT IS DISPLAYED
  7178. if (config.nav.multiplier.current > 16 && is_minor) {
  7179. is_visible = false;
  7180. } else {
  7181. if ((pos - last_position) < 65 ) {
  7182. if ((pos - last_position) < 35 ) {
  7183. if (i%4 == 0) {
  7184. if (pos == 0) {
  7185. is_visible = false;
  7186. }
  7187. } else {
  7188. is_visible = false;
  7189. }
  7190. } else {
  7191. if (!VMM.Util.isEven(i)) {
  7192. is_visible = false;
  7193. }
  7194. }
  7195. }
  7196. }
  7197. if (is_visible) {
  7198. if (the_intervals[i].is_detached) {
  7199. VMM.Lib.append(the_main_element, _interval);
  7200. the_intervals[i].is_detached = false;
  7201. }
  7202. } else {
  7203. the_intervals[i].is_detached = true;
  7204. VMM.Lib.detach(_interval);
  7205. }
  7206. if (_interval_visible) {
  7207. if (!is_visible) {
  7208. _animation.opacity = "0";
  7209. if (is_animated && not_too_many) {
  7210. _animation.animate = true;
  7211. }
  7212. the_intervals[i].interval_visible = false;
  7213. } else {
  7214. _animation.opacity = "100";
  7215. if (is_animated && is_in_view) {
  7216. _animation.animate = true;
  7217. }
  7218. }
  7219. } else {
  7220. _animation.opacity = "100";
  7221. if (is_visible) {
  7222. if (is_animated && not_too_many) {
  7223. _animation.animate = true;
  7224. } else {
  7225. if (is_animated && is_in_view) {
  7226. _animation.animate = true;
  7227. }
  7228. }
  7229. the_intervals[i].interval_visible = true;
  7230. } else {
  7231. if (is_animated && not_too_many) {
  7232. _animation.animate = true;
  7233. }
  7234. }
  7235. }
  7236. last_position = pos;
  7237. if (pos > config.nav.minor_width) {
  7238. config.nav.minor_width = pos;
  7239. }
  7240. if (pos < config.nav.minor_left) {
  7241. config.nav.minor_left = pos;
  7242. }
  7243. }
  7244. if (_animation.animate) {
  7245. VMM.Lib.animate(_interval, config.duration/2, config.ease, {opacity: _animation.opacity, left: _animation.pos});
  7246. } else {
  7247. VMM.Lib.css(_interval, "opacity", _animation.opacity);
  7248. VMM.Lib.css(_interval, "left", pos);
  7249. }
  7250. }
  7251. config.nav.constraint.right_min = -(config.nav.minor_width)+(config.width);
  7252. config.nav.constraint.right = config.nav.constraint.right_min + (config.width/2);
  7253. VMM.Lib.css($timeintervalminor_minor, "left", config.nav.minor_left - (config.width)/2);
  7254. VMM.Lib.width($timeintervalminor_minor, (config.nav.minor_width)+(config.width) + Math.abs(config.nav.minor_left) );
  7255. }
  7256. /* Interval Elements
  7257. ================================================== */
  7258. function createIntervalElements(_interval, _array, _element_parent) {
  7259. var inc_time = 0,
  7260. _first_run = true,
  7261. _last_pos = 0,
  7262. _largest_pos = 0,
  7263. _timezone_offset,
  7264. _first_date,
  7265. _last_date,
  7266. int_number = Math.ceil(_interval.number) + 2,
  7267. firefox = {
  7268. flag: false,
  7269. offset: 0
  7270. },
  7271. i = 0;
  7272. VMM.attachElement(_element_parent, "");
  7273. _interval.date = new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0);
  7274. _timezone_offset = _interval.date.getTimezoneOffset();
  7275. for(i = 0; i < int_number; i++) {
  7276. trace(_interval.type);
  7277. var _is_year = false,
  7278. int_obj = {
  7279. element: VMM.appendAndGetElement(_element_parent, "<div>", _interval.classname),
  7280. date: new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0),
  7281. visible: false,
  7282. date_string: "",
  7283. type: _interval.interval_type,
  7284. relative_pos: 0,
  7285. is_detached: false,
  7286. animation: {
  7287. animate: false,
  7288. pos: "",
  7289. opacity: "100"
  7290. }
  7291. };
  7292. if (_interval.type == "eon") {
  7293. if (_first_run) {
  7294. _first_date = Math.floor(data[0].startdate.getFullYear() / 500000000) * 500000000;
  7295. }
  7296. int_obj.date.setFullYear(_first_date + (inc_time * 500000000));
  7297. _is_year = true;
  7298. } else if (_interval.type == "era") {
  7299. if (_first_run) {
  7300. _first_date = Math.floor(data[0].startdate.getFullYear() / 100000000) * 100000000;
  7301. }
  7302. int_obj.date.setFullYear(_first_date + (inc_time * 100000000));
  7303. _is_year = true;
  7304. } else if (_interval.type == "epoch") {
  7305. if (_first_run) {
  7306. _first_date = Math.floor(data[0].startdate.getFullYear() / 10000000) * 10000000
  7307. }
  7308. int_obj.date.setFullYear(_first_date + (inc_time * 10000000));
  7309. _is_year = true;
  7310. } else if (_interval.type == "age") {
  7311. if (_first_run) {
  7312. _first_date = Math.floor(data[0].startdate.getFullYear() / 1000000) * 1000000
  7313. }
  7314. int_obj.date.setFullYear(_first_date + (inc_time * 1000000));
  7315. _is_year = true;
  7316. } else if (_interval.type == "millenium") {
  7317. if (_first_run) {
  7318. _first_date = Math.floor(data[0].startdate.getFullYear() / 1000) * 1000;
  7319. }
  7320. int_obj.date.setFullYear(_first_date + (inc_time * 1000));
  7321. _is_year = true;
  7322. } else if (_interval.type == "century") {
  7323. if (_first_run) {
  7324. _first_date = Math.floor(data[0].startdate.getFullYear() / 100) * 100
  7325. }
  7326. int_obj.date.setFullYear(_first_date + (inc_time * 100));
  7327. _is_year = true;
  7328. } else if (_interval.type == "decade") {
  7329. if (_first_run) {
  7330. _first_date = Math.floor(data[0].startdate.getFullYear() / 10) * 10;
  7331. }
  7332. int_obj.date.setFullYear(_first_date + (inc_time * 10));
  7333. _is_year = true;
  7334. } else if (_interval.type == "year") {
  7335. if (_first_run) {
  7336. _first_date = data[0].startdate.getFullYear();
  7337. }
  7338. int_obj.date.setFullYear(_first_date + inc_time);
  7339. _is_year = true;
  7340. } else if (_interval.type == "month") {
  7341. if (_first_run) {
  7342. _first_date = data[0].startdate.getMonth();
  7343. }
  7344. int_obj.date.setMonth(_first_date + inc_time);
  7345. } else if (_interval.type == "week") {
  7346. if (_first_run) {
  7347. _first_date = data[0].startdate.getMonth();
  7348. }
  7349. int_obj.date.setMonth(data[0].startdate.getMonth());
  7350. int_obj.date.setDate(_first_date + (inc_time * 7) );
  7351. } else if (_interval.type == "day") {
  7352. if (_first_run) {
  7353. _first_date = data[0].startdate.getDate();
  7354. }
  7355. int_obj.date.setMonth(data[0].startdate.getMonth());
  7356. int_obj.date.setDate(_first_date + inc_time);
  7357. } else if (_interval.type == "hour") {
  7358. if (_first_run) {
  7359. _first_date = data[0].startdate.getHours();
  7360. }
  7361. int_obj.date.setMonth(data[0].startdate.getMonth());
  7362. int_obj.date.setDate(data[0].startdate.getDate());
  7363. int_obj.date.setHours(_first_date + inc_time);
  7364. } else if (_interval.type == "minute") {
  7365. if (_first_run) {
  7366. _first_date = data[0].startdate.getMinutes();
  7367. }
  7368. int_obj.date.setMonth(data[0].startdate.getMonth());
  7369. int_obj.date.setDate(data[0].startdate.getDate());
  7370. int_obj.date.setHours(data[0].startdate.getHours());
  7371. int_obj.date.setMinutes(_first_date + inc_time);
  7372. } else if (_interval.type == "second") {
  7373. if (_first_run) {
  7374. _first_date = data[0].startdate.getSeconds();
  7375. }
  7376. int_obj.date.setMonth(data[0].startdate.getMonth());
  7377. int_obj.date.setDate(data[0].startdate.getDate());
  7378. int_obj.date.setHours(data[0].startdate.getHours());
  7379. int_obj.date.setMinutes(data[0].startdate.getMinutes());
  7380. int_obj.date.setSeconds(_first_date + inc_time);
  7381. } else if (_interval.type == "millisecond") {
  7382. if (_first_run) {
  7383. _first_date = data[0].startdate.getMilliseconds();
  7384. }
  7385. int_obj.date.setMonth(data[0].startdate.getMonth());
  7386. int_obj.date.setDate(data[0].startdate.getDate());
  7387. int_obj.date.setHours(data[0].startdate.getHours());
  7388. int_obj.date.setMinutes(data[0].startdate.getMinutes());
  7389. int_obj.date.setSeconds(data[0].startdate.getSeconds());
  7390. int_obj.date.setMilliseconds(_first_date + inc_time);
  7391. }
  7392. // FIX WEIRD FIREFOX BUG FOR GMT TIME FORMATTING
  7393. if (VMM.Browser.browser == "Firefox") {
  7394. if (int_obj.date.getFullYear() == "1970" && int_obj.date.getTimezoneOffset() != _timezone_offset) {
  7395. trace("FIREFOX 1970 TIMEZONE OFFSET " + int_obj.date.getTimezoneOffset() + " SHOULD BE " + _timezone_offset);
  7396. trace(_interval.type + " " + _interval.date);
  7397. // try and fix firefox bug, if not the flag will catch it
  7398. firefox.offset = (int_obj.date.getTimezoneOffset()/60);
  7399. firefox.flag = true;
  7400. int_obj.date.setHours(int_obj.date.getHours() + firefox.offset );
  7401. } else if (firefox.flag) {
  7402. // catch the bug the second time around
  7403. firefox.flag = false;
  7404. int_obj.date.setHours(int_obj.date.getHours() + firefox.offset );
  7405. if (_is_year) {
  7406. firefox.flag = true;
  7407. }
  7408. }
  7409. }
  7410. if (_is_year) {
  7411. if ( int_obj.date.getFullYear() < 0 ) {
  7412. int_obj.date_string = Math.abs( int_obj.date.getFullYear() ).toString() + " B.C.";
  7413. } else {
  7414. int_obj.date_string = int_obj.date.getFullYear();
  7415. }
  7416. } else {
  7417. int_obj.date_string = VMM.Date.prettyDate(int_obj.date, true);
  7418. }
  7419. // Increment Time
  7420. inc_time = inc_time + 1;
  7421. // No longer first run
  7422. _first_run = false;
  7423. int_obj.relative_pos = positionRelative(interval, int_obj.date);
  7424. _last_pos = int_obj.relative_pos.begin;
  7425. if (int_obj.relative_pos.begin > _largest_pos) {
  7426. _largest_pos = int_obj.relative_pos.begin;
  7427. }
  7428. // Add the time string to the element and position it.
  7429. VMM.appendElement(int_obj.element, int_obj.date_string);
  7430. VMM.Lib.css(int_obj.element, "text-indent", -(VMM.Lib.width(int_obj.element)/2));
  7431. VMM.Lib.css(int_obj.element, "opacity", "0");
  7432. // add the interval element to the array
  7433. _array.push(int_obj);
  7434. }
  7435. VMM.Lib.width($timeintervalminor_minor, _largest_pos);
  7436. positionInterval(_element_parent, _array);
  7437. }
  7438. /* BUILD
  7439. ================================================== */
  7440. function build() {
  7441. var i = 0,
  7442. j = 0;
  7443. VMM.attachElement(layout, "");
  7444. $timenav = VMM.appendAndGetElement(layout, "<div>", "timenav");
  7445. $content = VMM.appendAndGetElement($timenav, "<div>", "content");
  7446. $time = VMM.appendAndGetElement($timenav, "<div>", "time");
  7447. $timeintervalminor = VMM.appendAndGetElement($time, "<div>", "time-interval-minor");
  7448. $timeintervalminor_minor = VMM.appendAndGetElement($timeintervalminor, "<div>", "minor");
  7449. $timeintervalmajor = VMM.appendAndGetElement($time, "<div>", "time-interval-major");
  7450. $timeinterval = VMM.appendAndGetElement($time, "<div>", "time-interval");
  7451. $timebackground = VMM.appendAndGetElement(layout, "<div>", "timenav-background");
  7452. $timenavline = VMM.appendAndGetElement($timebackground, "<div>", "timenav-line");
  7453. $timenavindicator = VMM.appendAndGetElement($timebackground, "<div>", "timenav-indicator");
  7454. $timeintervalbackground = VMM.appendAndGetElement($timebackground, "<div>", "timenav-interval-background", "<div class='top-highlight'></div>");
  7455. $toolbar = VMM.appendAndGetElement(layout, "<div>", "vco-toolbar");
  7456. buildInterval();
  7457. buildMarkers();
  7458. buildEras();
  7459. calculateMultiplier();
  7460. positionMarkers(false);
  7461. positionEras();
  7462. positionInterval($timeinterval, interval_array, false, true);
  7463. positionInterval($timeintervalmajor, interval_major_array);
  7464. if (config.start_page) {
  7465. $backhome = VMM.appendAndGetElement($toolbar, "<div>", "back-home", "<div class='icon'></div>");
  7466. VMM.bindEvent(".back-home", onBackHome, "click");
  7467. VMM.Lib.attribute($backhome, "title", VMM.master_config.language.messages.return_to_title);
  7468. VMM.Lib.attribute($backhome, "rel", "timeline-tooltip");
  7469. }
  7470. // MAKE TIMELINE DRAGGABLE/TOUCHABLE
  7471. $dragslide = new VMM.DragSlider;
  7472. $dragslide.createPanel(layout, $timenav, config.nav.constraint, config.touch);
  7473. if (config.touch && config.start_page) {
  7474. VMM.Lib.addClass($toolbar, "touch");
  7475. VMM.Lib.css($toolbar, "top", 55);
  7476. VMM.Lib.css($toolbar, "left", 10);
  7477. } else {
  7478. if (config.start_page) {
  7479. VMM.Lib.css($toolbar, "top", 27);
  7480. }
  7481. $zoomin = VMM.appendAndGetElement($toolbar, "<div>", "zoom-in", "<div class='icon'></div>");
  7482. $zoomout = VMM.appendAndGetElement($toolbar, "<div>", "zoom-out", "<div class='icon'></div>");
  7483. // ZOOM EVENTS
  7484. VMM.bindEvent($zoomin, onZoomIn, "click");
  7485. VMM.bindEvent($zoomout, onZoomOut, "click");
  7486. // TOOLTIP
  7487. VMM.Lib.attribute($zoomin, "title", VMM.master_config.language.messages.expand_timeline);
  7488. VMM.Lib.attribute($zoomin, "rel", "timeline-tooltip");
  7489. VMM.Lib.attribute($zoomout, "title", VMM.master_config.language.messages.contract_timeline);
  7490. VMM.Lib.attribute($zoomout, "rel", "timeline-tooltip");
  7491. $toolbar.tooltip({selector: "div[rel=timeline-tooltip]", placement: "right"});
  7492. // MOUSE EVENTS
  7493. VMM.bindEvent(layout, onMouseScroll, 'DOMMouseScroll');
  7494. VMM.bindEvent(layout, onMouseScroll, 'mousewheel');
  7495. }
  7496. // USER CONFIGURABLE ADJUSTMENT TO DEFAULT ZOOM
  7497. if (config.nav.zoom.adjust != 0) {
  7498. if (config.nav.zoom.adjust < 0) {
  7499. for(i = 0; i < Math.abs(config.nav.zoom.adjust); i++) {
  7500. onZoomOut();
  7501. }
  7502. } else {
  7503. for(j = 0; j < config.nav.zoom.adjust; j++) {
  7504. onZoomIn();
  7505. }
  7506. }
  7507. }
  7508. //VMM.fireEvent(layout, "LOADED");
  7509. _active = true;
  7510. reSize(true);
  7511. VMM.fireEvent(layout, "LOADED");
  7512. };
  7513. function buildInterval() {
  7514. var i = 0,
  7515. j = 0;
  7516. // CALCULATE INTERVAL
  7517. timespan = getDateFractions((data[data.length - 1].enddate) - (data[0].startdate), true);
  7518. trace(timespan);
  7519. calculateInterval();
  7520. /* DETERMINE DEFAULT INTERVAL TYPE
  7521. millenium, ages, epoch, era and eon are not optimized yet. They may never be.
  7522. ================================================== */
  7523. /*
  7524. if (timespan.eons > data.length / config.nav.density) {
  7525. interval = interval_calc.eon;
  7526. interval_major = interval_calc.eon;
  7527. interval_macro = interval_calc.era;
  7528. } else if (timespan.eras > data.length / config.nav.density) {
  7529. interval = interval_calc.era;
  7530. interval_major = interval_calc.eon;
  7531. interval_macro = interval_calc.epoch;
  7532. } else if (timespan.epochs > data.length / config.nav.density) {
  7533. interval = interval_calc.epoch;
  7534. interval_major = interval_calc.era;
  7535. interval_macro = interval_calc.age;
  7536. } else if (timespan.ages > data.length / config.nav.density) {
  7537. interval = interval_calc.ages;
  7538. interval_major = interval_calc.epoch;
  7539. interval_macro = interval_calc.millenium;
  7540. } else if (timespan.milleniums > data.length / config.nav.density) {
  7541. interval = interval_calc.millenium;
  7542. interval_major = interval_calc.age;
  7543. interval_macro = interval_calc.century;
  7544. } else
  7545. */
  7546. if (timespan.centuries > data.length / config.nav.density) {
  7547. interval = interval_calc.century;
  7548. interval_major = interval_calc.millenium;
  7549. interval_macro = interval_calc.decade;
  7550. } else if (timespan.decades > data.length / config.nav.density) {
  7551. interval = interval_calc.decade;
  7552. interval_major = interval_calc.century;
  7553. interval_macro = interval_calc.year;
  7554. } else if (timespan.years > data.length / config.nav.density) {
  7555. interval = interval_calc.year;
  7556. interval_major = interval_calc.decade;
  7557. interval_macro = interval_calc.month;
  7558. } else if (timespan.months > data.length / config.nav.density) {
  7559. interval = interval_calc.month;
  7560. interval_major = interval_calc.year;
  7561. interval_macro = interval_calc.day;
  7562. } else if (timespan.days > data.length / config.nav.density) {
  7563. interval = interval_calc.day;
  7564. interval_major = interval_calc.month;
  7565. interval_macro = interval_calc.hour;
  7566. } else if (timespan.hours > data.length / config.nav.density) {
  7567. interval = interval_calc.hour;
  7568. interval_major = interval_calc.day;
  7569. interval_macro = interval_calc.minute;
  7570. } else if (timespan.minutes > data.length / config.nav.density) {
  7571. interval = interval_calc.minute;
  7572. interval_major = interval_calc.hour;
  7573. interval_macro = interval_calc.second;
  7574. } else if (timespan.seconds > data.length / config.nav.density) {
  7575. interval = interval_calc.second;
  7576. interval_major = interval_calc.minute;
  7577. interval_macro = interval_calc.second;
  7578. } else {
  7579. trace("NO IDEA WHAT THE TYPE SHOULD BE");
  7580. interval = interval_calc.day;
  7581. interval_major = interval_calc.month;
  7582. interval_macro = interval_calc.hour;
  7583. }
  7584. trace("INTERVAL TYPE: " + interval.type);
  7585. trace("INTERVAL MAJOR TYPE: " + interval_major.type);
  7586. createIntervalElements(interval, interval_array, $timeinterval);
  7587. createIntervalElements(interval_major, interval_major_array, $timeintervalmajor);
  7588. // Cleanup duplicate interval elements between normal and major
  7589. for(i = 0; i < interval_array.length; i++) {
  7590. for(j = 0; j < interval_major_array.length; j++) {
  7591. if (interval_array[i].date_string == interval_major_array[j].date_string) {
  7592. VMM.attachElement(interval_array[i].element, "");
  7593. }
  7594. }
  7595. }
  7596. }
  7597. function buildMarkers() {
  7598. var row = 2,
  7599. lpos = 0,
  7600. row_depth = 0,
  7601. i = 0,
  7602. k = 0,
  7603. l = 0;
  7604. markers = [];
  7605. era_markers = [];
  7606. for(i = 0; i < data.length; i++) {
  7607. var _marker,
  7608. _marker_flag,
  7609. _marker_content,
  7610. _marker_dot,
  7611. _marker_line,
  7612. _marker_line_event,
  7613. _marker_obj,
  7614. _marker_title = "",
  7615. has_title = false;
  7616. _marker = VMM.appendAndGetElement($content, "<div>", "marker");
  7617. _marker_flag = VMM.appendAndGetElement(_marker, "<div>", "flag");
  7618. _marker_content = VMM.appendAndGetElement(_marker_flag, "<div>", "flag-content");
  7619. _marker_dot = VMM.appendAndGetElement(_marker, "<div>", "dot");
  7620. _marker_line = VMM.appendAndGetElement(_marker, "<div>", "line");
  7621. _marker_line_event = VMM.appendAndGetElement(_marker_line, "<div>", "event-line");
  7622. _marker_relative_pos = positionRelative(interval, data[i].startdate, data[i].enddate);
  7623. _marker_thumb = "";
  7624. // THUMBNAIL
  7625. if (data[i].asset != null && data[i].asset != "") {
  7626. VMM.appendElement(_marker_content, VMM.MediaElement.thumbnail(data[i].asset, 24, 24, data[i].uniqueid));
  7627. } else {
  7628. VMM.appendElement(_marker_content, "<div style='margin-right:7px;height:50px;width:2px;float:left;'></div>");
  7629. }
  7630. // ADD DATE AND TITLE
  7631. if (data[i].title == "" || data[i].title == " " ) {
  7632. trace("TITLE NOTHING")
  7633. if (typeof data[i].slug != 'undefined' && data[i].slug != "") {
  7634. trace("SLUG")
  7635. _marker_title = VMM.Util.untagify(data[i].slug);
  7636. has_title = true;
  7637. } else {
  7638. var m = VMM.MediaType(data[i].asset.media);
  7639. if (m.type == "quote" || m.type == "unknown") {
  7640. _marker_title = VMM.Util.untagify(m.id);
  7641. has_title = true;
  7642. } else {
  7643. has_title = false;
  7644. }
  7645. }
  7646. } else if (data[i].title != "" || data[i].title != " ") {
  7647. trace(data[i].title)
  7648. _marker_title = VMM.Util.untagify(data[i].title);
  7649. has_title = true;
  7650. } else {
  7651. trace("TITLE SLUG NOT FOUND " + data[i].slug)
  7652. }
  7653. if (has_title) {
  7654. VMM.appendElement(_marker_content, "<h3>" + _marker_title + "</h3>");
  7655. } else {
  7656. VMM.appendElement(_marker_content, "<h3>" + _marker_title + "</h3>");
  7657. VMM.appendElement(_marker_content, "<h3 id='marker_content_" + data[i].uniqueid + "'>" + _marker_title + "</h3>");
  7658. }
  7659. // ADD ID
  7660. VMM.Lib.attr(_marker, "id", ( "marker_" + data[i].uniqueid).toString() );
  7661. // MARKER CLICK
  7662. VMM.bindEvent(_marker_flag, onMarkerClick, "", {number: i});
  7663. VMM.bindEvent(_marker_flag, onMarkerHover, "mouseenter mouseleave", {number: i, elem:_marker_flag});
  7664. _marker_obj = {
  7665. marker: _marker,
  7666. flag: _marker_flag,
  7667. lineevent: _marker_line_event,
  7668. type: "marker",
  7669. full: true,
  7670. relative_pos: _marker_relative_pos,
  7671. tag: data[i].tag,
  7672. pos_left: 0
  7673. };
  7674. if (data[i].type == "start") {
  7675. trace("BUILD MARKER HAS START PAGE");
  7676. config.start_page = true;
  7677. _marker_obj.type = "start";
  7678. }
  7679. if (data[i].type == "storify") {
  7680. _marker_obj.type = "storify";
  7681. }
  7682. if (data[i].tag) {
  7683. tags.push(data[i].tag);
  7684. }
  7685. markers.push(_marker_obj);
  7686. }
  7687. // CREATE TAGS
  7688. tags = VMM.Util.deDupeArray(tags);
  7689. if (tags.length > 3) {
  7690. config.nav.rows.current = config.nav.rows.half;
  7691. } else {
  7692. config.nav.rows.current = config.nav.rows.full;
  7693. }
  7694. for(k = 0; k < tags.length; k++) {
  7695. if (k < config.nav.rows.current.length) {
  7696. var tag_element = VMM.appendAndGetElement($timebackground, "<div>", "timenav-tag");
  7697. VMM.Lib.addClass(tag_element, "timenav-tag-row-" + (k+1));
  7698. if (tags.length > 3) {
  7699. VMM.Lib.addClass(tag_element, "timenav-tag-size-half");
  7700. } else {
  7701. VMM.Lib.addClass(tag_element, "timenav-tag-size-full");
  7702. }
  7703. VMM.appendElement(tag_element, "<div><h3>" + tags[k] + "</h3></div>");
  7704. }
  7705. }
  7706. // RESIZE FLAGS IF NEEDED
  7707. if (tags.length > 3) {
  7708. for(l = 0; l < markers.length; l++) {
  7709. VMM.Lib.addClass(markers[l].flag, "flag-small");
  7710. markers[l].full = false;
  7711. }
  7712. }
  7713. }
  7714. function buildEras() {
  7715. var number_of_colors = 6,
  7716. current_color = 0,
  7717. j = 0;
  7718. // CREATE ERAS
  7719. for(j = 0; j < eras.length; j++) {
  7720. var era = {
  7721. content: VMM.appendAndGetElement($content, "<div>", "era"),
  7722. text_content: VMM.appendAndGetElement($timeinterval, "<div>", "era"),
  7723. startdate: VMM.Date.parse(eras[j].startDate),
  7724. enddate: VMM.Date.parse(eras[j].endDate),
  7725. title: eras[j].headline,
  7726. uniqueid: VMM.Util.unique_ID(6),
  7727. tag: "",
  7728. relative_pos: ""
  7729. },
  7730. st = VMM.Date.prettyDate(era.startdate),
  7731. en = VMM.Date.prettyDate(era.enddate),
  7732. era_text = "<div>&nbsp;</div>";
  7733. if (typeof eras[j].tag != "undefined") {
  7734. era.tag = eras[j].tag;
  7735. }
  7736. era.relative_pos = positionRelative(interval, era.startdate, era.enddate);
  7737. VMM.Lib.attr(era.content, "id", era.uniqueid);
  7738. VMM.Lib.attr(era.text_content, "id", era.uniqueid + "_text");
  7739. // Background Color
  7740. VMM.Lib.addClass(era.content, "era"+(current_color+1));
  7741. VMM.Lib.addClass(era.text_content, "era"+(current_color+1));
  7742. if (current_color < number_of_colors) {
  7743. current_color++;
  7744. } else {
  7745. current_color = 0;
  7746. }
  7747. VMM.appendElement(era.content, era_text);
  7748. VMM.appendElement(era.text_content, VMM.Util.unlinkify(era.title));
  7749. era_markers.push(era);
  7750. }
  7751. }
  7752. };
  7753. }
  7754. /* **********************************************
  7755. Begin VMM.Timeline.DataObj.js
  7756. ********************************************** */
  7757. /* VMM.Timeline.DataObj.js
  7758. TIMELINE SOURCE DATA PROCESSOR
  7759. ================================================== */
  7760. if (typeof VMM.Timeline !== 'undefined' && typeof VMM.Timeline.DataObj == 'undefined') {
  7761. VMM.Timeline.DataObj = {
  7762. data_obj: {},
  7763. model_array: [],
  7764. getData: function (raw_data) {
  7765. VMM.Timeline.DataObj.data_obj = {};
  7766. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, VMM.Timeline.Config.language.messages.loading_timeline);
  7767. if (type.of(raw_data) == "object") {
  7768. trace("DATA SOURCE: JSON OBJECT");
  7769. VMM.Timeline.DataObj.parseJSON(raw_data);
  7770. } else if (type.of(raw_data) == "string") {
  7771. if (raw_data.match("%23")) {
  7772. trace("DATA SOURCE: TWITTER SEARCH");
  7773. VMM.Timeline.DataObj.model.tweets.getData("%23medill");
  7774. } else if ( raw_data.match("spreadsheet") ) {
  7775. trace("DATA SOURCE: GOOGLE SPREADSHEET");
  7776. VMM.Timeline.DataObj.model.googlespreadsheet.getData(raw_data);
  7777. } else if (raw_data.match("storify.com")) {
  7778. trace("DATA SOURCE: STORIFY");
  7779. VMM.Timeline.DataObj.model.storify.getData(raw_data);
  7780. //http://api.storify.com/v1/stories/number10gov/g8-and-nato-chicago-summit
  7781. } else if (raw_data.match("\.jsonp")) {
  7782. trace("DATA SOURCE: JSONP");
  7783. LoadLib.js(raw_data, VMM.Timeline.DataObj.onJSONPLoaded);
  7784. } else {
  7785. trace("DATA SOURCE: JSON");
  7786. var req = "";
  7787. if (raw_data.indexOf("?") > -1) {
  7788. req = raw_data + "&callback=onJSONP_Data";
  7789. } else {
  7790. req = raw_data + "?callback=onJSONP_Data";
  7791. }
  7792. VMM.getJSON(req, VMM.Timeline.DataObj.parseJSON);
  7793. }
  7794. } else if (type.of(raw_data) == "html") {
  7795. trace("DATA SOURCE: HTML");
  7796. VMM.Timeline.DataObj.parseHTML(raw_data);
  7797. } else {
  7798. trace("DATA SOURCE: UNKNOWN");
  7799. }
  7800. },
  7801. onJSONPLoaded: function() {
  7802. trace("JSONP IS LOADED");
  7803. VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, storyjs_jsonp_data);
  7804. },
  7805. parseHTML: function (d) {
  7806. trace("parseHTML");
  7807. trace("WARNING: THIS IS STILL ALPHA AND WILL NOT WORK WITH ID's other than #timeline");
  7808. var _data_obj = VMM.Timeline.DataObj.data_template_obj;
  7809. /* Timeline start slide
  7810. ================================================== */
  7811. if (VMM.Lib.find("#timeline section", "time")[0]) {
  7812. _data_obj.timeline.startDate = VMM.Lib.html(VMM.Lib.find("#timeline section", "time")[0]);
  7813. _data_obj.timeline.headline = VMM.Lib.html(VMM.Lib.find("#timeline section", "h2"));
  7814. _data_obj.timeline.text = VMM.Lib.html(VMM.Lib.find("#timeline section", "article"));
  7815. var found_main_media = false;
  7816. if (VMM.Lib.find("#timeline section", "figure img").length != 0) {
  7817. found_main_media = true;
  7818. _data_obj.timeline.asset.media = VMM.Lib.attr(VMM.Lib.find("#timeline section", "figure img"), "src");
  7819. } else if (VMM.Lib.find("#timeline section", "figure a").length != 0) {
  7820. found_main_media = true;
  7821. _data_obj.timeline.asset.media = VMM.Lib.attr(VMM.Lib.find("#timeline section", "figure a"), "href");
  7822. } else {
  7823. //trace("NOT FOUND");
  7824. }
  7825. if (found_main_media) {
  7826. if (VMM.Lib.find("#timeline section", "cite").length != 0) {
  7827. _data_obj.timeline.asset.credit = VMM.Lib.html(VMM.Lib.find("#timeline section", "cite"));
  7828. }
  7829. if (VMM.Lib.find(this, "figcaption").length != 0) {
  7830. _data_obj.timeline.asset.caption = VMM.Lib.html(VMM.Lib.find("#timeline section", "figcaption"));
  7831. }
  7832. }
  7833. }
  7834. /* Timeline Date Slides
  7835. ================================================== */
  7836. VMM.Lib.each("#timeline li", function(i, elem){
  7837. var valid_date = false;
  7838. var _date = {
  7839. "type":"default",
  7840. "startDate":"",
  7841. "headline":"",
  7842. "text":"",
  7843. "asset":
  7844. {
  7845. "media":"",
  7846. "credit":"",
  7847. "caption":""
  7848. },
  7849. "tags":"Optional"
  7850. };
  7851. if (VMM.Lib.find(this, "time") != 0) {
  7852. valid_date = true;
  7853. _date.startDate = VMM.Lib.html(VMM.Lib.find(this, "time")[0]);
  7854. if (VMM.Lib.find(this, "time")[1]) {
  7855. _date.endDate = VMM.Lib.html(VMM.Lib.find(this, "time")[1]);
  7856. }
  7857. _date.headline = VMM.Lib.html(VMM.Lib.find(this, "h3"));
  7858. _date.text = VMM.Lib.html(VMM.Lib.find(this, "article"));
  7859. var found_media = false;
  7860. if (VMM.Lib.find(this, "figure img").length != 0) {
  7861. found_media = true;
  7862. _date.asset.media = VMM.Lib.attr(VMM.Lib.find(this, "figure img"), "src");
  7863. } else if (VMM.Lib.find(this, "figure a").length != 0) {
  7864. found_media = true;
  7865. _date.asset.media = VMM.Lib.attr(VMM.Lib.find(this, "figure a"), "href");
  7866. } else {
  7867. //trace("NOT FOUND");
  7868. }
  7869. if (found_media) {
  7870. if (VMM.Lib.find(this, "cite").length != 0) {
  7871. _date.asset.credit = VMM.Lib.html(VMM.Lib.find(this, "cite"));
  7872. }
  7873. if (VMM.Lib.find(this, "figcaption").length != 0) {
  7874. _date.asset.caption = VMM.Lib.html(VMM.Lib.find(this, "figcaption"));
  7875. }
  7876. }
  7877. trace(_date);
  7878. _data_obj.timeline.date.push(_date);
  7879. }
  7880. });
  7881. VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, _data_obj);
  7882. },
  7883. parseJSON: function(d) {
  7884. trace("parseJSON");
  7885. if (d.timeline.type == "default") {
  7886. trace("DATA SOURCE: JSON STANDARD TIMELINE");
  7887. VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, d);
  7888. } else if (d.timeline.type == "twitter") {
  7889. trace("DATA SOURCE: JSON TWEETS");
  7890. VMM.Timeline.DataObj.model_Tweets.buildData(d);
  7891. } else {
  7892. trace("DATA SOURCE: UNKNOWN JSON");
  7893. trace(type.of(d.timeline));
  7894. };
  7895. },
  7896. /* MODEL OBJECTS
  7897. New Types of Data can be formatted for the timeline here
  7898. ================================================== */
  7899. model: {
  7900. googlespreadsheet: {
  7901. extractSpreadsheetKey: function(url) {
  7902. var key = VMM.Util.getUrlVars(url)["key"];
  7903. if (!key) {
  7904. if (url.match("docs.google.com/spreadsheets/d/")) {
  7905. var pos = url.indexOf("docs.google.com/spreadsheets/d/") + "docs.google.com/spreadsheets/d/".length;
  7906. var tail = url.substr(pos);
  7907. key = tail.split('/')[0]
  7908. }
  7909. }
  7910. if (!key) { key = url}
  7911. return key;
  7912. },
  7913. getData: function(raw) {
  7914. var getjsondata, key, worksheet, url, timeout, tries = 0;
  7915. // new Google Docs URLs can specify 'key' differently.
  7916. // that format doesn't seem to have a way to specify a worksheet.
  7917. key = VMM.Timeline.DataObj.model.googlespreadsheet.extractSpreadsheetKey(raw);
  7918. worksheet = VMM.Util.getUrlVars(raw)["worksheet"];
  7919. if (typeof worksheet == "undefined") worksheet = "od6";
  7920. url = "https://spreadsheets.google.com/feeds/list/" + key + "/" + worksheet + "/public/values?alt=json";
  7921. timeout = setTimeout(function() {
  7922. trace("Google Docs timeout " + url);
  7923. trace(url);
  7924. if (tries < 3) {
  7925. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Still waiting on Google Docs, trying again " + tries);
  7926. tries ++;
  7927. getjsondata.abort()
  7928. requestJsonData();
  7929. } else {
  7930. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Google Docs is not responding");
  7931. }
  7932. }, 16000);
  7933. function requestJsonData() {
  7934. getjsondata = VMM.getJSON(url, function(d) {
  7935. clearTimeout(timeout);
  7936. VMM.Timeline.DataObj.model.googlespreadsheet.buildData(d);
  7937. })
  7938. .error(function(jqXHR, textStatus, errorThrown) {
  7939. if (jqXHR.status == 400) {
  7940. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Error reading Google spreadsheet. Check the URL and make sure it's published to the web.");
  7941. clearTimeout(timeout);
  7942. return;
  7943. }
  7944. trace("Google Docs ERROR");
  7945. trace("Google Docs ERROR: " + textStatus + " " + jqXHR.responseText);
  7946. })
  7947. .success(function(d) {
  7948. clearTimeout(timeout);
  7949. });
  7950. }
  7951. requestJsonData();
  7952. },
  7953. buildData: function(d) {
  7954. var data_obj = VMM.Timeline.DataObj.data_template_obj,
  7955. is_valid = false;
  7956. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Parsing Google Doc Data");
  7957. function getGVar(v) {
  7958. if (typeof v != 'undefined') {
  7959. return v.$t;
  7960. } else {
  7961. return "";
  7962. }
  7963. }
  7964. if (typeof d.feed.entry == 'undefined') {
  7965. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Error parsing spreadsheet. Make sure you have no blank rows and that the headers have not been changed.");
  7966. } else {
  7967. is_valid = true;
  7968. for(var i = 0; i < d.feed.entry.length; i++) {
  7969. var dd = d.feed.entry[i],
  7970. dd_type = "";
  7971. if (typeof(dd.gsx$startdate) == 'undefined') {
  7972. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Missing start date. Make sure the headers of your Google Spreadsheet have not been changed.");
  7973. return;
  7974. }
  7975. if (typeof dd.gsx$type != 'undefined') {
  7976. dd_type = dd.gsx$type.$t;
  7977. } else if (typeof dd.gsx$titleslide != 'undefined') {
  7978. dd_type = dd.gsx$titleslide.$t;
  7979. }
  7980. if (dd_type.match("start") || dd_type.match("title") ) {
  7981. data_obj.timeline.startDate = getGVar(dd.gsx$startdate);
  7982. data_obj.timeline.headline = getGVar(dd.gsx$headline);
  7983. data_obj.timeline.asset.media = getGVar(dd.gsx$media);
  7984. data_obj.timeline.asset.caption = getGVar(dd.gsx$mediacaption);
  7985. data_obj.timeline.asset.credit = getGVar(dd.gsx$mediacredit);
  7986. data_obj.timeline.text = getGVar(dd.gsx$text);
  7987. data_obj.timeline.type = "google spreadsheet";
  7988. } else if (dd_type.match("era")) {
  7989. var era = {
  7990. startDate: getGVar(dd.gsx$startdate),
  7991. endDate: getGVar(dd.gsx$enddate),
  7992. headline: getGVar(dd.gsx$headline),
  7993. text: getGVar(dd.gsx$text),
  7994. tag: getGVar(dd.gsx$tag)
  7995. }
  7996. data_obj.timeline.era.push(era);
  7997. } else {
  7998. var date = {
  7999. type: "google spreadsheet",
  8000. startDate: getGVar(dd.gsx$startdate),
  8001. endDate: getGVar(dd.gsx$enddate),
  8002. headline: getGVar(dd.gsx$headline),
  8003. text: getGVar(dd.gsx$text),
  8004. tag: getGVar(dd.gsx$tag),
  8005. asset: {
  8006. media: getGVar(dd.gsx$media),
  8007. credit: getGVar(dd.gsx$mediacredit),
  8008. caption: getGVar(dd.gsx$mediacaption),
  8009. thumbnail: getGVar(dd.gsx$mediathumbnail)
  8010. }
  8011. };
  8012. data_obj.timeline.date.push(date);
  8013. }
  8014. };
  8015. }
  8016. if (is_valid) {
  8017. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Finished Parsing Data");
  8018. VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, data_obj);
  8019. } else {
  8020. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, VMM.Language.messages.loading + " Google Doc Data (cells)");
  8021. trace("There may be too many entries. Still trying to load data. Now trying to load cells to avoid Googles limitation on cells");
  8022. VMM.Timeline.DataObj.model.googlespreadsheet.getDataCells(d.feed.link[0].href);
  8023. }
  8024. },
  8025. getDataCells: function(raw) {
  8026. var getjsondata, key, url, timeout, tries = 0;
  8027. key = VMM.Timeline.DataObj.model.googlespreadsheet.extractSpreadsheetKey(raw);
  8028. url = "https://spreadsheets.google.com/feeds/cells/" + key + "/od6/public/values?alt=json";
  8029. timeout = setTimeout(function() {
  8030. trace("Google Docs timeout " + url);
  8031. trace(url);
  8032. if (tries < 3) {
  8033. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Still waiting on Google Docs, trying again " + tries);
  8034. tries ++;
  8035. getjsondata.abort()
  8036. requestJsonData();
  8037. } else {
  8038. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Google Docs is not responding");
  8039. }
  8040. }, 16000);
  8041. function requestJsonData() {
  8042. getjsondata = VMM.getJSON(url, function(d) {
  8043. clearTimeout(timeout);
  8044. VMM.Timeline.DataObj.model.googlespreadsheet.buildDataCells(d);
  8045. })
  8046. .error(function(jqXHR, textStatus, errorThrown) {
  8047. trace("Google Docs ERROR");
  8048. trace("Google Docs ERROR: " + textStatus + " " + jqXHR.responseText);
  8049. })
  8050. .success(function(d) {
  8051. clearTimeout(timeout);
  8052. });
  8053. }
  8054. requestJsonData();
  8055. },
  8056. buildDataCells: function(d) {
  8057. var data_obj = VMM.Timeline.DataObj.data_template_obj,
  8058. is_valid = false,
  8059. cellnames = ["timeline"],
  8060. list = [],
  8061. max_row = 0,
  8062. i = 0,
  8063. k = 0;
  8064. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, VMM.Language.messages.loading_timeline + " Parsing Google Doc Data (cells)");
  8065. function getGVar(v) {
  8066. if (typeof v != 'undefined') {
  8067. return v.$t;
  8068. } else {
  8069. return "";
  8070. }
  8071. }
  8072. if (typeof d.feed.entry != 'undefined') {
  8073. is_valid = true;
  8074. // DETERMINE NUMBER OF ROWS
  8075. for(i = 0; i < d.feed.entry.length; i++) {
  8076. var dd = d.feed.entry[i];
  8077. if (parseInt(dd.gs$cell.row) > max_row) {
  8078. max_row = parseInt(dd.gs$cell.row);
  8079. }
  8080. }
  8081. // CREATE OBJECT FOR EACH ROW
  8082. for(var i = 0; i < max_row + 1; i++) {
  8083. var date = {
  8084. type: "",
  8085. startDate: "",
  8086. endDate: "",
  8087. headline: "",
  8088. text: "",
  8089. tag: "",
  8090. asset: {
  8091. media: "",
  8092. credit: "",
  8093. caption: "",
  8094. thumbnail: ""
  8095. }
  8096. };
  8097. list.push(date);
  8098. }
  8099. // PREP GOOGLE DOC CELL DATA TO EVALUATE
  8100. for(i = 0; i < d.feed.entry.length; i++) {
  8101. var dd = d.feed.entry[i],
  8102. dd_type = "",
  8103. column_name = "",
  8104. cell = {
  8105. content: getGVar(dd.gs$cell),
  8106. col: dd.gs$cell.col,
  8107. row: dd.gs$cell.row,
  8108. name: ""
  8109. };
  8110. //trace(cell);
  8111. if (cell.row == 1) {
  8112. if (cell.content == "Start Date") {
  8113. column_name = "startDate";
  8114. } else if (cell.content == "End Date") {
  8115. column_name = "endDate";
  8116. } else if (cell.content == "Headline") {
  8117. column_name = "headline";
  8118. } else if (cell.content == "Text") {
  8119. column_name = "text";
  8120. } else if (cell.content == "Media") {
  8121. column_name = "media";
  8122. } else if (cell.content == "Media Credit") {
  8123. column_name = "credit";
  8124. } else if (cell.content == "Media Caption") {
  8125. column_name = "caption";
  8126. } else if (cell.content == "Media Thumbnail") {
  8127. column_name = "thumbnail";
  8128. } else if (cell.content == "Type") {
  8129. column_name = "type";
  8130. } else if (cell.content == "Tag") {
  8131. column_name = "tag";
  8132. }
  8133. cellnames.push(column_name);
  8134. } else {
  8135. cell.name = cellnames[cell.col];
  8136. list[cell.row][cell.name] = cell.content;
  8137. }
  8138. };
  8139. for(i = 0; i < list.length; i++) {
  8140. var date = list[i];
  8141. if (date.type.match("start") || date.type.match("title") ) {
  8142. data_obj.timeline.startDate = date.startDate;
  8143. data_obj.timeline.headline = date.headline;
  8144. data_obj.timeline.asset.media = date.media;
  8145. data_obj.timeline.asset.caption = date.caption;
  8146. data_obj.timeline.asset.credit = date.credit;
  8147. data_obj.timeline.text = date.text;
  8148. data_obj.timeline.type = "google spreadsheet";
  8149. } else if (date.type.match("era")) {
  8150. var era = {
  8151. startDate: date.startDate,
  8152. endDate: date.endDate,
  8153. headline: date.headline,
  8154. text: date.text,
  8155. tag: date.tag
  8156. }
  8157. data_obj.timeline.era.push(era);
  8158. } else {
  8159. if (date.startDate) {
  8160. var date = {
  8161. type: "google spreadsheet",
  8162. startDate: date.startDate,
  8163. endDate: date.endDate,
  8164. headline: date.headline,
  8165. text: date.text,
  8166. tag: date.tag,
  8167. asset: {
  8168. media: date.media,
  8169. credit: date.credit,
  8170. caption: date.caption,
  8171. thumbnail: date.thumbnail
  8172. }
  8173. };
  8174. data_obj.timeline.date.push(date);
  8175. } else {
  8176. trace("Skipping item " + i + " in list: no start date.")
  8177. }
  8178. }
  8179. }
  8180. }
  8181. is_valid = data_obj.timeline.date.length > 0;
  8182. if (is_valid) {
  8183. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Finished Parsing Data");
  8184. VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, data_obj);
  8185. } else {
  8186. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Unable to load Google Doc data source. Make sure you have no blank rows and that the headers have not been changed.");
  8187. }
  8188. }
  8189. },
  8190. storify: {
  8191. getData: function(raw) {
  8192. var key, url, storify_timeout;
  8193. //http://storify.com/number10gov/g8-and-nato-chicago-summit
  8194. //http://api.storify.com/v1/stories/number10gov/g8-and-nato-chicago-summit
  8195. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Loading Storify...");
  8196. key = raw.split("storify.com\/")[1];
  8197. url = "//api.storify.com/v1/stories/" + key + "?per_page=300&callback=?";
  8198. storify_timeout = setTimeout(function() {
  8199. trace("STORIFY timeout");
  8200. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Storify is not responding");
  8201. }, 6000);
  8202. VMM.getJSON(url, VMM.Timeline.DataObj.model.storify.buildData)
  8203. .error(function(jqXHR, textStatus, errorThrown) {
  8204. trace("STORIFY error");
  8205. trace("STORIFY ERROR: " + textStatus + " " + jqXHR.responseText);
  8206. })
  8207. .success(function(d) {
  8208. clearTimeout(storify_timeout);
  8209. });
  8210. },
  8211. buildData: function(d) {
  8212. VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Parsing Data");
  8213. var _data_obj = VMM.Timeline.DataObj.data_template_obj;
  8214. _data_obj.timeline.startDate = new Date(d.content.date.created);;
  8215. _data_obj.timeline.headline = d.content.title;
  8216. trace(d);
  8217. //d.permalink
  8218. var tt = "";
  8219. var t_name = d.content.author.username;
  8220. var t_nickname = "";
  8221. if (typeof d.content.author.name != 'undefined') {
  8222. t_name = d.content.author.name;
  8223. t_nickname = d.content.author.username + "&nbsp;";
  8224. }
  8225. if (typeof d.content.description != 'undefined' && d.content.description != null) {
  8226. tt += d.content.description;
  8227. }
  8228. tt += "<div class='storify'>"
  8229. //tt += " <a href='" + d.content.permalink + "' target='_blank' alt='link to original story' title='link to original story'>" + "<span class='created-at'></span>" + " </a>";
  8230. tt += "<div class='vcard author'><a class='screen-name url' href='" + d.content.author.permalink + "' target='_blank'>";
  8231. tt += "<span class='avatar'><img src='" + d.content.author.avatar + "' style='max-width: 32px; max-height: 32px;'></span>"
  8232. tt += "<span class='fn'>" + t_name + "</span>";
  8233. tt += "<span class='nickname'>" + t_nickname + "<span class='thumbnail-inline'></span></span>";
  8234. tt += "</a>";
  8235. //tt += "<span class='nickname'>" + d.content.author.stats.stories + " Stories</span>";
  8236. //tt += "<span class='nickname'>" + d.content.author.stats.subscribers + " Subscribers</span>";
  8237. tt += "</div>"
  8238. tt += "</div>";
  8239. _data_obj.timeline.text = tt;
  8240. _data_obj.timeline.asset.media = d.content.thumbnail;
  8241. //_data_obj.timeline.asset.media = dd.gsx$media.$t;
  8242. //_data_obj.timeline.asset.caption = dd.gsx$mediacaption.$t;
  8243. //_data_obj.timeline.asset.credit = dd.gsx$mediacredit.$t;
  8244. _data_obj.timeline.type = "storify";
  8245. for(var i = 0; i < d.content.elements.length; i++) {
  8246. var dd = d.content.elements[i];
  8247. var is_text = false;
  8248. var d_date = new Date(dd.posted_at);
  8249. //trace(tempdat);
  8250. trace(dd.type);
  8251. //trace(dd);
  8252. var _date = {
  8253. "type": "storify",
  8254. "startDate": dd.posted_at,
  8255. "endDate": dd.posted_at,
  8256. "headline": " ",
  8257. "slug": "",
  8258. "text": "",
  8259. "asset": {
  8260. "media": "",
  8261. "credit": "",
  8262. "caption": ""
  8263. }
  8264. };
  8265. /* MEDIA
  8266. ================================================== */
  8267. if (dd.type == "image") {
  8268. if (typeof dd.source.name != 'undefined') {
  8269. if (dd.source.name == "flickr") {
  8270. _date.asset.media = "//flickr.com/photos/" + dd.meta.pathalias + "/" + dd.meta.id + "/";
  8271. _date.asset.credit = "<a href='" + _date.asset.media + "'>" + dd.attribution.name + "</a>";
  8272. _date.asset.credit += " on <a href='" + dd.source.href + "'>" + dd.source.name + "</a>";
  8273. } else if (dd.source.name == "instagram") {
  8274. _date.asset.media = dd.permalink;
  8275. _date.asset.credit = "<a href='" + dd.permalink + "'>" + dd.attribution.name + "</a>";
  8276. _date.asset.credit += " on <a href='" + dd.source.href + "'>" + dd.source.name + "</a>";
  8277. } else {
  8278. _date.asset.credit = "<a href='" + dd.permalink + "'>" + dd.attribution.name + "</a>";
  8279. if (typeof dd.source.href != 'undefined') {
  8280. _date.asset.credit += " on <a href='" + dd.source.href + "'>" + dd.source.name + "</a>";
  8281. }
  8282. _date.asset.media = dd.data.image.src;
  8283. }
  8284. } else {
  8285. _date.asset.credit = "<a href='" + dd.permalink + "'>" + dd.attribution.name + "</a>";
  8286. _date.asset.media = dd.data.image.src;
  8287. }
  8288. _date.slug = dd.attribution.name;
  8289. if (typeof dd.data.image.caption != 'undefined') {
  8290. if (dd.data.image.caption != 'undefined') {
  8291. _date.asset.caption = dd.data.image.caption;
  8292. _date.slug = dd.data.image.caption;
  8293. }
  8294. }
  8295. } else if (dd.type == "quote") {
  8296. if (dd.permalink.match("twitter")) {
  8297. _date.asset.media = dd.permalink;
  8298. _date.slug = VMM.Util.untagify(dd.data.quote.text);
  8299. } else if (dd.permalink.match("storify")) {
  8300. is_text = true;
  8301. _date.asset.media = "<blockquote>" + dd.data.quote.text.replace(/<\s*\/?\s*b\s*.*?>/g,"") + "</blockquote>";
  8302. }
  8303. } else if (dd.type == "link") {
  8304. _date.headline = dd.data.link.title;
  8305. _date.text = dd.data.link.description;
  8306. if (dd.data.link.thumbnail != 'undefined' && dd.data.link.thumbnail != '') {
  8307. _date.asset.media = dd.data.link.thumbnail;
  8308. } else {
  8309. _date.asset.media = dd.permalink;
  8310. }
  8311. //_date.asset.media = dd.permalink;
  8312. _date.asset.caption = "<a href='" + dd.permalink + "' target='_blank'>" + dd.data.link.title + "</a>"
  8313. _date.slug = dd.data.link.title;
  8314. } else if (dd.type == "text") {
  8315. if (dd.permalink.match("storify")) {
  8316. is_text = true;
  8317. var d_name = d.content.author.username;
  8318. var d_nickname = "";
  8319. if (typeof dd.attribution.name != 'undefined') {
  8320. t_name = dd.attribution.name;
  8321. t_nickname = dd.attribution.username + "&nbsp;";
  8322. }
  8323. var asset_text = "<div class='storify'>"
  8324. asset_text += "<blockquote><p>" + dd.data.text.replace(/<\s*\/?\s*b\s*.*?>/g,"") + "</p></blockquote>";
  8325. //asset_text += " <a href='" + dd.attribution.href + "' target='_blank' alt='link to author' title='link to author'>" + "<span class='created-at'></span>" + " </a>";
  8326. asset_text += "<div class='vcard author'><a class='screen-name url' href='" + dd.attribution.href + "' target='_blank'>";
  8327. asset_text += "<span class='avatar'><img src='" + dd.attribution.thumbnail + "' style='max-width: 32px; max-height: 32px;'></span>"
  8328. asset_text += "<span class='fn'>" + t_name + "</span>";
  8329. asset_text += "<span class='nickname'>" + t_nickname + "<span class='thumbnail-inline'></span></span>";
  8330. asset_text += "</a></div></div>";
  8331. _date.text = asset_text;
  8332. // Try and put it before the element where it is expected on storify
  8333. if ( (i+1) >= d.content.elements.length ) {
  8334. _date.startDate = d.content.elements[i-1].posted_at;
  8335. } else {
  8336. if (d.content.elements[i+1].type == "text" && d.content.elements[i+1].permalink.match("storify")) {
  8337. if ( (i+2) >= d.content.elements.length ) {
  8338. _date.startDate = d.content.elements[i-1].posted_at;
  8339. } else {
  8340. if (d.content.elements[i+2].type == "text" && d.content.elements[i+2].permalink.match("storify")) {
  8341. if ( (i+3) >= d.content.elements.length ) {
  8342. _date.startDate = d.content.elements[i-1].posted_at;
  8343. } else {
  8344. if (d.content.elements[i+3].type == "text" && d.content.elements[i+3].permalink.match("storify")) {
  8345. _date.startDate = d.content.elements[i-1].posted_at;
  8346. } else {
  8347. trace("LEVEL 3");
  8348. _date.startDate = d.content.elements[i+3].posted_at;
  8349. }
  8350. }
  8351. } else {
  8352. trace("LEVEL 2");
  8353. _date.startDate = d.content.elements[i+2].posted_at;
  8354. }
  8355. }
  8356. } else {
  8357. trace("LEVEL 1");
  8358. _date.startDate = d.content.elements[i+1].posted_at;
  8359. }
  8360. }
  8361. _date.endDate = _date.startDate
  8362. }
  8363. } else if (dd.type == "video") {
  8364. _date.headline = dd.data.video.title;
  8365. _date.asset.caption = dd.data.video.description;
  8366. _date.asset.caption = dd.source.username;
  8367. _date.asset.media = dd.data.video.src;
  8368. } else {
  8369. trace("NO MATCH ");
  8370. trace(dd);
  8371. }
  8372. if (is_text) {
  8373. _date.slug = VMM.Util.untagify(dd.data.text);
  8374. }
  8375. _data_obj.timeline.date.push(_date);
  8376. };
  8377. VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, _data_obj);
  8378. }
  8379. },
  8380. tweets: {
  8381. type: "twitter",
  8382. buildData: function(raw_data) {
  8383. VMM.bindEvent(global, VMM.Timeline.DataObj.model.tweets.onTwitterDataReady, "TWEETSLOADED");
  8384. VMM.ExternalAPI.twitter.getTweets(raw_data.timeline.tweets);
  8385. },
  8386. getData: function(raw_data) {
  8387. VMM.bindEvent(global, VMM.Timeline.DataObj.model.tweets.onTwitterDataReady, "TWEETSLOADED");
  8388. VMM.ExternalAPI.twitter.getTweetSearch(raw_data);
  8389. },
  8390. onTwitterDataReady: function(e, d) {
  8391. var _data_obj = VMM.Timeline.DataObj.data_template_obj;
  8392. for(var i = 0; i < d.tweetdata.length; i++) {
  8393. var _date = {
  8394. "type":"tweets",
  8395. "startDate":"",
  8396. "headline":"",
  8397. "text":"",
  8398. "asset":
  8399. {
  8400. "media":"",
  8401. "credit":"",
  8402. "caption":""
  8403. },
  8404. "tags":"Optional"
  8405. };
  8406. // pass in the 'created_at' string returned from twitter //
  8407. // stamp arrives formatted as Tue Apr 07 22:52:51 +0000 2009 //
  8408. //var twit_date = VMM.ExternalAPI.twitter.parseTwitterDate(d.tweetdata[i].raw.created_at);
  8409. //trace(twit_date);
  8410. _date.startDate = d.tweetdata[i].raw.created_at;
  8411. if (type.of(d.tweetdata[i].raw.from_user_name)) {
  8412. _date.headline = d.tweetdata[i].raw.from_user_name + " (<a href='https://twitter.com/" + d.tweetdata[i].raw.from_user + "'>" + "@" + d.tweetdata[i].raw.from_user + "</a>)" ;
  8413. } else {
  8414. _date.headline = d.tweetdata[i].raw.user.name + " (<a href='https://twitter.com/" + d.tweetdata[i].raw.user.screen_name + "'>" + "@" + d.tweetdata[i].raw.user.screen_name + "</a>)" ;
  8415. }
  8416. _date.asset.media = d.tweetdata[i].content;
  8417. _data_obj.timeline.date.push(_date);
  8418. };
  8419. VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, _data_obj);
  8420. }
  8421. }
  8422. },
  8423. /* TEMPLATE OBJECTS
  8424. ================================================== */
  8425. data_template_obj: { "timeline": { "headline":"", "description":"", "asset": { "media":"", "credit":"", "caption":"" }, "date": [], "era":[] } },
  8426. date_obj: {"startDate":"2012,2,2,11,30", "headline":"", "text":"", "asset": {"media":"http://youtu.be/vjVfu8-Wp6s", "credit":"", "caption":"" }, "tags":"Optional"}
  8427. };
  8428. }