<?php if (!defined('ABSPATH')) exit('direct script access is not allowed');
/**
 * This file is part of Novuso WPCommon
 *
 * @author    John Nickell
 * @copyright Copyright (c) 2014, Novuso. (http://novuso.com/)
 * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
 */

if (!function_exists('novuso_wp_common_register_scripts')):
/**
 * Registers common JavaScript libraries
 */
function novuso_wp_common_register_scripts() {
    $debug = (defined('WP_DEBUG') && WP_DEBUG) ? true : false;
    $basePath = trailingslashit(NOVUSO_WP_COMMON_URL).'assets/js/';
    $version = null;

    // Modernizr
    $handle = 'modernizr';
    $source = $basePath.'modernizr-2.8.3'.($debug ? '' : '.min').'.js';
    $deps = [];
    $footer = false;
    wp_register_script($handle, $source, $deps, $version, $footer);

    // JSON2
    $handle = 'json2';
    $source = $basePath.'json2-20140204'.($debug ? '' : '.min').'.js';
    $deps = [];
    $footer = true;
    wp_deregister_script($handle);
    wp_register_script($handle, $source, $deps, $version, $footer);

    // jQuery core
    $handle = 'jquery-core';
    $source = $basePath.'jquery-1.11.1'.($debug ? '' : '.min').'.js';
    $deps = ['json2'];
    $footer = true;
    wp_deregister_script($handle);
    wp_register_script($handle, $source, $deps, $version, $footer);

    // jQuery
    $handle = 'jquery';
    $source = $basePath.'jquery-migrate-1.2.1'.($debug ? '' : '.min').'.js';
    $deps = ['jquery-core'];
    $footer = true;
    wp_deregister_script($handle);
    wp_deregister_script('jquery-migrate');
    wp_register_script($handle, $source, $deps, $version, $footer);

    // Underscore
    $handle = 'underscore';
    $source = $basePath.'underscore-1.6.0'.($debug ? '' : '.min').'.js';
    $deps = [];
    $footer = true;
    wp_deregister_script($handle);
    wp_register_script($handle, $source, $deps, $version, $footer);

    // Backbone
    $handle = 'backbone';
    $source = $basePath.'backbone-1.1.2'.($debug ? '' : '.min').'.js';
    $deps = ['underscore', 'jquery'];
    $footer = true;
    wp_deregister_script($handle);
    wp_register_script($handle, $source, $deps, $version, $footer);

    // Marionette
    $handle = 'marionette';
    $source = $basePath.'backbone.marionette-2.0.2'.($debug ? '' : '.min').'.js';
    $deps = ['backbone'];
    $footer = true;
    wp_register_script($handle, $source, $deps, $version, $footer);

    // Bootstrap
    $handle = 'bootstrap';
    $source = $basePath.'bootstrap-3.2.0'.($debug ? '' : '.min').'.js';
    $deps = ['jquery'];
    $footer = true;
    wp_register_script($handle, $source, $deps, $version, $footer);

    // DataTables
    $handle = 'datatables';
    $source = $basePath.'jquery.dataTables-1.10.0'.($debug ? '' : '.min').'.js';
    $deps = ['jquery'];
    $footer = true;
    wp_register_script($handle, $source, $deps, $version, $footer);

    // DataTables with Bootstrap
    $handle = 'datatables-bootstrap';
    $source = $basePath.'dataTables.bootstrap-1.10.0'.($debug ? '' : '.min').'.js';
    $deps = ['datatables'];
    $footer = true;
    wp_register_script($handle, $source, $deps, $version, $footer);

    // Markdown
    $handle = 'markdown';
    $source = $basePath.'markdown-0.5.0'.($debug ? '' : '.min').'.js';
    $deps = [];
    $footer = true;
    wp_register_script($handle, $source, $deps, $version, $footer);

    // Masonry
    $handle = 'masonry';
    $source = $basePath.'masonry-3.1.5'.($debug ? '' : '.min').'.js';
    $deps = [];
    $footer = true;
    wp_register_script($handle, $source, $deps, $version, $footer);
}
endif;

if (!function_exists('novuso_wp_common_register_styles')):
/**
 * Registers common CSS dependencies
 */
function novuso_wp_common_register_styles() {
    $debug = (defined('WP_DEBUG') && WP_DEBUG) ? true : false;
    $basePath = trailingslashit(NOVUSO_WP_COMMON_URL).'assets/css/';
    $version = null;

    // DataTables with Bootstrap
    $handle = 'datatables-bootstrap-css';
    $source = $basePath.'dataTables.bootstrap-1.10.0'.($debug ? '' : '.min').'.css';
    $deps = [];
    wp_register_style($handle, $source, $deps, $version);
}
endif;
