Updates to javascript

- Changed require.yml config from dependencies to globals (more obvious what it means)
- Updated js_asset_manager to work with new require.yml
- Fixed a few bugs in octopress.js related to mobile nave and flash movies.
This commit is contained in:
Brandon Mathis 2013-04-02 16:24:13 -05:00
parent 9f3407906e
commit b1d7550556
4 changed files with 18 additions and 24 deletions

View File

@ -7,7 +7,7 @@
require_js:
# Dependiences are added first as globals
dependencies:
globals:
- lib/modernizr.js
- lib/swfobject-dynamic.js
- lib/*.*

View File

@ -6,13 +6,13 @@ var addEvent = 'addEventListener',
type = 'gesturestart',
qsa = 'querySelectorAll',
scales = [1, 1],
meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
meta = qsa in document ? document[qsa]('meta[name=viewport]') : [];
function fix() {
meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
doc.removeEventListener(type, fix, true);
document.removeEventListener(type, fix, true);
}
if ((meta = meta[meta.length - 1]) && addEvent in doc) {
if ((meta = meta[meta.length - 1]) && addEvent in document) {
fix();
scales = [0.25, 1.6];
doc[addEvent](type, fix, true);
document[addEvent](type, fix, true);
}

View File

@ -4,11 +4,11 @@ var octopress = (function(){
var mainNav = $('ul.main-navigation, ul[role=main-navigation]').before('<fieldset class="mobile-nav">')
var mobileNav = $('fieldset.mobile-nav').append('<select>');
mobileNav.find('select').append('<option value="">Navigate&hellip;</option>');
var addOption = function() {
var addOption = function(i, option) {
mobileNav.find('select').append('<option value="' + this.href + '">&raquo; ' + $(this).text() + '</option>');
}
mainNav.find('a').each(i, addOption);
$('ul.subscription a').each(i, addOption);
mainNav.find('a').each(addOption);
$('ul.subscription a').each(addOption);
mobileNav.find('select').bind('change', function(event) {
if (event.target.value) { window.location.href = event.target.value; }
});
@ -61,7 +61,7 @@ var octopress = (function(){
, flashVideoFallback: function (){
var flashplayerlocation = "/assets/jwplayer/player.swf",
flashplayerskin = "/assets/jwplayer/glow/glow.xml";
$('video').each(i, function(video){
$('video').each(function(i, video){
video = $(video);
if (!Modernizr.video.h264 && swfobject.getFlashPlayerVersion() || window.location.hash.indexOf("flash-test") !== -1){
video.children('source[src$=mp4]').first().map(i, function(source){
@ -81,18 +81,12 @@ var octopress = (function(){
}
, wrapFlashVideos: function () {
$('object').each(i, function(object) {
object = $(object);
if ( $('param[name=movie]', object).length ) {
var wrapper = object.before('<div class="flash-video"><div>').previous();
$(wrapper).children().append(object);
$('object').each(function(i, object) {
if( $(object).find('param[name=movie]').length ){
$(object).wrap('<div class="flash-video">')
}
});
$('iframe[src*=vimeo],iframe[src*=youtube]').each(i, function(iframe) {
iframe = $(iframe);
var wrapper = iframe.before('<div class="flash-video"><div>').previous();
$(wrapper).children().append(iframe);
});
$('iframe[src*=vimeo],iframe[src*=youtube]').wrap('<div class="flash-video">')
}
}
})();
@ -101,7 +95,7 @@ $(document).ready(function() {
octopress.wrapFlashVideos();
octopress.testFeature(['maskImage', 'transform']);
octopress.flashVideoFallback();
octopress.addCodeLineNumbers();
octopress.addMobileNav();
octopress.addSidebarToggler();
});

View File

@ -15,7 +15,7 @@ module Octopress
@js_assets_path = File.expand_path("../../assets/javascripts", File.dirname(__FILE__))
# Read js dependencies from require_js.yml configuration
@dependencies = @configuration[:require_js][:dependencies].collect {|item| Dir.glob("#{@js_assets_path}/#{item}") }.flatten.uniq
@globals = @configuration[:require_js][:globals].collect {|item| Dir.glob("#{@js_assets_path}/#{item}") }.flatten.uniq
@modules = @configuration[:require_js][:modules].collect {|item| Dir.glob("#{@js_assets_path}/#{item}") }.flatten.uniq
@template_path = File.expand_path("../../#{@configuration[:source]}", File.dirname(__FILE__))
@ -24,7 +24,7 @@ module Octopress
def get_fingerprint
Digest::MD5.hexdigest(@modules.concat(@dependencies).uniq.map! do |path|
Digest::MD5.hexdigest(@modules.concat(@globals).uniq.map! do |path|
"#{File.mtime(path).to_i}"
end.join)
end
@ -43,8 +43,8 @@ module Octopress
if File.exists?(file) and File.open(file) {|f| f.readline} =~ /#{@fingerprint}/
false
else
modules = @modules.delete_if { |f| @dependencies.include? f }
js = Stitch::Package.new(:dependencies => @dependencies, :paths => modules).compile
modules = @modules.delete_if { |f| @globals.include? f }
js = Stitch::Package.new(:dependencies => @globals, :paths => modules).compile
js = "/* Octopress fingerprint: #{@fingerprint} */\n" + js
js = Uglifier.new.compile js if Octopress.env == 'production'
write_path = "#{@template_path}/#{@build_path}"