Skip to content
Permalink
Browse files

split js files

  • Loading branch information
bborgesr committed Apr 21, 2017
1 parent 541d3c1 commit ea915038ae2126f48c15e3aac41782a22b16c506
@@ -1,6 +1,7 @@
^.*\.Rproj$
^\.Rproj\.user$
^tools$
^srcjs$
^tests-manual$
^\.travis\.yml$
^appveyor\.yml$
@@ -13,9 +13,11 @@ appendDependencies <- function(x, value) {
addDeps <- function(x) {
if (getOption("shiny.minified", TRUE)) {
adminLTE_js <- "app.min.js"
shinydashboard_js <- "shinydashboard.min.js"
adminLTE_css <- c("AdminLTE.min.css", "_all-skins.min.css")
} else {
adminLTE_js <- "app.js"
shinydashboard_js <- "shinydashboard.js"
adminLTE_css <- c("AdminLTE.css", "_all-skins.css")
}

@@ -28,7 +30,7 @@ addDeps <- function(x) {
htmlDependency("shinydashboard",
as.character(utils::packageVersion("shinydashboard")),
c(file = system.file(package = "shinydashboard")),
script = "shinydashboard.js",
script = shinydashboard_js,
stylesheet = "shinydashboard.css"
)
)

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more.

Large diffs are not rendered by default.

@@ -0,0 +1 @@
});
@@ -0,0 +1 @@
$(function() {
@@ -0,0 +1,48 @@
/* global Shiny */

// tabItemInputBinding
// ------------------------------------------------------------------
// Based on Shiny.tabItemInputBinding, but customized for tabItems in
// shinydashboard, which have a slightly different structure.
var tabItemInputBinding = new Shiny.InputBinding();
$.extend(tabItemInputBinding, {
find: function(scope) {
return $(scope).find('ul.sidebar-menu');
},
getValue: function(el) {
var anchor = $(el).find('li:not(.treeview).active').children('a');
if (anchor.length === 1)
return this._getTabName(anchor);

return null;
},
setValue: function(el, value) {
var self = this;
var anchors = $(el).find('li:not(.treeview)').children('a');
anchors.each(function() {
if (self._getTabName($(this)) === value) {
$(this).tab('show');
return false;
}
});
},
receiveMessage: function(el, data) {
if (data.hasOwnProperty('value'))
this.setValue(el, data.value);
},
subscribe: function(el, callback) {
// This event is triggered by deactivateOtherTabs, which is triggered by
// shown. The deactivation of other tabs must occur before Shiny gets the
// input value.
$(el).on('change.tabItemInputBinding', function() {
callback();
});
},
unsubscribe: function(el) {
$(el).off('.tabItemInputBinding');
},
_getTabName: function(anchor) {
return anchor.attr('data-value');
}
});
Shiny.inputBindings.register(tabItemInputBinding, 'shinydashboard.tabItemInput');
@@ -0,0 +1,45 @@
/* global Shiny */

// menuOutputBinding
// ------------------------------------------------------------------
// Based on Shiny.htmlOutputBinding, but instead of putting the result in a
// wrapper div, it replaces the origin DOM element with the new DOM elements,
// copying over the ID and class.
var menuOutputBinding = new Shiny.OutputBinding();
$.extend(menuOutputBinding, {
find: function(scope) {
return $(scope).find('.shinydashboard-menu-output');
},
onValueError: function(el, err) {
Shiny.unbindAll(el);
this.renderError(el, err);
},
renderValue: function(el, data) {
Shiny.unbindAll(el);

var html;
var dependencies = [];
if (data === null) {
return;
} else if (typeof(data) === 'string') {
html = data;
} else if (typeof(data) === 'object') {
html = data.html;
dependencies = data.deps;
}

var $html = $($.parseHTML(html));

// Convert the inner contents to HTML, and pass to renderHtml
Shiny.renderHtml($html.html(), el, dependencies);

// Extract class of wrapper, and add them to the wrapper element
el.className = 'shinydashboard-menu-output shiny-bound-output ' +
$html.attr('class');

Shiny.initializeInputs(el);
Shiny.bindAll(el);
}
});
Shiny.outputBindings.register(menuOutputBinding,
"shinydashboard.menuOutputBinding");
@@ -0,0 +1,15 @@
// Optionally disable sidebar
if ($("section.sidebar").data("disable")) {
$("body").addClass("sidebar-collapse");
$(".navbar > .sidebar-toggle").hide();
}

// Trigger the resize event when the sidebar is collapsed/expanded
// (this allows images to be responsive and resize themselves)
$(document).on("click", ".sidebar-toggle", function() {
$(window).trigger("resize");
});

$(document).on("click", ".treeview > a", function() {
$(this).next(".treeview-menu").trigger("shown");
});
@@ -0,0 +1,46 @@
// This function handles a special case in the AdminLTE sidebar: when there
// is a sidebar-menu with items, and one of those items has sub-items, and
// they are used for tab navigation. Normally, if one of the items is
// selected and then a sub-item is clicked, both the item and sub-item will
// retain the "active" class, so they will both be highlighted. This happens
// because they're not designed to be used together for tab panels. This
// code ensures that only one item will have the "active" class.
var deactivateOtherTabs = function() {
var $this = $(this);
var $sidebarMenu = $this.closest("ul.sidebar-menu");

// Find all tab links under sidebar-menu
var $tablinks = $sidebarMenu.find("a[data-toggle='tab']");

// If any other items are active, deactivate them
$tablinks.not($this).parent("li").removeClass("active");

// Trigger event for the tabItemInputBinding
$sidebarMenu.trigger('change.tabItemInputBinding');
};

$(document).on('shown.bs.tab', '.sidebar-menu a[data-toggle="tab"]',
deactivateOtherTabs);


// When document is ready, if there is a sidebar menu with no activated tabs,
// activate the one specified by `data-start-selected`, or if that's not
// present, the first one.
var ensureActivatedTab = function() {
var $tablinks = $("ul.sidebar-menu").find("a").filter("[data-toggle='tab']");

// If there's a `data-start-selected` attribute and we can find a tab with
// that name, activate it.
var $startTab = $tablinks.filter("[data-start-selected='1']");
if ($startTab.length !== 0) {
$startTab.tab("show");
return;
}

// If we got this far, just activate the first tab.
if (! $tablinks.parent("li").hasClass("active") ) {
$tablinks.first().tab("show");
}
};

ensureActivatedTab();
@@ -1,27 +1,51 @@
module.exports = function(grunt) {

var srcdir = '../inst/';
var srcdirjs = '../srcjs/';
var srcdircss = '../inst/';
var destdirjs = '../inst/';
var destdircss = '../inst/';

grunt.initConfig({
pkg: pkgInfo(),
concat: {
options: {
process: function(src, filepath) {
return '//---------------------------------------------------------------------\n' +
'// Source file: ' + filepath + '\n\n' + src;
},
sourceMap: true
},
shinydashboard: {
src: [
srcdirjs + '_start.js',
srcdirjs + 'tabs.js',
srcdirjs + 'sidebar.js',
srcdirjs + 'output_binding_menu.js',
srcdirjs + 'input_binding_tabItem.js',
srcdirjs + '_end.js'
],
dest: destdirjs + 'shinydashboard.js'
}
},

uglify: {
adminlte: {
options: {
sourceMap: true
},
src: srcdir + '/AdminLTE/app.js',
dest: srcdir + '/AdminLTE/app.min.js'
src: destdirjs + '/AdminLTE/app.js',
dest: destdirjs + '/AdminLTE/app.min.js'
}
},

cssmin: {
adminlte: {
src: srcdir + '/AdminLTE/AdminLTE.css',
dest: srcdir + '/AdminLTE/AdminLTE.min.css'
src: srcdircss + '/AdminLTE/AdminLTE.css',
dest: srcdircss + '/AdminLTE/AdminLTE.min.css'
},
adminlte_themes: {
src: srcdir + '/AdminLTE/_all-skins.css',
dest: srcdir + '/AdminLTE/_all-skins.min.css'
src: srcdircss + '/AdminLTE/_all-skins.css',
dest: srcdircss + '/AdminLTE/_all-skins.min.css'
}
},

@@ -30,7 +54,7 @@ module.exports = function(grunt) {
force: true // Don't abort if there are JSHint warnings
},
shinydashboard: {
src: srcdir + '/shinydashboard.js',
src: destdirjs + '/shinydashboard.js',
}
},

@@ -51,10 +75,11 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-newer');


grunt.registerTask('default', ['newer:uglify', 'newer:cssmin', 'newer:jshint']);
grunt.registerTask('default', ['newer:concat', 'newer:uglify', 'newer:cssmin', 'newer:jshint']);



@@ -1,6 +1,7 @@
{
"devDependencies": {
"grunt": "^1.0.1",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-cssmin": "^2.0.0",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-uglify": "^2.1.0",
@@ -23,6 +23,6 @@ srcdir <- file.path(dirname(thisFile()), "../../AdminLTE/dist")
destdir <- file.path(dirname(thisFile()), "../inst/AdminLTE")


file.copy(file.path(srcdir, "/js/app.js"), destdir, overwrite = TRUE)
file.copy(file.path(srcdir, "/js/app.js"), "../srcjs/AdminLTE", overwrite = TRUE)
file.copy(file.path(srcdir, "/css/AdminLTE.css"), destdir, overwrite = TRUE)
file.copy(file.path(srcdir, "/css/skins/_all-skins.css"), destdir, overwrite = TRUE)
@@ -380,6 +380,13 @@ grunt-cli@~1.2.0:
nopt "~3.0.6"
resolve "~1.1.0"

grunt-contrib-concat@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/grunt-contrib-concat/-/grunt-contrib-concat-1.0.1.tgz#61509863084e871d7e86de48c015259ed97745bd"
dependencies:
chalk "^1.0.0"
source-map "^0.5.3"

grunt-contrib-cssmin@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/grunt-contrib-cssmin/-/grunt-contrib-cssmin-2.0.0.tgz#3bc8e8c8865c819159cc2779f82fcf833473345b"
@@ -907,7 +914,7 @@ signal-exit@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"

source-map@0.5.x, source-map@~0.5.1:
source-map@0.5.x, source-map@^0.5.3, source-map@~0.5.1:
version "0.5.6"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"

0 comments on commit ea91503

Please sign in to comment.
You can’t perform that action at this time.