From 0f3702d6548b5305d204796e4d1d6879b497d339 Mon Sep 17 00:00:00 2001 From: Zach Wise Date: Wed, 18 Jul 2012 15:21:52 -0500 Subject: [PATCH] Cleanup and merged with StoryJS core library --- source/js/Core/VMM.Library.js | 26 ++++++++++++ source/js/Core/VMM.Util.js | 54 +++++++++++++------------ source/js/Embed/Embed.js | 66 +++++++++++++------------------ source/js/VMM.Timeline.License.js | 1 + source/js/VMM.Timeline.TimeNav.js | 4 +- source/js/VMM.Timeline.js | 25 +++++------- 6 files changed, 95 insertions(+), 81 deletions(-) diff --git a/source/js/Core/VMM.Library.js b/source/js/Core/VMM.Library.js index 1d0e977..0b4935a 100644 --- a/source/js/Core/VMM.Library.js +++ b/source/js/Core/VMM.Library.js @@ -2,6 +2,32 @@ ================================================== */ if(typeof VMM != 'undefined') { + VMM.smoothScrollTo = function(elem, duration, ease) { + if( typeof( jQuery ) != 'undefined' ){ + var _ease = "easein", + _duration = 1000; + + if (duration != null) { + if (duration < 1) { + _duration = 1; + } else { + _duration = Math.round(duration); + } + + } + + if (ease != null && ease != "") { + _ease = ease; + } + + if (jQuery(window).scrollTop() != VMM.Lib.offset(elem).top) { + VMM.Lib.animate('html,body', _duration, _ease, {scrollTop: VMM.Lib.offset(elem).top}) + } + + } + + }; + VMM.attachElement = function(element, content) { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).html(content); diff --git a/source/js/Core/VMM.Util.js b/source/js/Core/VMM.Util.js index 38f6ad1..91c5c8a 100644 --- a/source/js/Core/VMM.Util.js +++ b/source/js/Core/VMM.Util.js @@ -25,6 +25,18 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') { }, + /* * MERGE CONFIG + ================================================== */ + mergeConfig: function(config_main, config_to_merge) { + var x; + for (x in config_to_merge) { + if (Object.prototype.hasOwnProperty.call(config_to_merge, x)) { + config_main[x] = config_to_merge[x]; + } + } + return config_main; + }, + /* * GET OBJECT ATTRIBUTE BY INDEX ================================================== */ getObjectAttributeByIndex: function(obj, index) { @@ -42,6 +54,13 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') { } }, + + /* * ORDINAL + ================================================== */ + ordinal: function(n) { + return ["th","st","nd","rd"][(!( ((n%10) >3) || (Math.floor(n%100/10)==1)) ) * (n%10)]; + }, + /* * RANDOM BETWEEN ================================================== */ //VMM.Util.randomBetween(1, 3) @@ -363,34 +382,19 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') { properQuotes: function(str) { return str.replace(/\"([^\"]*)\"/gi,"“$1”"); }, - /* * Given an int or decimal, return a string with pretty commas in the correct spot. + /* * Add Commas to numbers ================================================== */ - niceNumber: function(n){ - - var amount = String( Math.abs(Number(n) ) ); - - var leftOfDecimal = amount.split(/\./g)[0]; - var rightOfDecimal = amount.split(/\./g)[1]; - - var formatted_text = ''; - - var num_a = leftOfDecimal.toArray(); - num_a.reverse(); - - for (var i=1; i <= num_a.length; i++) { - if ( (i%3 == 0) && (i < num_a.length ) ) { - formatted_text = "," + num_a[i-1] + formatted_text; - } else { - formatted_text = num_a[i-1] + formatted_text; - } - } - if (rightOfDecimal != null && rightOfDecimal != '' && rightOfDecimal != undefined) { - return formatted_text + "." + rightOfDecimal; - } else { - return formatted_text; + niceNumber: function(nStr){ + nStr += ''; + x = nStr.split('.'); + x1 = x[0]; + x2 = x.length > 1 ? '.' + x[1] : ''; + var rgx = /(\d+)(\d{3})/; + while (rgx.test(x1)) { + x1 = x1.replace(rgx, '$1' + ',' + '$2'); } + return x1 + x2; }, - /* * Transform text to Title Case ================================================== */ toTitleCase: function(t){ diff --git a/source/js/Embed/Embed.js b/source/js/Embed/Embed.js index 35dcc0a..7f0935f 100644 --- a/source/js/Embed/Embed.js +++ b/source/js/Embed/Embed.js @@ -1,18 +1,7 @@ -/* * VéritéCo Timeline Loader 0.8 - * Designed and built by Zach Wise digitalartwork.net - - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * http://www.gnu.org/licenses/ - +/* + VéritéCo Embed Loader 0.8 + Designed and built by Zach Wise digitalartwork.net + Date: June 21, 2012 */ /* CodeKit Import @@ -22,9 +11,9 @@ var WebFontConfig; -if(typeof timeline_path == 'undefined' || typeof timeline_path == 'undefined') { +if(typeof embed_path == 'undefined' || typeof embed_path == 'undefined') { // REPLACE WITH YOUR BASEPATH IF YOU WANT OTHERWISE IT WILL TRY AND FIGURE IT OUT - var timeline_path = getScriptPath("timeline-embed.js").split("js/")[0]; + var embed_path = getScriptPath("timeline-embed.js").split("js/")[0]; } function getScriptPath(scriptname) { var scriptTags = document.getElementsByTagName('script'), @@ -48,8 +37,8 @@ function getScriptPath(scriptname) { /* VARS ================================================== */ - var timelinejs, t, te, x, isCDN = false, - timeline_js_version = "1.62", + var embedjs, t, te, x, isCDN = false, + js_version = "1.68", jquery_version_required = "1.7.1", jquery_version = "", ready = { @@ -67,19 +56,19 @@ function getScriptPath(scriptname) { } }, path = { - base: timeline_path, - css: timeline_path + "css/", - js: timeline_path + "js/", - locale: timeline_path + "js/locale/", + base: embed_path, + css: embed_path + "css/", + js: embed_path + "js/", + locale: embed_path + "js/locale/", jquery: "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js", font: { google: false, - css: timeline_path + "css/themes/font/", + css: embed_path + "css/themes/font/", js: "http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js" } }, embed_config = { - version: timeline_js_version, + version: js_version, debug: false, embed: true, width: '100%', @@ -87,8 +76,8 @@ function getScriptPath(scriptname) { source: 'https://docs.google.com/spreadsheet/pub?key=0Agl_Dv6iEbDadFYzRjJPUGktY0NkWXFUWkVIZDNGRHc&output=html', lang: 'en', font: 'default', - css: path.css + 'timeline.css?'+timeline_js_version, - js: path.js + 'timeline-min.js?'+timeline_js_version + css: path.css + 'timeline.css?'+js_version, + js: path.js + 'timeline-min.js?'+js_version }, font_presets = [ { name: "Merriweather-NewsCycle", google: [ 'News+Cycle:400,700:latin', 'Merriweather:400,700,900:latin' ] }, @@ -148,17 +137,16 @@ function getScriptPath(scriptname) { if (embed_config.lang.match("/")) { path.locale = embed_config.lang; } else { - path.locale = path.locale + embed_config.lang + ".js?" + timeline_js_version; + path.locale = path.locale + embed_config.lang + ".js?" + js_version; } // Check for old installs still using the old method of language if (embed_config.js.match("locale")) { embed_config.lang = embed_config.js.split("locale/")[1].replace(".js", ""); - embed_config.js = path.js + 'timeline-min.js?'+timeline_js_version; + embed_config.js = path.js + 'timeline-min.js?' + js_version; } /* PREPARE ================================================== */ - timeline_config = embed_config; - createTimelineDiv(); + createEmbedDiv(); /* Load CSS ================================================== */ @@ -178,7 +166,7 @@ function getScriptPath(scriptname) { path.font.css = embed_config.font; } else { path.font.name = embed_config.font; - path.font.css = path.font.css + embed_config.font + ".css?" + timeline_js_version; + path.font.css = path.font.css + embed_config.font + ".css?" + js_version; } LazyLoad.css(path.font.css, onloaded_font_css); @@ -262,7 +250,7 @@ function getScriptPath(scriptname) { if (ready.js && ready.css && ready.font.css && ready.font.js && ready.language) { if (!ready.finished) { ready.finished = true; - buildTimeline(); + buildEmbed(); } } else { ready.timeout = setTimeout('onloaded_check_again();', 250); @@ -275,11 +263,11 @@ function getScriptPath(scriptname) { /* Build Timeline ================================================== */ - function createTimelineDiv() { + function createEmbedDiv() { t = document.createElement('div'); te = document.getElementById("timeline-embed"); te.appendChild(t); - t.setAttribute("id", 'timeline'); + t.setAttribute("id", 'timelinejs'); if (embed_config.width.toString().match("%") ) { te.style.width = embed_config.width; @@ -302,12 +290,12 @@ function getScriptPath(scriptname) { t.style.position = 'relative'; } - function buildTimeline() { + function buildEmbed() { VMM.debug = embed_config.debug; - timelinejs = new VMM.Timeline(); - timelinejs.init(embed_config.source); + embedjs = new VMM.Timeline(); + embedjs.init(embed_config.source); if (isCDN) { - VMM.bindEvent(global, onTimelineHeadline, "TIMELINE_HEADLINE"); + VMM.bindEvent(global, onHeadline, "HEADLINE"); } }; diff --git a/source/js/VMM.Timeline.License.js b/source/js/VMM.Timeline.License.js index 2a0742f..5bdb65e 100644 --- a/source/js/VMM.Timeline.License.js +++ b/source/js/VMM.Timeline.License.js @@ -1,5 +1,6 @@ /*! TimelineJS + Version 1.65 Designed and built by Zach Wise at VéritéCo This program is free software: you can redistribute it and/or modify diff --git a/source/js/VMM.Timeline.TimeNav.js b/source/js/VMM.Timeline.TimeNav.js index 8dbdda8..04f7bb7 100644 --- a/source/js/VMM.Timeline.TimeNav.js +++ b/source/js/VMM.Timeline.TimeNav.js @@ -1295,8 +1295,8 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin $dragslide.createPanel(layout, $timenav, config.nav.constraint, config.touch); // ZOOM EVENTS - VMM.bindEvent(".zoom-in", onZoomIn, "click"); - VMM.bindEvent(".zoom-out", onZoomOut, "click"); + VMM.bindEvent($zoomin, onZoomIn, "click"); + VMM.bindEvent($zoomout, onZoomOut, "click"); if (!config.touch) { diff --git a/source/js/VMM.Timeline.js b/source/js/VMM.Timeline.js index ae8ba7e..097028e 100755 --- a/source/js/VMM.Timeline.js +++ b/source/js/VMM.Timeline.js @@ -62,10 +62,10 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { if (type.of(_timeline_id) == "string") { timeline_id = _timeline_id; } else { - timeline_id = "#timeline"; + timeline_id = "#timelinejs"; } - version = "1.65"; + version = "1.68"; trace("TIMELINE VERSION " + version); @@ -76,7 +76,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { events: { data_ready: "DATAREADY", messege: "MESSEGE", - headline: "TIMELINE_HEADLINE", + headline: "HEADLINE", slide_change: "SLIDE_CHANGE", resize: "resize" }, @@ -191,21 +191,14 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { var createConfig = function(conf) { // APPLY SUPPLIED CONFIG TO TIMELINE CONFIG + if (typeof embed_config == 'object') { + timeline_config = embed_config; + } if (typeof timeline_config == 'object') { trace("HAS TIMELINE CONFIG"); - var x; - for (x in timeline_config) { - if (Object.prototype.hasOwnProperty.call(timeline_config, x)) { - config[x] = timeline_config[x]; - } - } + config = VMM.Util.mergeConfig(config, timeline_config); } else if (typeof conf == 'object') { - var x; - for (x in conf) { - if (Object.prototype.hasOwnProperty.call(conf, x)) { - config[x] = conf[x]; - } - } + config = VMM.Util.mergeConfig(config, conf); } if (VMM.Browser.device == "mobile" || VMM.Browser.device == "tablet") { @@ -347,10 +340,12 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { $feedback = VMM.appendAndGetElement($timeline, "
", "feedback", ""); + // EVENTS VMM.bindEvent(global, onDataReady, config.events.data_ready); VMM.bindEvent(global, showMessege, config.events.messege); VMM.fireEvent(global, config.events.messege, VMM.master_config.language.messages.loading_timeline); + /* GET DATA ================================================== */ if (VMM.Browser.browser == "Explorer" || VMM.Browser.browser == "MSIE") {