Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Webpack Encore to manage assets #586

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,5 +1,6 @@
/app/config/parameters.yml
/build/
/node_modules/
/phpunit.xml
/.php_cs
/var/*
Expand All @@ -16,3 +17,5 @@
!var/SymfonyRequirements.php
/vendor/
/web/bundles/
/web/build/fonts/glyphicons-*
/web/build/images/glyphicons-*
65 changes: 65 additions & 0 deletions app/Resources/assets/js/admin.js
@@ -0,0 +1,65 @@
require('eonasdan-bootstrap-datetimepicker');

require('imports-loader?define=>false!typeahead.js/dist/typeahead.jquery.min.js');
const Bloodhound = require('imports-loader?define=>false!typeahead.js/dist/bloodhound.js');
window.Bloodhound = Bloodhound;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this shouldn't be needed (in theory), but it's possible there's some legacy library that isn't requiring this correctly. We'll need to make sure each line is needed, and document which lines are needed and why

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove those, I see this error:

Uncaught ReferenceError: Bloodhound is not defined
    at HTMLDocument.<anonymous> (admin.js:35043)
    at mightThrow (admin.js:11908)
    at process (admin.js:11976)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a lot of errors related to this library. Maybe we can replace it with some simpler alternative library? After all, our needs are super basic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add something like .autoProvideVariables({ 'window.Bloodhound': "bloodhound") to your webpack.config.js

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might decide to change: twitter/typeahead.js#1618

require('../scss/bootstrap-tagsinput.scss');
require('bootstrap-tagsinput');

$(function() {
// Datetime picker initialization.
// See http://eonasdan.github.io/bootstrap-datetimepicker/
$('[data-toggle="datetimepicker"]').datetimepicker({
icons: {
time: 'fa fa-clock-o',
date: 'fa fa-calendar',
up: 'fa fa-chevron-up',
down: 'fa fa-chevron-down',
previous: 'fa fa-chevron-left',
next: 'fa fa-chevron-right',
today: 'fa fa-check-circle-o',
clear: 'fa fa-trash',
close: 'fa fa-remove'
}
});

// Bootstrap-tagsinput initialization
// http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/
var $input = $('input[data-toggle="tagsinput"]');
if ($input.length) {
var source = new Bloodhound({
local: $input.data('tags'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
datumTokenizer: Bloodhound.tokenizers.whitespace
});
source.initialize();
$input.tagsinput({
trimValue: true,
focusClass: 'focus',
typeahead: {
name: 'tags',
source: source.ttAdapter()
}
});
}
})

// Handling the modal confirmation message.
$(document).on('submit', 'form[data-confirmation]', function (event) {
var $form = $(this),
$confirm = $('#confirmationModal');

if ($confirm.data('result') !== 'yes') {
//cancel submit event
event.preventDefault();

$confirm
.off('click', '#btnYes')
.on('click', '#btnYes', function () {
$confirm.data('result', 'yes');
$form.find('input[type="submit"]').attr('disabled', 'disabled');
$form.submit();
})
.modal('show');
}
});
7 changes: 7 additions & 0 deletions app/Resources/assets/js/app.js
@@ -0,0 +1,7 @@
// loads the Bootstrap jQuery plugins
require('bootstrap-sass/assets/javascripts/bootstrap/dropdown.js');
require('bootstrap-sass/assets/javascripts/bootstrap/modal.js');
require('bootstrap-sass/assets/javascripts/bootstrap/transition.js');

// loads the code syntax highlighting library
require('./highlight.js');
9 changes: 9 additions & 0 deletions app/Resources/assets/js/highlight.js
@@ -0,0 +1,9 @@
var hljs = require('highlight.js/lib/highlight.js');

hljs.configure({
languages: ['twig', 'php']
});

hljs.initHighlightingOnLoad();

module.exports = hljs;
11 changes: 11 additions & 0 deletions app/Resources/assets/js/login.js
@@ -0,0 +1,11 @@
$(function() {
var usernameEl = $('#username');
var passwordEl = $('#password');

// in a real application, hardcoding the user/password would be idiotic
// but for the demo application it's very convenient to do so
if (!usernameEl.val() && !passwordEl.val()) {
usernameEl.val('jane_admin');
passwordEl.val('kitten');
}
});
25 changes: 25 additions & 0 deletions app/Resources/assets/scss/admin.scss
@@ -0,0 +1,25 @@
@import "~bootswatch/flatly/variables";
@import "~eonasdan-bootstrap-datetimepicker/src/sass/bootstrap-datetimepicker-build.scss";

/* Page: 'Backend post index'
------------------------------------------------------------------------- */
body#admin_post_index .item-actions {
white-space: nowrap
}

body#admin_post_index .item-actions a.btn + a.btn {
margin-left: 4px
}

/* Page: 'Backend post show'
------------------------------------------------------------------------- */
body#admin_post_show .post-tags .label-default {
background-color: #e9ecec;
color: #6D8283;
font-size: 16px;
margin-right: 10px;
padding: .4em 1em .5em;
}
body#admin_post_show .post-tags .label-default i {
color: #95A6A7;
}