<commit_before>'use strict';

define(['app', 'extended-route-provider','authentication', 'services', 'filters', 'storage', 'workflows', 'realm-configuration', 'user-notifications'], function (app) {

     app.value("realm", {value:"ABS"});
    app.value("schemaTypes", [ "absPermit", "absCheckpoint", "absCheckpointCommunique", "authority", "measure", "database", "resource" ]);

    app.config(['extendedRouteProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
          $locationProvider.html5Mode(true);
        $locationProvider.hashPrefix('!');

        $routeProvider.
            when('/',                            { templateUrl: '/app/views/home/index.html'                     ,resolveController: true, resolveUser: true}).
            when('/commonformat',                { templateUrl: '/app/views/common-formats.html'            ,resolveController: true, resolveUser: true}).
            //when('/presentation',                { templateUrl: '/app/views/help/presentation.html'            ,resolveController: true, resolveUser: true}).
            when('/about',                       { templateUrl: '/app/views/about/about.html'                     ,resolveController: true, resolveUser: true}).
            when('/help',                        { templateUrl: '/app/views/help/help.html'                      ,resolveController: true, resolveUser: true}).
            when('/help/presentations/',         { templateUrl: '/app/views/help/presentations/home.html'                      ,resolveController: true, resolveUser: true}).
            when('/help/accounts',              { templateUrl: '/app/views/help/accounts/accounts.html'                      ,resolveController: true, resolveUser: true}).
            // when('/help/accounts/:question',              { templateUrl: '/app/views/help/accounts/accounts.html'                      ,resolveController: true, resolveUser: true}).

            when('/forums',                  { templateUrl: '/app/views/forums/forum-list-view.html'    ,resolveController: true, resolveUser: true }).
            when('/forums/iac',              { templateUrl: '/app/views/forums/thread-list-view.html'   ,resolveController: true, resolveUser: true, forumId:17415, postUrl:'/forums/iac', text:'IAC' }).
            when('/forums/iac/:threadId',    { templateUrl: '/app/views/forums/post-list-view.html'     ,resolveController: true, resolveUser: true, forumId:17415, forumListUrl:'/forums/iac/', text:'IAC'}).
            when('/forums/vlr',              { templateUrl: '/app/views/forums/thread-list-view.html'   ,resolveController: true, resolveUser: true, forumId:17384, postUrl:'/forums/vlr', text:'VLR' }).
            when('/forums/vlr/:threadId',    { templateUrl: '/app/views/forums/post-list-view.html'     ,resolveController: true, resolveUser: true, forumId:17384, forumListUrl:'/forums/vlr/', text:'VLR'}).
            when('/forums/caribbean',              { templateUrl: '/app/views/forums/thread-list-view.html'   ,resolveController: true, resolveUser: true, forumId:17378, postUrl:'/forums/caribbean', text:'Caribbean Region Forum' }).
            when('/forums/caribbean/:threadId',    { templateUrl: '/app/views/forums/post-list-view.html'     ,resolveController: true, resolveUser: true, forumId:17378, forumListUrl:'/forums/caribbean/', text:'Caribbean Region Forum'}).

            // when('/forums/caribbean region',              { templateUrl: '/app/views/forums/thread-list-view.html'   ,resolveController: true, resolveUser: true, forumId:17378, postUrl:'/forums/caribbean region' }).
            // when('/forums/caribbean region/:threadId',    { templateUrl: '/app/views/forums/post-list-view.html'     ,resolveController: true, resolveUser: true, forumId:17378, forumListUrl:'/forums/caribbean region/'}).

            when('/forums/art10_groups',              { templateUrl: '/app/views/forums/thread-list-view.html'   ,resolveController: true, resolveUser: true, forumId:17316, postUrl:'/forums/art10_groups', text:'Forum on Article 10' }).
            when('/forums/art10_groups/:threadId',    { templateUrl: '/app/views/forums/post-list-view.html'     ,resolveController: true, resolveUser: true, forumId:17316, forumListUrl:'/forums/art10_groups/', text:'Forum on Article 10' }).

            when('/help/search',              { templateUrl: '/app/views/help/search/search.html'                      ,resolveController: true, resolveUser: true}).
            // when('/help/search/:question',              { templateUrl: '/app/views/help/search/search.html'                      ,resolveController: true, resolveUser: true}).
            when('/help/tours',              { templateUrl: '/app/views/help/tours/tours.html'                      ,resolveController: true, resolveUser: true}).

            when('/help/register',              { templateUrl: '/app/views/help/register/register.html'                      ,resolveController: true, resolveUser: true}).
            // when('/help/register/:question',              { templateUrl: '/app/views/help/register/register.html'                      ,resolveController: true, resolveUser: true}).

            when('/search',                         { templateUrl: '/app/views/search/find.html'                      ,resolveController: true, resolveUser: true}).
            //when('/search/',                                      { templateUrl: '/app/views/search/find.html'              ,resolveController: true, resolveUser: true}).
            when('/search/:documentSchema',                       { templateUrl: '/app/views/search/find.html'              ,resolveController: true, resolveUser: true}).
            when('/search/:documentSchema/:countryCode',              { templateUrl: '/app/views/search/find.html'              ,resolveController: true, resolveUser: true}).

            when('/find',                           { redirectTo:'/search'}).
            when('/find/simple',                    { templateUrl: '/app/views/find/simple.html'     ,resolveController: true, resolveUser: true}).

            when('/countries',                   { templateUrl: '/app/views/countries/profiles.html'                 ,resolveController: true, resolveUser: true}).
            when('/countries/:code',             { templateUrl: '/app/views/countries/profiles.html'                  ,resolveController: true, resolveUser: true}).

            // when('/database/record',             { templateUrl: '/app/views/forms/view/records-id.html'     ,resolveController: true, resolveUser: true}).
            // when('/database/record/:documentID',  { templateUrl: '/app/views/forms/view/records-id.html'     ,resolveController: true, resolveUser: true}).
            // when('/database/record/:documentID/:revision', { templateUrl: '/app/views/forms/view/records-id.html'     ,resolveController: true, resolveUser: true}).
            when('/database/:documentID',                           { templateUrl: '/app/views/forms/view/records-id.html'    ,resolveController: true, resolveUser: true}).
            when('/database/:documentSchema/:documentID',           { templateUrl: '/app/views/forms/view/records-id.html'    ,resolveController: true, resolveUser: true}).
            when('/database/:documentSchema/:documentID/:revision', { templateUrl: '/app/views/forms/view/records-id.html'    ,resolveController: true, resolveUser: true}).

            when('/register',                    { templateUrl: '/app/views/register.html'                  ,resolveController: true, resolveUser: true}).
            when('/register/tasks/:id',          { templateUrl: '/app/views/tasks/tasks-id.html'            ,resolveController: true, resolveUser: true}).
            when('/register/tasks/:id/:activity',{ templateUrl: '/app/views/tasks/tasks-id-activity.html'   ,resolveController: true, resolveUser: true}).
            when('/oauth2/callback',             { templateUrl: '/app/views/oauth2/callback.html'           ,resolveController: true, resolveUser: true}).
            when('/workshops/lac',               { templateUrl: '/app/views/workshops/lac.html'             ,resolveController: true, resolveUser: true}).
            when('/workshops/caribbean',         { templateUrl: '/app/views/workshops/caribbean.html'       ,resolveController: true, resolveUser: true}).
            //when('/searchforum.shtml',           { templateUrl:'/app/views/about.html#iac'}).

            when('/certificate/:documentNumber',{ templateUrl: '/app/views/forms/view/records-id.html'       ,resolveController: true, resolveUser: true}).

            //TODO: rename document_type to something more generic... or make this feature more flexible
                when('/commonformat', {
              templateUrl: '/app/views/about/about.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/about/common-formats.html',
              ignoreSubController: true,
            }).
            when('/about', { redirectTo: '/about/absch' }).

            when('/help/presentations/:folder/:document_type', {
              templateUrl: '/app/views/help/presentations/presentation.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/help/presentations/:folder/-',
              ignoreSubController: true,
            }).
            when('/help/presentations/:folder', { redirectTo: '/help/presentations/:folder/start' }).

            when('/about/:document_type', {
              templateUrl: '/app/views/about/about.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/about/-',
              ignoreSubController: true,
            }).
            when('/about', { redirectTo: '/about/absch' }).

            when('/dashboard', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/register/dashboard.html',
            }).

            when('/register/dashboard', {
                templateUrl: '/app/views/register/register.html',
                resolveController: true,
                resolveUser: true,
                subTemplateUrl: '/app/views/register/dashboard.html',
            }).

            when('/register', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/register/dashboard.html',
            }).
            // when('/dashboard/:tour', {
            //   templateUrl: '/app/views/register.html',
            //   resolveController: true,
            //   resolveUser: true,
            //   subTemplateUrl: '/app/views/dashboard.html',
            // }).

            //  when('/dashboard/completed', {
            //   templateUrl: '/app/views/register/register.html',
            //   resolveController: true,
            //   resolveUser: true,
            //   subTemplateUrl: '/app/views/tasks/my-completed-tasks.directive.html',
            // }).
            //  when('/dashboard/pending', {
            //   templateUrl: '/app/views/register/register.html',
            //   resolveController: true,
            //   resolveUser: true,
            //   subTemplateUrl: '/app/views/tasks/my-tasks.directive.html',
            //   type : 'my'
            // }).
            // when('/dashboard/mytasks', {
            //     templateUrl: '/app/views/register/register.html',
            //     resolveController: true,
            //     resolveUser: true,
            //     subTemplateUrl: '/app/views/tasks/my-pending-tasks.directive.html',
            // }).
            //

            when('/register/requests', {
                templateUrl: '/app/views/register/register.html',
                resolveController: true,
                resolveUser: true,
                subTemplateUrl: '/app/views/tasks/my-tasks.directive.html',
                type : 'all'
            }).
            when('/register/requests/:workflowId', {
                templateUrl: '/app/views/register/register.html',
                resolveController: true,
                resolveUser: true,
                subTemplateUrl: '/app/views/tasks/my-tasks.directive.html',
                type : 'all'
            }).
            when('/register/requests/:type/:status', {
                templateUrl: '/app/views/register/register.html',
                resolveController: true,
                resolveUser: true,
                subTemplateUrl: '/app/views/tasks/my-tasks.directive.html',
            }).

            when('/contacts', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/register/contacts.html',
            }).

            when('/register/:document_type', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/register/type_document_list.html',
            }).

            when('/register/:document_type/new', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/forms/edit/edit--', //filled in through controller
            }).

            when('/register/:document_type/help', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/register/type_document_list.html',
            }).

             when('/register/:document_type/:identifier/edit', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/forms/edit/edit--', //filled in through controller
            }).

             when('/register/:document_type/:identifier/edit/:tour', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/forms/edit/edit--', //filled in through controller
            }).

            when('/searchforum.shtml',           { redirectTo:'/about/portal10' }).

            when('/commonformat',           { redirectTo:'/about/common-formats' }).

            otherwise({redirectTo:'/help/404'});
    }]);
});
<commit_msg>added route labels for breadcrumbs<commit_after>'use strict';

define(['app', 'extended-route-provider','authentication', 'services', 'filters', 'storage', 'workflows', 'realm-configuration', 'user-notifications'], function (app) {

     app.value("realm", {value:"ABS"});
    app.value("schemaTypes", [ "absPermit", "absCheckpoint", "absCheckpointCommunique", "authority", "measure", "database", "resource" ]);

    app.config(['extendedRouteProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
          $locationProvider.html5Mode(true);
        $locationProvider.hashPrefix('!');

        $routeProvider.
            when('/',                            { templateUrl: '/app/views/home/index.html',                       label:'ABSCH',                              resolveController: true, resolveUser: true}).
            when('/commonformat',                { templateUrl: '/app/views/common-formats.html',                   label:'Common Formats',                     resolveController: true, resolveUser: true}).
            when('/help',                        { templateUrl: '/app/views/help/help.html',                        label:'Help',                               resolveController: true, resolveUser: true}).
            when('/help/about',                  { templateUrl: '/app/views/help/about/about.html',                 label:'About the ABSCH',                    resolveController: true, resolveUser: true}).
            when('/help/presentations/',         { templateUrl: '/app/views/help/presentations/home.html',          label:'Presentations',                      resolveController: true, resolveUser: true}).
            when('/help/accounts',               { templateUrl: '/app/views/help/accounts/accounts.html',           label:'CBD Accounts',                       resolveController: true, resolveUser: true}).
            when('/help/search',                 { templateUrl: '/app/views/help/search/search.html',               label:'Finding Information',                resolveController: true, resolveUser: true}).
            when('/help/tours',                  { templateUrl: '/app/views/help/tours/tours.html',                 label:'Tours',                              resolveController: true, resolveUser: true}).
            when('/help/register',               { templateUrl: '/app/views/help/register/register.html',           label:'Submitting Information',             resolveController: true, resolveUser: true}).

            when('/forums',                        { templateUrl: '/app/views/forums/forum-list-view.html',         label:'Forums',       resolveController: true, resolveUser: true }).
            when('/forums/iac',              { templateUrl: '/app/views/forums/thread-list-view.html'   ,resolveController: true, resolveUser: true, forumId:17415, postUrl:'/forums/iac', text:'IAC' }).
            when('/forums/iac/:threadId',    { templateUrl: '/app/views/forums/post-list-view.html'     ,resolveController: true, resolveUser: true, forumId:17415, forumListUrl:'/forums/iac/', text:'IAC'}).
            when('/forums/vlr',                    { templateUrl: '/app/views/forums/thread-list-view.html'   ,resolveController: true, resolveUser: true, forumId:17384, postUrl:'/forums/vlr', text:'VLR' }).
            when('/forums/vlr/:threadId',          { templateUrl: '/app/views/forums/post-list-view.html'     ,resolveController: true, resolveUser: true, forumId:17384, forumListUrl:'/forums/vlr/', text:'VLR'}).
            when('/forums/caribbean',              { templateUrl: '/app/views/forums/thread-list-view.html'   ,resolveController: true, resolveUser: true, forumId:17378, postUrl:'/forums/caribbean', text:'Caribbean Region Forum' }).
            when('/forums/caribbean/:threadId',    { templateUrl: '/app/views/forums/post-list-view.html'     ,resolveController: true, resolveUser: true, forumId:17378, forumListUrl:'/forums/caribbean/', text:'Caribbean Region Forum'}).
            //when('/forums/caribbean region',              { templateUrl: '/app/views/forums/thread-list-view.html'   ,resolveController: true, resolveUser: true, forumId:17378, postUrl:'/forums/caribbean region' }).
            //when('/forums/caribbean region/:threadId',    { templateUrl: '/app/views/forums/post-list-view.html'     ,resolveController: true, resolveUser: true, forumId:17378, forumListUrl:'/forums/caribbean region/'}).
            when('/forums/art10_groups',              { templateUrl: '/app/views/forums/thread-list-view.html'   ,resolveController: true, resolveUser: true, forumId:17316, postUrl:'/forums/art10_groups', text:'Forum on Article 10' }).
            when('/forums/art10_groups/:threadId',    { templateUrl: '/app/views/forums/post-list-view.html'     ,resolveController: true, resolveUser: true, forumId:17316, forumListUrl:'/forums/art10_groups/', text:'Forum on Article 10' }).

            when('/search',                                 { templateUrl: '/app/views/search/find.html',   label:'Search',         resolveController: true, resolveUser: true}).
            when('/search/:documentSchema',                 { templateUrl: '/app/views/search/find.html',   label:'Search',         resolveController: true, resolveUser: true}).
            when('/search/:documentSchema/:countryCode',    { templateUrl: '/app/views/search/find.html',   label:'Search',         resolveController: true, resolveUser: true}).
            when('/find/simple',                            { templateUrl: '/app/views/find/simple.html',   label:'Simple Search',  resolveController: true, resolveUser: true}).
            when('/find',                                   { redirectTo:'/search'}).

            when('/countries',                   { templateUrl: '/app/views/countries/profiles.html',       label:'Country Information',      resolveController: true, resolveUser: true}).
            when('/countries/:code',             { templateUrl: '/app/views/countries/profiles.html',       label:'Country Profile', param:'true',      resolveController: true, resolveUser: true}).

            // when('/database/record',             { templateUrl: '/app/views/forms/view/records-id.html'     ,resolveController: true, resolveUser: true}).
            // when('/database/record/:documentID',  { templateUrl: '/app/views/forms/view/records-id.html'     ,resolveController: true, resolveUser: true}).
            // when('/database/record/:documentID/:revision', { templateUrl: '/app/views/forms/view/records-id.html'     ,resolveController: true, resolveUser: true}).

            when('/database/:documentID',                           { templateUrl: '/app/views/forms/view/records-id.html'    ,resolveController: true, resolveUser: true}).
            when('/database/:documentSchema/:documentID',           { templateUrl: '/app/views/forms/view/records-id.html'    ,resolveController: true, resolveUser: true}).
            when('/database/:documentSchema/:documentID/:revision', { templateUrl: '/app/views/forms/view/records-id.html'    ,resolveController: true, resolveUser: true}).

            when('/register',                    { templateUrl: '/app/views/register.html'                  ,resolveController: true, resolveUser: true}).
            when('/register/tasks/:id',          { templateUrl: '/app/views/tasks/tasks-id.html'            ,resolveController: true, resolveUser: true}).
            when('/register/tasks/:id/:activity',{ templateUrl: '/app/views/tasks/tasks-id-activity.html'   ,resolveController: true, resolveUser: true}).
            when('/oauth2/callback',             { templateUrl: '/app/views/oauth2/callback.html'           ,resolveController: true, resolveUser: true}).
            when('/workshops/lac',               { templateUrl: '/app/views/workshops/lac.html'             ,resolveController: true, resolveUser: true}).
            when('/workshops/caribbean',         { templateUrl: '/app/views/workshops/caribbean.html'       ,resolveController: true, resolveUser: true}).
            //when('/searchforum.shtml',           { templateUrl:'/app/views/about.html#iac'}).

            when('/certificate/:documentNumber',{ templateUrl: '/app/views/forms/view/records-id.html'       ,resolveController: true, resolveUser: true}).

            //TODO: rename document_type to something more generic... or make this feature more flexible
                when('/commonformat', {
              templateUrl: '/app/views/about/about.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/about/common-formats.html',
              ignoreSubController: true,
            }).
            when('/about', { redirectTo: '/about/absch' }).

            when('/help/presentations/:folder/:document_type', {
              templateUrl: '/app/views/help/presentations/presentation.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/help/presentations/:folder/-',
              ignoreSubController: true,
            }).
            when('/help/presentations/:folder', { redirectTo: '/help/presentations/:folder/start' }).

            when('/dashboard', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/register/dashboard.html',
            }).

            when('/register/dashboard', {
                templateUrl: '/app/views/register/register.html',
                resolveController: true,
                resolveUser: true,
                subTemplateUrl: '/app/views/register/dashboard.html',
            }).

            when('/register', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/register/dashboard.html',
            }).
            // when('/dashboard/:tour', {
            //   templateUrl: '/app/views/register.html',
            //   resolveController: true,
            //   resolveUser: true,
            //   subTemplateUrl: '/app/views/dashboard.html',
            // }).

            //  when('/dashboard/completed', {
            //   templateUrl: '/app/views/register/register.html',
            //   resolveController: true,
            //   resolveUser: true,
            //   subTemplateUrl: '/app/views/tasks/my-completed-tasks.directive.html',
            // }).
            //  when('/dashboard/pending', {
            //   templateUrl: '/app/views/register/register.html',
            //   resolveController: true,
            //   resolveUser: true,
            //   subTemplateUrl: '/app/views/tasks/my-tasks.directive.html',
            //   type : 'my'
            // }).
            // when('/dashboard/mytasks', {
            //     templateUrl: '/app/views/register/register.html',
            //     resolveController: true,
            //     resolveUser: true,
            //     subTemplateUrl: '/app/views/tasks/my-pending-tasks.directive.html',
            // }).
            //

            when('/register/requests', {
                templateUrl: '/app/views/register/register.html',
                resolveController: true,
                resolveUser: true,
                subTemplateUrl: '/app/views/tasks/my-tasks.directive.html',
                type : 'all'
            }).
            when('/register/requests/:workflowId', {
                templateUrl: '/app/views/register/register.html',
                resolveController: true,
                resolveUser: true,
                subTemplateUrl: '/app/views/tasks/my-tasks.directive.html',
                type : 'all'
            }).
            when('/register/requests/:type/:status', {
                templateUrl: '/app/views/register/register.html',
                resolveController: true,
                resolveUser: true,
                subTemplateUrl: '/app/views/tasks/my-tasks.directive.html',
            }).

            when('/contacts', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/register/contacts.html',
            }).

            when('/register/:document_type', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/register/type_document_list.html',
            }).

            when('/register/:document_type/new', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/forms/edit/edit--', //filled in through controller
            }).

            when('/register/:document_type/help', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/register/type_document_list.html',
            }).

             when('/register/:document_type/:identifier/edit', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/forms/edit/edit--', //filled in through controller
            }).

             when('/register/:document_type/:identifier/edit/:tour', {
              templateUrl: '/app/views/register/register.html',
              resolveController: true,
              resolveUser: true,
              subTemplateUrl: '/app/views/forms/edit/edit--', //filled in through controller
            }).

            when('/searchforum.shtml',           { redirectTo:'/about/portal10' }).

            when('/commonformat',           { redirectTo:'/about/common-formats' }).

            otherwise({redirectTo:'/help/404'});
    }]);
});
<|endoftext|>


<commit_before>function ActionButton(html, callback)
{
    /*
     * Default Color: #DDDDDD; (light gray)
     * Hovered: Darken uniformly (-111111)
     * Selected: Set blue (|0000FF)
     */
    var self = this; // <- I hate javascript.
    this.hover = function()
    {
        self.hovered = true;
        if(self.selected) self.html.style.backgroundColor = '#CCCCFF';
        else self.html.style.backgroundColor = '#CCCCCC';
    };
    this.unhover = function()
    {
        self.hovered = false;
        if(self.selected) self.html.style.backgroundColor = '#DDDDFF';
        else self.html.style.backgroundColor = '#DDDDDD';
    };
    this.select = function()
    {
        self.selected = true;
        if(self.hovered) self.html.style.backgroundColor = '#CCCCFF';
        else self.html.style.backgroundColor = '#DDDDFF';
    };
    this.deselect = function()
    {
        self.callback(self);
        self.selected = false;
        if(self.hovered) self.html.style.backgroundColor = '#CCCCCC'
        else self.html.style.backgroundColor = '#DDDDDD';
    };
    this.hovered = false;
    this.selected = false;

    this.html = html;
    this.callback = callback;
    this.html.addEventListener('mouseover', this.hover, false);
    this.html.addEventListener('mouseout', this.unhover, false);
    this.html.addEventListener('mousedown', this.select, false);
    this.html.addEventListener('mouseup', this.deselect, false);
}

/* Note- the callback is in charge of enforcing the single selection */
/* Sends (self) to callback on click */
function SingleSelectionButton(html, callback)
{
    /*
     * Default Color: #DDDDDD; (light gray)
     * Hovered: Darken uniformly (-111111)
     * Selected: Set blue (|0000FF)
     */
    var self = this; // <- I hate javascript.
    this.hover = function()
    {
        self.hovered = true;
        if(self.selected) self.html.style.backgroundColor = '#CCCCFF';
        else self.html.style.backgroundColor = '#CCCCCC';
    };
    this.unhover = function()
    {
        self.hovered = false;
        if(self.selected) self.html.style.backgroundColor = '#DDDDFF';
        else self.html.style.backgroundColor = '#DDDDDD';
    };
    this.select = function()
    {
        self.callback(self);
        self.selected = true;
        if(self.hovered) self.html.style.backgroundColor = '#CCCCFF';
        else self.html.style.backgroundColor = '#DDDDFF';
    };
    this.deselect = function()
    {
        self.selected = false;
        if(self.hovered) self.html.style.backgroundColor = '#CCCCCC'
        else self.html.style.backgroundColor = '#DDDDDD';
    };
    this.hovered = false;
    this.selected = false;

    this.html = html;
    this.callback = callback;
    this.html.addEventListener('mouseover', this.hover, false);
    this.html.addEventListener('mouseout', this.unhover, false);
    this.html.addEventListener('click', this.select, false);
}

/* Sends (self, selected) to callback on click */
function SelectionCell(html, odd, callback, object)
{
    /*
     * Default Color: #DDDDDD; (light gray)
     * Odd Id'd: Darken uniformly (-222222)
     * Hovered: Darken uniformly (-111111)
     * Selected: Set blue (|0000FF)
     */
    var self = this; // <- I hate javascript.
    this.hover = function()
    {
        self.hovered = true;
        if(self.selected) self.html.style.backgroundColor = '#AAAAFF';
        else self.html.style.backgroundColor = '#AAAAAA';
    };
    this.unhover = function()
    {
        self.hovered = false;
        if(self.odd)
        {
            if(self.selected) self.html.style.backgroundColor = '#BBBBFF';
            else self.html.style.backgroundColor = '#BBBBBB';
        }
        else
        {
            if(self.selected) self.html.style.backgroundColor = '#DDDDFF';
            else self.html.style.backgroundColor = '#DDDDDD';
        }
    };
    this.select = function()
    {
        self.selected = true;
        if(self.odd)
        {
            if(self.hovered) self.html.style.backgroundColor = '#AAAAFF';
            else self.html.style.backgroundColor = '#BBBBFF';
        }
        else
        {
            if(self.hovered) self.html.style.backgroundColor = '#CCCCFF';
            else self.html.style.backgroundColor = '#DDDDFF';
        }
    };
    this.deselect = function()
    {
        self.selected = false;
        if(self.odd)
        {
            if(self.hovered) self.html.style.backgroundColor = '#AAAAAA'
            else self.html.style.backgroundColor = '#BBBBBB';
        }
        else
        {
            if(self.hovered) self.html.style.backgroundColor = '#CCCCCC'
            else self.html.style.backgroundColor = '#DDDDDD';
        }
    };
    this.clicked = function()
    {
        self.callback(self, !self.selected);
        if(self.selected)self.deselect();
        else self.select();
    }

    this.hovered = false;
    this.selected = false;

    this.html = html;
    this.odd = odd;
    this.callback = callback;
    this.object = object;
    this.html.addEventListener('mouseover', this.hover, false);
    this.html.addEventListener('mouseout', this.unhover, false);
    this.html.addEventListener('click', this.clicked, false);

    this.deselect(); //give self odd coloring
}

/* Note- the callback is in charge of enforcing the single selection */
/* Sends (self) to callback on click */
function SingleSelectionCell(html, odd, callback, object)
{
    /*
     * Default Color: #DDDDDD; (light gray)
     * Odd Id'd: Darken uniformly (-222222)
     * Hovered: Darken uniformly (-111111)
     * Selected: Set blue (|0000FF)
     */
    var self = this; // <- I hate javascript.
    this.hover = function()
    {
        self.hovered = true;
        if(self.selected) self.html.style.backgroundColor = '#AAAAFF';
        else self.html.style.backgroundColor = '#AAAAAA';
    };
    this.unhover = function()
    {
        self.hovered = false;
        if(self.odd)
        {
            if(self.selected) self.html.style.backgroundColor = '#BBBBFF';
            else self.html.style.backgroundColor = '#BBBBBB';
        }
        else
        {
            if(self.selected) self.html.style.backgroundColor = '#DDDDFF';
            else self.html.style.backgroundColor = '#DDDDDD';
        }
    };
    this.select = function()
    {
        self.callback(self);
        self.selected = true;
        if(self.odd)
        {
            if(self.hovered) self.html.style.backgroundColor = '#AAAAFF';
            else self.html.style.backgroundColor = '#BBBBFF';
        }
        else
        {
            if(self.hovered) self.html.style.backgroundColor = '#CCCCFF';
            else self.html.style.backgroundColor = '#DDDDFF';
        }
    };
    this.deselect = function()
    {
        self.selected = false;
        if(self.odd)
        {
            if(self.hovered) self.html.style.backgroundColor = '#AAAAAA'
            else self.html.style.backgroundColor = '#BBBBBB';
        }
        else
        {
            if(self.hovered) self.html.style.backgroundColor = '#CCCCCC'
            else self.html.style.backgroundColor = '#DDDDDD';
        }
    };

    this.hovered = false;
    this.selected = false;

    this.html = html;
    this.odd = odd;
    this.callback = callback;
    this.object = object;
    this.html.addEventListener('mouseover', this.hover, false);
    this.html.addEventListener('mouseout', this.unhover, false);
    this.html.addEventListener('click', this.select, false);

    this.deselect(); //Set its color
}

function NoteView(html, object)
{
    this.html = html;
    this.object = object;

    this.constructHTML = function()
    {
        if(!this.object) return;

        //Ok. This next bit of codes is going to look ridiculous... but since the DOM has no easy way of heirarchical access, its the best I can think of.
        //I recommend opening 'index.html' and finding the xml defining 'note_view_construct' (the DOM node cloned to be this.html) as reference (vim command ':sp index.html')
        this.html.children[0].children[0].innerHTML = this.object.title;
        this.html.children[0].children[1].innerHTML = this.object.likes+' likes, '+this.object.comments.length+' comments';
        this.html.children[0].children[2].innerHTML = this.object.username;

        this.html.children[1].innerHTML = 'Tags: '+object.tagString;

        //Content
        for(var i = 0; i < this.object.contents.length; i++)
            this.html.children[2].appendChild(this.constructContentHTML(this.object.contents[i]));

        alert(JSON.stringify(this.object.comments));
        //Comments
        for(var i = 0; i < this.object.comments.length; i++)
            this.html.children[4].appendChild(this.constructCommentHTML(this.object.comments[i]));
    };

    this.constructContentHTML = function(content)
    {
        var contentHTML = document.getElementById('note_content_cell_construct').cloneNode(true);
        switch(content.type)
        {
            case 'TEXT':
                contentHTML.innerHTML = content.text;
                break;
            case 'PHOTO':
                contentHTML.innerHTML = '';
                break;
            case 'AUDIO':
                contentHTML.innerHTML = content.media_url;
                break;
            case 'VIDEO':
                contentHTML.innerHTML = content.media_url;
                break;
        }
        return contentHTML;
    };

    this.constructCommentHTML = function(comment)
    {
        var commentHTML = document.getElementById('note_comment_cell_construct').cloneNode(true);
        commentHTML.children[0].innerHTML = comment.username;
        commentHTML.appendChild(this.constructContentHTML({"type":"TEXT","text":comment.text}));
        for(var i = 0; i < comment.contents.length; i++)
            commentHTML.appendChild(this.constructContentHTML(comment.contents[i]));
        return commentHTML;
    }

    this.constructHTML();
}
<commit_msg>final attempt at comments<commit_after>function ActionButton(html, callback)
{
    /*
     * Default Color: #DDDDDD; (light gray)
     * Hovered: Darken uniformly (-111111)
     * Selected: Set blue (|0000FF)
     */
    var self = this; // <- I hate javascript.
    this.hover = function()
    {
        self.hovered = true;
        if(self.selected) self.html.style.backgroundColor = '#CCCCFF';
        else self.html.style.backgroundColor = '#CCCCCC';
    };
    this.unhover = function()
    {
        self.hovered = false;
        if(self.selected) self.html.style.backgroundColor = '#DDDDFF';
        else self.html.style.backgroundColor = '#DDDDDD';
    };
    this.select = function()
    {
        self.selected = true;
        if(self.hovered) self.html.style.backgroundColor = '#CCCCFF';
        else self.html.style.backgroundColor = '#DDDDFF';
    };
    this.deselect = function()
    {
        self.callback(self);
        self.selected = false;
        if(self.hovered) self.html.style.backgroundColor = '#CCCCCC'
        else self.html.style.backgroundColor = '#DDDDDD';
    };
    this.hovered = false;
    this.selected = false;

    this.html = html;
    this.callback = callback;
    this.html.addEventListener('mouseover', this.hover, false);
    this.html.addEventListener('mouseout', this.unhover, false);
    this.html.addEventListener('mousedown', this.select, false);
    this.html.addEventListener('mouseup', this.deselect, false);
}

/* Note- the callback is in charge of enforcing the single selection */
/* Sends (self) to callback on click */
function SingleSelectionButton(html, callback)
{
    /*
     * Default Color: #DDDDDD; (light gray)
     * Hovered: Darken uniformly (-111111)
     * Selected: Set blue (|0000FF)
     */
    var self = this; // <- I hate javascript.
    this.hover = function()
    {
        self.hovered = true;
        if(self.selected) self.html.style.backgroundColor = '#CCCCFF';
        else self.html.style.backgroundColor = '#CCCCCC';
    };
    this.unhover = function()
    {
        self.hovered = false;
        if(self.selected) self.html.style.backgroundColor = '#DDDDFF';
        else self.html.style.backgroundColor = '#DDDDDD';
    };
    this.select = function()
    {
        self.callback(self);
        self.selected = true;
        if(self.hovered) self.html.style.backgroundColor = '#CCCCFF';
        else self.html.style.backgroundColor = '#DDDDFF';
    };
    this.deselect = function()
    {
        self.selected = false;
        if(self.hovered) self.html.style.backgroundColor = '#CCCCCC'
        else self.html.style.backgroundColor = '#DDDDDD';
    };
    this.hovered = false;
    this.selected = false;

    this.html = html;
    this.callback = callback;
    this.html.addEventListener('mouseover', this.hover, false);
    this.html.addEventListener('mouseout', this.unhover, false);
    this.html.addEventListener('click', this.select, false);
}

/* Sends (self, selected) to callback on click */
function SelectionCell(html, odd, callback, object)
{
    /*
     * Default Color: #DDDDDD; (light gray)
     * Odd Id'd: Darken uniformly (-222222)
     * Hovered: Darken uniformly (-111111)
     * Selected: Set blue (|0000FF)
     */
    var self = this; // <- I hate javascript.
    this.hover = function()
    {
        self.hovered = true;
        if(self.selected) self.html.style.backgroundColor = '#AAAAFF';
        else self.html.style.backgroundColor = '#AAAAAA';
    };
    this.unhover = function()
    {
        self.hovered = false;
        if(self.odd)
        {
            if(self.selected) self.html.style.backgroundColor = '#BBBBFF';
            else self.html.style.backgroundColor = '#BBBBBB';
        }
        else
        {
            if(self.selected) self.html.style.backgroundColor = '#DDDDFF';
            else self.html.style.backgroundColor = '#DDDDDD';
        }
    };
    this.select = function()
    {
        self.selected = true;
        if(self.odd)
        {
            if(self.hovered) self.html.style.backgroundColor = '#AAAAFF';
            else self.html.style.backgroundColor = '#BBBBFF';
        }
        else
        {
            if(self.hovered) self.html.style.backgroundColor = '#CCCCFF';
            else self.html.style.backgroundColor = '#DDDDFF';
        }
    };
    this.deselect = function()
    {
        self.selected = false;
        if(self.odd)
        {
            if(self.hovered) self.html.style.backgroundColor = '#AAAAAA'
            else self.html.style.backgroundColor = '#BBBBBB';
        }
        else
        {
            if(self.hovered) self.html.style.backgroundColor = '#CCCCCC'
            else self.html.style.backgroundColor = '#DDDDDD';
        }
    };
    this.clicked = function()
    {
        self.callback(self, !self.selected);
        if(self.selected)self.deselect();
        else self.select();
    }

    this.hovered = false;
    this.selected = false;

    this.html = html;
    this.odd = odd;
    this.callback = callback;
    this.object = object;
    this.html.addEventListener('mouseover', this.hover, false);
    this.html.addEventListener('mouseout', this.unhover, false);
    this.html.addEventListener('click', this.clicked, false);

    this.deselect(); //give self odd coloring
}

/* Note- the callback is in charge of enforcing the single selection */
/* Sends (self) to callback on click */
function SingleSelectionCell(html, odd, callback, object)
{
    /*
     * Default Color: #DDDDDD; (light gray)
     * Odd Id'd: Darken uniformly (-222222)
     * Hovered: Darken uniformly (-111111)
     * Selected: Set blue (|0000FF)
     */
    var self = this; // <- I hate javascript.
    this.hover = function()
    {
        self.hovered = true;
        if(self.selected) self.html.style.backgroundColor = '#AAAAFF';
        else self.html.style.backgroundColor = '#AAAAAA';
    };
    this.unhover = function()
    {
        self.hovered = false;
        if(self.odd)
        {
            if(self.selected) self.html.style.backgroundColor = '#BBBBFF';
            else self.html.style.backgroundColor = '#BBBBBB';
        }
        else
        {
            if(self.selected) self.html.style.backgroundColor = '#DDDDFF';
            else self.html.style.backgroundColor = '#DDDDDD';
        }
    };
    this.select = function()
    {
        self.callback(self);
        self.selected = true;
        if(self.odd)
        {
            if(self.hovered) self.html.style.backgroundColor = '#AAAAFF';
            else self.html.style.backgroundColor = '#BBBBFF';
        }
        else
        {
            if(self.hovered) self.html.style.backgroundColor = '#CCCCFF';
            else self.html.style.backgroundColor = '#DDDDFF';
        }
    };
    this.deselect = function()
    {
        self.selected = false;
        if(self.odd)
        {
            if(self.hovered) self.html.style.backgroundColor = '#AAAAAA'
            else self.html.style.backgroundColor = '#BBBBBB';
        }
        else
        {
            if(self.hovered) self.html.style.backgroundColor = '#CCCCCC'
            else self.html.style.backgroundColor = '#DDDDDD';
        }
    };

    this.hovered = false;
    this.selected = false;

    this.html = html;
    this.odd = odd;
    this.callback = callback;
    this.object = object;
    this.html.addEventListener('mouseover', this.hover, false);
    this.html.addEventListener('mouseout', this.unhover, false);
    this.html.addEventListener('click', this.select, false);

    this.deselect(); //Set its color
}

function NoteView(html, object)
{
    this.html = html;
    this.object = object;

    this.constructHTML = function()
    {
        if(!this.object) return;

        //Ok. This next bit of codes is going to look ridiculous... but since the DOM has no easy way of heirarchical access, its the best I can think of.
        //I recommend opening 'index.html' and finding the xml defining 'note_view_construct' (the DOM node cloned to be this.html) as reference (vim command ':sp index.html')
        this.html.children[0].children[0].innerHTML = this.object.title;
        this.html.children[0].children[1].innerHTML = this.object.likes+' likes, '+this.object.comments.length+' comments';
        this.html.children[0].children[2].innerHTML = this.object.username;

        this.html.children[1].innerHTML = 'Tags: '+object.tagString;

        //Content
        for(var i = 0; i < this.object.contents.length; i++)
            this.html.children[2].appendChild(this.constructContentHTML(this.object.contents[i]));

        alert(JSON.stringify(this.object.comments));
        //Comments
        for(var i = 0; i < this.object.comments.length; i++)
            this.html.children[4].appendChild(this.constructCommentHTML(this.object.comments[i]));
    };

    this.constructContentHTML = function(content)
    {
        var contentHTML = document.getElementById('note_content_cell_construct').cloneNode(true);
        switch(content.type)
        {
            case 'TEXT':
                contentHTML.innerHTML = content.text;
                break;
            case 'PHOTO':
                contentHTML.innerHTML = '';
                break;
            case 'AUDIO':
                contentHTML.innerHTML = content.media_url;
                break;
            case 'VIDEO':
                contentHTML.innerHTML = content.media_url;
                break;
        }
        return contentHTML;
    };

    this.constructCommentHTML = function(comment)
    {
        var commentHTML = document.getElementById('note_comment_cell_construct').cloneNode(true);
        commentHTML.children[0].innerHTML = comment.username;
        commentHTML.appendChild(this.constructContentHTML({"type":"TEXT","text":comment.title}));
        for(var i = 0; i < comment.contents.length; i++)
            commentHTML.appendChild(this.constructContentHTML(comment.contents[i]));
        return commentHTML;
    }

    this.constructHTML();
}
<|endoftext|>


<commit_before>const beard = require('../lib/index');
const fs = require('fs');
const chai = require('chai');
const { assert, expect } = chai;
chai.use(require('chai-string'));

const read = (file) => fs.readFileSync(`${__dirname}/../.beard/${file}`, 'utf8').trim();
const contents = (path, ext) => {
  const files = fs.readdirSync(`${__dirname}/../.beard`);
  const file = files.find(file => new RegExp(`${path}\.[^\.]+\.${ext}`).test(file));
  return fs.readFileSync(`${__dirname}/../.beard/${file}`, 'utf8').trim().replace(/\s+/g, ' ');
}

const engine = beard({ root: __dirname });

chai.use(function (chai, utils) {
  const Assertion = chai.Assertion;

  Assertion.addMethod('matchScoped', function (expected) {
    const hashRegex = new RegExp(expected.replace(/\$b/gm, '(b\-[0-9a-fA-F]{6})'));
    new Assertion(this._obj).to.match(hashRegex);
  });
});

// const hashRegex = (actual, expected) => {
//   const hashedExpected = expected.replace(/\$b/gm, '(b\-[0-9a-fA-F]{8})');
//   assert(new RegExp(hashedExpected).test(actual), `Expected ${actual} to be ${expected}`);
// }
// chai.Assertion.addChainableMethod('matchHashedHTML', hashRegex, chainingBehavior);
// expect(fooStr).to.be.foo('bar');
// expect(fooStr).to.be.foo.equal('foo');

describe('Bundling', function() {
  it('renders a simple bundled file', function() {
    expect(engine.render('templates/simple')).to.equal(' simple ');
  });

  it('extracts style blocks into scss asset files and imports them in the entry file', function() {
    expect(engine.render('templates/simple')).to.not.include('body { color: blue; }');
    expect(contents('simple', 'scss')).to.equalIgnoreSpaces('body { color: blue; }');
    expect(read('entry.css')).to.include("@import './simple.");
  });

  it('extracts frontend script blocks into js asset files and imports them in the entry file', function() {
    expect(engine.render('templates/simple')).to.not.include("document.getElementById('demo').innerHTML = 'hello';");
    expect(contents('simple', 'js')).to.equalIgnoreSpaces("document.getElementById('demo').innerHTML = 'hello';");
    expect(read('entry.js')).to.include("import './simple.");
  });

  it('extracts the ssjs script block', function() {
    expect(contents('simple', 'ssjs.js')).to.equalIgnoreSpaces("const foo = 'boo';");
  });

  describe('when script or style block has bundle attribute', function() {
    it('creates a custom bundle entry file', function() {
      expect(read('alert.css')).to.includes("@import './named-bundle.");
      expect(read('alert.js')).to.includes("import './named-bundle.");
    });
  });

  describe('when script or style block has multiple bundle values in the bundle attribute', function() {
    it('creates a custom bundle entry file', function() {
      expect(read('alert.css')).to.includes("@import './multiple-bundles.");
      expect(read('info.css')).to.includes("@import './multiple-bundles.");
      expect(read('alert.js')).to.includes("import './multiple-bundles.");
      expect(read('main.js')).to.includes("import './multiple-bundles.");
    });
  });

  describe('when script block has inline attribute', function() {
    it('leaves the script tag in the template', function() {
      expect(engine.render('templates/inline-js')).to.
        equalIgnoreSpaces("
content
 ");
    });
  });

  describe('when style block is scoped', function() {
    it('sets custom css class names on css styles and on html elements', function() {
      expect(engine.render('templates/scoped')).to.matchScoped('test');
      expect(contents('scoped', 'scss')).to.matchScoped('span.$b { color: green; }');
    });

    it('does not set custom css class names on nested css styles', function() {
      expect(engine.render('templates/scoped-nested')).to.matchScoped(' test
These tacos are amazin!
 ');
      expect(contents('scoped-nested', 'scss')).to.matchScoped('span.$b { color: green; } h1.$b { color: blue; em { font-style: italic; } }');
    });

    it('handles regular media elements', function() {
      expect(contents('media-queries', 'scss')).to.matchScoped('@page { color: green; font-size: 14px; }');
    });

    it('sets custom css class names on nested styles in media elements', function() {
      expect(engine.render('templates/scoped-media-queries')).to.matchScoped(' test ');
      expect(contents('scoped-media-queries', 'scss')).to.matchScoped('@media screen {body.$b { color: green; } span.$b { color: green; }}');
    });

    it('sets custom css class names before deep selector', function() {
      expect(engine.render('templates/scoped-deep')).to.matchScoped('
hello
');
      expect(contents('scoped-deep', 'scss')).to.matchScoped('h1.$b em { color: red; }');
    });

    it('sets custom css class names on chained selectors', function() {
      expect(engine.render('templates/scoped-chaining')).to.matchScoped('
hello h1

hello h4

hello div
');
      expect(contents('scoped-chaining', 'scss')).to.matchScoped('h1.$b em.$b, h4.$b em.$b:first-of-type, div.$b em.$b { color: green; }');
    });

    it('sets custom css class names selectors with pseudo elements', function() {
      expect(engine.render('templates/scoped-pseudo-elements')).to.matchScoped('

nacho libre

hello world

hello h1

hello h4

hello world

nacho libre

');
      expect(contents('scoped-pseudo-elements', 'scss')).to.matchScoped('h1.$b em.$b, h4.$b em.$b:before { color: green; } h4.$b em.$b::before { color: green; } .Text.$b:first-child > p.$b:first-child :first-child { background-color: #ff3300; } .Text.$b:first-child > p.$b:first-child:first-letter { background-color: #ff3300; } .Text.$b:first-of-type { background-color: #aae; }');
    });

    it('ignores commented styles', function() {
      expect(contents('commented-styles', 'scss')).to
        .eq('.Major { padding-bottom: var(--space-xxl); background-color: var(--major-color); } .foo { color: blue; } .header { color: red; } .content { color: orange; size: 15px; }');
    });
  });
});
<commit_msg>Update all scss extensions to css in bundling tests<commit_after>const beard = require('../lib/index');
const fs = require('fs');
const chai = require('chai');
const { assert, expect } = chai;
chai.use(require('chai-string'));

const read = (file) => fs.readFileSync(`${__dirname}/../.beard/${file}`, 'utf8').trim();
const contents = (path, ext) => {
  const files = fs.readdirSync(`${__dirname}/../.beard`);
  const file = files.find(file => new RegExp(`${path}\.[^\.]+\.${ext}`).test(file));
  return fs.readFileSync(`${__dirname}/../.beard/${file}`, 'utf8').trim().replace(/\s+/g, ' ');
}

const engine = beard({ root: __dirname });

chai.use(function (chai, utils) {
  const Assertion = chai.Assertion;

  Assertion.addMethod('matchScoped', function (expected) {
    const hashRegex = new RegExp(expected.replace(/\$b/gm, '(b\-[0-9a-fA-F]{6})'));
    new Assertion(this._obj).to.match(hashRegex);
  });
});

// const hashRegex = (actual, expected) => {
//   const hashedExpected = expected.replace(/\$b/gm, '(b\-[0-9a-fA-F]{8})');
//   assert(new RegExp(hashedExpected).test(actual), `Expected ${actual} to be ${expected}`);
// }
// chai.Assertion.addChainableMethod('matchHashedHTML', hashRegex, chainingBehavior);
// expect(fooStr).to.be.foo('bar');
// expect(fooStr).to.be.foo.equal('foo');

describe('Bundling', function() {
  it('renders a simple bundled file', function() {
    expect(engine.render('templates/simple')).to.equal(' simple ');
  });

  it('extracts style blocks into scss asset files and imports them in the entry file', function() {
    expect(engine.render('templates/simple')).to.not.include('body { color: blue; }');
    expect(contents('simple', 'css')).to.equalIgnoreSpaces('body { color: blue; }');
    expect(read('entry.css')).to.include("@import './simple.");
  });

  it('extracts frontend script blocks into js asset files and imports them in the entry file', function() {
    expect(engine.render('templates/simple')).to.not.include("document.getElementById('demo').innerHTML = 'hello';");
    expect(contents('simple', 'js')).to.equalIgnoreSpaces("document.getElementById('demo').innerHTML = 'hello';");
    expect(read('entry.js')).to.include("import './simple.");
  });

  it('extracts the ssjs script block', function() {
    expect(contents('simple', 'ssjs.js')).to.equalIgnoreSpaces("const foo = 'boo';");
  });

  describe('when script or style block has bundle attribute', function() {
    it('creates a custom bundle entry file', function() {
      expect(read('alert.css')).to.includes("@import './named-bundle.");
      expect(read('alert.js')).to.includes("import './named-bundle.");
    });
  });

  describe('when script or style block has multiple bundle values in the bundle attribute', function() {
    it('creates a custom bundle entry file', function() {
      expect(read('alert.css')).to.includes("@import './multiple-bundles.");
      expect(read('info.css')).to.includes("@import './multiple-bundles.");
      expect(read('alert.js')).to.includes("import './multiple-bundles.");
      expect(read('main.js')).to.includes("import './multiple-bundles.");
    });
  });

  describe('when script block has inline attribute', function() {
    it('leaves the script tag in the template', function() {
      expect(engine.render('templates/inline-js')).to.
        equalIgnoreSpaces("
content
 ");
    });
  });

  describe('when style block is scoped', function() {
    it('sets custom css class names on css styles and on html elements', function() {
      expect(engine.render('templates/scoped')).to.matchScoped('test');
      expect(contents('scoped', 'css')).to.matchScoped('span.$b { color: green; }');
    });

    it('does not set custom css class names on nested css styles', function() {
      expect(engine.render('templates/scoped-nested')).to.matchScoped(' test
These tacos are amazin!
 ');
      expect(contents('scoped-nested', 'css')).to.matchScoped('span.$b { color: green; } h1.$b { color: blue; em { font-style: italic; } }');
    });

    it('handles regular media elements', function() {
      expect(contents('media-queries', 'css')).to.matchScoped('@page { color: green; font-size: 14px; }');
    });

    it('sets custom css class names on nested styles in media elements', function() {
      expect(engine.render('templates/scoped-media-queries')).to.matchScoped(' test ');
      expect(contents('scoped-media-queries', 'css')).to.matchScoped('@media screen {body.$b { color: green; } span.$b { color: green; }}');
    });

    it('sets custom css class names before deep selector', function() {
      expect(engine.render('templates/scoped-deep')).to.matchScoped('
hello
');
      expect(contents('scoped-deep', 'css')).to.matchScoped('h1.$b em { color: red; }');
    });

    it('sets custom css class names on chained selectors', function() {
      expect(engine.render('templates/scoped-chaining')).to.matchScoped('
hello h1

hello h4

hello div
');
      expect(contents('scoped-chaining', 'css')).to.matchScoped('h1.$b em.$b, h4.$b em.$b:first-of-type, div.$b em.$b { color: green; }');
    });

    it('sets custom css class names selectors with pseudo elements', function() {
      expect(engine.render('templates/scoped-pseudo-elements')).to.matchScoped('

nacho libre

hello world

hello h1

hello h4

hello world

nacho libre

');
      expect(contents('scoped-pseudo-elements', 'css')).to.matchScoped('h1.$b em.$b, h4.$b em.$b:before { color: green; } h4.$b em.$b::before { color: green; } .Text.$b:first-child > p.$b:first-child :first-child { background-color: #ff3300; } .Text.$b:first-child > p.$b:first-child:first-letter { background-color: #ff3300; } .Text.$b:first-of-type { background-color: #aae; }');
    });

    it('ignores commented styles', function() {
      expect(contents('commented-styles', 'css')).to
        .eq('.Major { padding-bottom: var(--space-xxl); background-color: var(--major-color); } .foo { color: blue; } .header { color: red; } .content { color: orange; size: 15px; }');
    });
  });
});
<|endoftext|>


<commit_before>import React from 'react';
import Radium from 'radium';

import Page from '../Page/Page';
import Style from './_ContactPage.Style';

class ContactPage extends React.Component {

  render() {
    return (
      <Page title='Contact'>

          {/* Contact Details*/}

Mailing Address

PO Box 10
Ft. Howard, MD 21052

Physical Address

4640 Northpoint Blvd.
Edgemere, MD 21219

Telephone

410-388-1100

Facsimile

410-388-2742

Toll Free Fax

800-742-2246

Email

Michele Dosch: michele@bandbwelding.com

          {/* Directions */}

Directions to the Shop

From the West or Northwest:

Take I-695 South around Baltimore to the Key Bridge. Pay toll then exit onto #43. At head of ramp, turn left onto MD 158 (Beth Blvd). Take MD 158 to MD 151, turn left, go 0.3 miles, immediately after passing under railroad bridge, make right turn into B&B Welding.

From the East or Northeast:

Take I-695 South around Baltimore to exit #42. At the head of the ramp, turn North onto Md. 151 for 110 yds under railroad bridge and immediately turn right into B&B Welding Company.

      </Page>
    );
  }
}

export default Radium(ContactPage);
<commit_msg>Added contact<commit_after>import React from 'react';
import Radium from 'radium';

import Page from '../Page/Page';
import Style from './_ContactPage.Style';

class ContactPage extends React.Component {

  render() {
    return (
      <Page title='Contact'>

          {/* Contact Details*/}

Mailing Address

PO Box 10
Ft. Howard, MD 21052

Physical Address

4640 Northpoint Blvd.
Edgemere, MD 21219

Telephone

410-388-1100

Facsimile

410-388-2742

Toll Free Fax

800-742-2246

Email

Michele Dosch: michele@bandbwelding.com

Estimating - Dave Mills Sr: dave@bandbwelding.com

          {/* Directions */}

Directions to the Shop

From the West or Northwest:

Take I-695 South around Baltimore to the Key Bridge. Pay toll then exit onto #43. At head of ramp, turn left onto MD 158 (Beth Blvd). Take MD 158 to MD 151, turn left, go 0.3 miles, immediately after passing under railroad bridge, make right turn into B&B Welding.

From the East or Northeast:

Take I-695 South around Baltimore to exit #42. At the head of the ramp, turn North onto Md. 151 for 110 yds under railroad bridge and immediately turn right into B&B Welding Company.

      </Page>
    );
  }
}

export default Radium(ContactPage);
<|endoftext|>


<commit_before>import $events from 'wee-events';
import { _doc, _win } from 'core/variables';
import { $copy, $extend, $isObject } from 'core/types';
import { $exec } from 'core/core';
import { $each, $parseHTML, $setRef } from 'core/dom';
import { $serializeForm } from 'dom/index';
import { supportsPushState } from './push-state';
import $fetch from 'wee-fetch';
import $ from 'wee-dom';
import { warn } from 'core/warn';
import { parseLocation } from './location';
import { $setVar } from 'wee-store';

let defaults = {
	action: 'replace',
	bind: {
		click: 'a'
	},
	context: 'document',
	fetch: $fetch.create(),
	partials: ['title', 'main'],
	request: {
		method: 'get',
		responseType: 'text',
		headers: {
			'X-PJAX': 'true'
		}
	},
	replace: null
};
let overrides = {
	partials: false
};
export let settings = $copy(defaults);
let response = null;
let paused = false;

/**
 * Determine if path is valid for history navigation
 *
 * @param {HTMLElement} el
 * @param {string} [currentPath]
 * @returns {boolean}
 * @private
 */
function _isValid(el, currentPath) {
	// Link has no destination URL
	if (! el.href) { return false; }

	// Link opens a new browser window
	if (el.target === '_blank') { return false; }

	// Link is not absolute URL
	if (! /https?:/.test(el.href)) { return false; }

	// Link is a download
	if (el.hasAttribute('download')) { return false; }

	// Link is supposed to be ignored
	if (el.hasAttribute('data-static')) { return false; }

	// Link is external URL
	if (el.host && el.host !== location.host) { return false; }

	// Link is current page, but with a hash added
	if (el.hash && el.pathname === currentPath) { return false; }

	return true;
}

/**
 * Return current path
 *
 * @private
 * @param {object} [loc]
 * @returns {string}
 */
function _path(loc) {
	loc = loc || location;
	return loc.pathname + loc.search + loc.hash;
}

/**
 * Reset references and variables for a given selector
 *
 * @private
 * @param sel
 */
function _reset(sel) {
	response = null;
	$setRef(sel);
	$setVar(sel);

	pjax.bind(sel);
}

const pjax = {
	_setWindowLocation(location) {
		_win.location = location;
	},

	// Empty callbacks - will be defined by router.pjax
	onError() {},
	onTrigger() {},

	/**
	 * Bind element events and form submit events to callback
	 *
	 * @param {($|HTMLElement|string)} [context=document]
	 */
	bind(context) {
		const current = parseLocation();
		const events = settings.bind;
		context = context || settings.context;

		if (supportsPushState()) {
			const keys = Object.keys(events);
			let i = 0;

			// Iterate through events to be bound
			for (; i < keys.length; i++) {
				const event = keys[i];
				const sel = events[event];

				$each(sel, el => {
					const evts = event.split(' ').map(val => {
							return val + '.pjax';
						}).join(' ');

					// Retrieve data-url off of element
					// Used if element is not  tag
					const loc = el.getAttribute('data-url');
					let destination = el;

					// Create  tag for validation of URL
					if (loc) {
						let attrs = el.attributes;
						let j = 0;
						let attr;

						destination = _doc.createElement('a');

						// Clone attributes from bound element to new a tag
						for (; j < attrs.length; j++) {
							attr = attrs[j];
							destination.setAttribute(attr.name, attr.value);
						}

						// Set URL
						destination.href = loc;
					}

					// Ensure the path exists and is local
					if (! evts || ! _isValid(destination, current.path)) {
						// TODO: Make this print as verbose only
						// warn('routes', 'PJAX: no events provided or invalid destination URL ' + destination.href);
						return;
					}

					// TODO: Make this reset optional so we can use 'bind' dynamically
					// Remove existing pjax events
					$events.off(el, '.pjax');

					// Bind designated events
					$events.on(el, evts, e => {
						if (paused) {
							warn('routes', 'pjax has been paused - will not trigger navigation');
							return;
						}

						// Don't navigate with control keys
						if (e.metaKey || e.ctrlKey || e.shiftKey) { return; }

						// Don't navigate when preventDefault already called
						if (e.defaultPrevented) { return; }

						// Don't navigate on right click
						if (e.button !== undefined && e.button !== 0) { return; }

						let path = _path(destination);

						e.preventDefault();

						this.onTrigger(path);
					});
				}, {
					context: context
				});
			}
		}
	},

	go(to, from, next) {
		if (paused) {
			warn('routes', 'pjax has been paused - will not request partials');
			return next();
		}

		let request = settings.request;

		// Navigate to external URL or if history isn't supported
		let a = _doc.createElement('a');
		a.href = to.url;

		if (! supportsPushState() || ! _isValid(a, from.fullPath)) {
			// Will trigger full page reload
			this._setWindowLocation(to.fullPath);
			return false;
		}

		request.url = to.fullPath;

		settings.fetch(request)
			.then(res => {
				response = res;
				next();
			})
			.catch(error => {
				next(error);
			});
	},

	/**
	 * Apply configuration
	 *
	 * @param {Object} options
	 */
	init(options = {}) {
		if (supportsPushState()) {
			if (options.onError) {
				this.onError = options.onError;
				delete options.onError;
			}

			settings = $extend(settings, options);

			// https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration
			if ('scrollRestoration' in _win.history) {
				_win.history.scrollRestoration = 'manual';
			}

			// Bind all designated elements to trigger navigation
			this.bind();

			return true;
		}

		return false;
	},

	/**
	 * Inform if pjax is currently paused
	 *
	 * @returns {boolean}
	 */
	isPaused() {
		return paused;
	},

	/**
	 * Override partials to be replaced
	 *
	 * @param partials
	 */
	override(options) {
		if (options.partials) {
			overrides.partials = options.partials;
		}
	},

	/**
	 * Pause previously bound pjax from triggering
	 */
	pause() {
		paused = true;
	},

	/**
	 * Replace target partials on DOM
	 */
	replace() {
		let partials = overrides.partials || settings.partials;

		if (paused) {
			warn('routes', 'pjax has been paused - will not replace partials');
			return;
		}

		if (! response) {
			warn('routes', 'no response to use for partial replacement');
			return;
		}

		let html = response.data;

		if (settings.replace) {
			$exec(settings.replace, {
				args: [html, settings]
			});
		}

		html = $parseHTML('' + html + '').firstChild;

		// Make partial replacements from response
		$each(partials, sel => {
			$each(sel, function(el) {
				const target = $(sel)[0];

				// Retain any classes added dynamically to container
				el.className = target.className;

				if (target) {
					const parent = target.parentNode;

					target.innerHTML = el.innerHTML

					_reset(parent);
				}
			}, {
				context: html
			});
		});
	},

	/**
	 * Reset module back to default settings
	 */
	reset() {
		settings = $copy(defaults);
	},

	/**
	 * Resume pjax to normal operating status
	 */
	resume() {
		paused = false;
		overrides = {
			partials: false
		};
	}
};

export default pjax;<commit_msg>Fix issue with router push<commit_after>import $events from 'wee-events';
import { _doc, _win } from 'core/variables';
import { $copy, $extend, $isObject } from 'core/types';
import { $exec } from 'core/core';
import { $each, $parseHTML, $setRef } from 'core/dom';
import { $serializeForm } from 'dom/index';
import { supportsPushState } from './push-state';
import $fetch from 'wee-fetch';
import $ from 'wee-dom';
import { warn } from 'core/warn';
import { parseLocation } from './location';
import { $setVar } from 'wee-store';

let defaults = {
	action: 'replace',
	bind: {
		click: 'a'
	},
	context: 'document',
	fetch: $fetch.create(),
	partials: ['title', 'main'],
	request: {
		method: 'get',
		responseType: 'text',
		headers: {
			'X-PJAX': 'true'
		}
	},
	replace: null
};
const overrideDefaults = {
	partials: false,
	requestCount: 0
};
let overrides = $copy(overrideDefaults);
export let settings = $copy(defaults);
let response = null;
let paused = false;

/**
 * Determine if path is valid for history navigation
 *
 * @param {HTMLElement} el
 * @param {string} [currentPath]
 * @returns {boolean}
 * @private
 */
function _isValid(el, currentPath) {
	// Link has no destination URL
	if (! el.href) { return false; }

	// Link opens a new browser window
	if (el.target === '_blank') { return false; }

	// Link is not absolute URL
	if (! /https?:/.test(el.href)) { return false; }

	// Link is a download
	if (el.hasAttribute('download')) { return false; }

	// Link is supposed to be ignored
	if (el.hasAttribute('data-static')) { return false; }

	// Link is external URL
	if (el.host && el.host !== location.host) { return false; }

	// Link is current page, but with a hash added
	if (el.hash && el.pathname === currentPath) { return false; }

	return true;
}

/**
 * Return current path
 *
 * @private
 * @param {object} [loc]
 * @returns {string}
 */
function _path(loc) {
	loc = loc || location;
	return loc.pathname + loc.search + loc.hash;
}

/**
 * Reset references and variables for a given selector
 *
 * @private
 * @param sel
 */
function _reset(sel) {
	response = null;
	$setRef(sel);
	$setVar(sel);

	pjax.bind(sel);
}

const pjax = {
	_setWindowLocation(location) {
		_win.location = location;
	},

	// Empty callbacks - will be defined by router.pjax
	onError() {},
	onTrigger() {},

	/**
	 * Bind element events and form submit events to callback
	 *
	 * @param {($|HTMLElement|string)} [context=document]
	 */
	bind(context) {
		const current = parseLocation();
		const events = settings.bind;
		context = context || settings.context;

		if (supportsPushState()) {
			const keys = Object.keys(events);
			let i = 0;

			// Iterate through events to be bound
			for (; i < keys.length; i++) {
				const event = keys[i];
				const sel = events[event];

				$each(sel, el => {
					const evts = event.split(' ').map(val => {
							return val + '.pjax';
						}).join(' ');

					// Retrieve data-url off of element
					// Used if element is not  tag
					const loc = el.getAttribute('data-url');
					let destination = el;

					// Create  tag for validation of URL
					if (loc) {
						let attrs = el.attributes;
						let j = 0;
						let attr;

						destination = _doc.createElement('a');

						// Clone attributes from bound element to new a tag
						for (; j < attrs.length; j++) {
							attr = attrs[j];
							destination.setAttribute(attr.name, attr.value);
						}

						// Set URL
						destination.href = loc;
					}

					// Ensure the path exists and is local
					if (! evts || ! _isValid(destination, current.path)) {
						// TODO: Make this print as verbose only
						// warn('routes', 'PJAX: no events provided or invalid destination URL ' + destination.href);
						return;
					}

					// TODO: Make this reset optional so we can use 'bind' dynamically
					// Remove existing pjax events
					$events.off(el, '.pjax');

					// Bind designated events
					$events.on(el, evts, e => {
						if (paused) {
							warn('routes', 'pjax has been paused - will not trigger navigation');
							return;
						}

						// Don't navigate with control keys
						if (e.metaKey || e.ctrlKey || e.shiftKey) { return; }

						// Don't navigate when preventDefault already called
						if (e.defaultPrevented) { return; }

						// Don't navigate on right click
						if (e.button !== undefined && e.button !== 0) { return; }

						let path = _path(destination);

						e.preventDefault();

						this.onTrigger(path);
					});
				}, {
					context: context
				});
			}
		}
	},

	go(to, from, next) {
		if (paused) {
			warn('routes', 'pjax has been paused - will not request partials');
			return next();
		}

		let request = settings.request;
		settings.lastRequestUrl = to.fullPath;

		// Navigate to external URL or if history isn't supported
		let a = _doc.createElement('a');
		a.href = to.url;

		if (! supportsPushState() || ! _isValid(a, from.fullPath)) {
			// Will trigger full page reload
			this._setWindowLocation(to.fullPath);
			return false;
		}

		request.url = to.fullPath;

		settings.fetch(request)
			.then(res => {
				response = res;
				next();
			})
			.catch(error => {
				next(error);
			});
	},

	/**
	 * Apply configuration
	 *
	 * @param {Object} options
	 */
	init(options = {}) {
		if (supportsPushState()) {
			if (options.onError) {
				this.onError = options.onError;
				delete options.onError;
			}

			settings = $extend(settings, options);

			// https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration
			if ('scrollRestoration' in _win.history) {
				_win.history.scrollRestoration = 'manual';
			}

			// Bind all designated elements to trigger navigation
			this.bind();

			return true;
		}

		return false;
	},

	/**
	 * Inform if pjax is currently paused
	 *
	 * @returns {boolean}
	 */
	isPaused() {
		return paused;
	},

	/**
	 * Override partials to be replaced
	 *
	 * @param partials
	 */
	override(options) {
		if (options.partials) {
			overrides.partials = options.partials;
		}

		overrides.requestCount += 1;
	},

	/**
	 * Pause previously bound pjax from triggering
	 */
	pause() {
		paused = true;
	},

	/**
	 * Replace target partials on DOM
	 */
	replace() {
		let partials = overrides.partials || settings.partials;

		if (paused) {
			warn('routes', 'pjax has been paused - will not replace partials');
			return;
		}

		if (! response) {
			warn('routes', 'no response to use for partial replacement');
			return;
		}

		let html = response.data;

		if (settings.replace) {
			$exec(settings.replace, {
				args: [html, settings]
			});
		}

		html = $parseHTML('' + html + '').firstChild;

		// Make partial replacements from response
		$each(partials, sel => {
			$each(sel, function(el) {
				const target = $(sel)[0];

				// Retain any classes added dynamically to container
				el.className = target.className;

				if (target) {
					const parent = target.parentNode;

					target.innerHTML = el.innerHTML

					_reset(parent);
				}
			}, {
				context: html
			});
		});
	},

	/**
	 * Reset module back to default settings
	 */
	reset() {
		settings = $copy(defaults);
	},

	/**
	 * Resume pjax to normal operating status
	 */
	resume() {
		if (overrides.requestCount > 0) {
			overrides.requestCount -= 1;
		}

		if (overrides.requestCount === 0) {
			paused = false;
			overrides = $copy(overrideDefaults);
		}
	}
};

export default pjax;<|endoftext|>


<commit_before>'use strict';

/* Directives */

var app = angular.module('myApp.directives', []);

app.directive('appVersion', ['version', function(version) {
        return function(scope, elm, attrs) {
            elm.text(version);
        };
    }]);

app.directive('editor', function($timeout) {
    var editorWindow = angular.element('
{{file.content}}
');
    return {
        restrict: 'E',
        compile: function(elem) {
            elem.append(editorWindow);

            return function(scope, element, attrs) {

                $timeout(function() {

                    var lang = attrs.language,
                            editor = ace.edit('editor-' + attrs.index);

                    console.log({language: lang});

                    editor.setTheme("ace/theme/tomorrow");
                    editor.getSession().setMode("ace/mode/" + lang);

                    editor.on('change', function(data) {
                        scope.file.content = editor.getValue();
                    });

                }, 0);
            }
        }

    };
});

module.directive('unfocus', function() {
    return {
        restrict: 'A',
        link: function(scope, element, attribs) {

            element[0].focus();

            element.bind("blur", function() {
                scope.$apply(attribs["unfocus"]);
                console.log("??");
            });

        }

    }
});

//
//
//    return function(scope, element, attrs) {
//        $timeout(function() {
//            var lang = attrs.editor;
//            var editor = ace.edit(element[0]);
//            editor.setTheme("ace/theme/tomorrow");
//            editor.getSession().setMode("ace/mode/" + lang);
//
//            editor.on('change', function(data) {
//               console.log(editor.getValue());
//
//            });
//
//        }, 0);
//    };
//});<commit_msg>Fix the error in console() - Maayan is unhappy.<commit_after>'use strict';

/* Directives */

var app = angular.module('myApp.directives', []);

app.directive('appVersion', ['version', function(version) {
        return function(scope, elm, attrs) {
            elm.text(version);
        };
    }]);

app.directive('editor', function($timeout) {
    var editorWindow = angular.element('
{{file.content}}
');
    return {
        restrict: 'E',
        compile: function(elem) {
            elem.append(editorWindow);

            return function(scope, element, attrs) {

                $timeout(function() {

                    var lang = attrs.language,
                            editor = ace.edit('editor-' + attrs.index);

                    console.log({language: lang});

                    editor.setTheme("ace/theme/tomorrow");
                    editor.getSession().setMode("ace/mode/" + lang);

                    editor.on('change', function(data) {
                        scope.file.content = editor.getValue();
                    });

                }, 0);
            }
        }

    };
});

app.directive('unfocus', function() {
    return {
        restrict: 'A',
        link: function(scope, element, attribs) {

            element[0].focus();

            element.bind("blur", function() {
                scope.$apply(attribs["unfocus"]);
                console.log("??");
            });

        }

    };
});

//
//
//    return function(scope, element, attrs) {
//        $timeout(function() {
//            var lang = attrs.editor;
//            var editor = ace.edit(element[0]);
//            editor.setTheme("ace/theme/tomorrow");
//            editor.getSession().setMode("ace/mode/" + lang);
//
//            editor.on('change', function(data) {
//               console.log(editor.getValue());
//
//            });
//
//        }, 0);
//    };
//});<|endoftext|>


<commit_before>//= require social_stream/wall

SocialStream.Documents.Wall = (function(SS, $, undefined) {
  var initWall = function() {
    $('<label/>', {
      "for": 'new_document_title',
      style: 'display: none;',
      text: I18n.t('activerecord.attributes.document.title')
    }).insertBefore($('#post_text'));

    $('<textarea/>', {
      name: 'document[description]',
      id: 'new_document_description',
      'class': 'document_description',
      style: 'display: none;',
      placeholder: I18n.t('document.description.input')
    }).insertAfter($('#post_text'));

    $('.wall_input form').
      attr('enctype', 'multipart/form-data'); // this is ignored if done after creating the file input

    $('<input>', {
      name: 'document[file]',
      type: 'file',
      style: 'visibility: hidden;'
    }).insertAfter('.wall_input textarea.document_description');

    $('.wall_input button.new_document').click(function(event){
      event.preventDefault();

      $('label[for="new_document_title"]').show();

      $('#post_text').
        attr('name', 'document[title]').
        attr('placeholder', I18n.t('document.title.input'));

      $('#new_document_description').show().val($('#post_text').val());

      SocialStream.Wall.changeAction($(this).attr('data-path'));

      SocialStream.Wall.changeOwner('document');
      SocialStream.Wall.changeRelationSelect('document');

      $('.wall_input input[type=file]').trigger('click');
    });

    $('.wall_input input[type=file]').change(function(){
      $("#post_text").val($(this).val().replace(/C:\\fakepath\\/i, ''));
    });
  };

  SS.Wall.callbackRegister('show', initWall);
})(SocialStream, jQuery);
<commit_msg>position added<commit_after>//= require social_stream/wall

SocialStream.Documents.Wall = (function(SS, $, undefined) {
  var initWall = function() {
    $('<label/>', {
      "for": 'new_document_title',
      style: 'display: none;',
      text: I18n.t('activerecord.attributes.document.title')
    }).insertBefore($('#post_text'));

    $('<textarea/>', {
      name: 'document[description]',
      id: 'new_document_description',
      'class': 'document_description',
      style: 'display: none;',
      placeholder: I18n.t('document.description.input')
    }).insertAfter($('#post_text'));

    $('.wall_input form').
      attr('enctype', 'multipart/form-data'); // this is ignored if done after creating the file input

    $('<input>', {
      name: 'document[file]',
      type: 'file',
      style: 'visibility: hidden; position: absolute'
    }).insertAfter('.wall_input textarea.document_description');

    $('.wall_input button.new_document').click(function(event){
      event.preventDefault();

      $('label[for="new_document_title"]').show();

      $('#post_text').
        attr('name', 'document[title]').
        attr('placeholder', I18n.t('document.title.input'));

      $('#new_document_description').show().val($('#post_text').val());

      SocialStream.Wall.changeAction($(this).attr('data-path'));

      SocialStream.Wall.changeOwner('document');
      SocialStream.Wall.changeRelationSelect('document');

      $('.wall_input input[type=file]').trigger('click');
    });

    $('.wall_input input[type=file]').change(function(){
      $("#post_text").val($(this).val().replace(/C:\\fakepath\\/i, ''));
    });
  };

  SS.Wall.callbackRegister('show', initWall);
})(SocialStream, jQuery);
<|endoftext|>


<commit_before>'use strict';

var Promise = require("bluebird"),
    _ = require('lodash'),
    mongodb = require('mongodb'),
    timeEngine = require('./timeEngine'),
    processing = {
        issues: [],
        comments: []
    };

var includeIssues = (client, repo, filter) => {
    return new Promise(function(resolve, reject) {
        var ghrepo = client.repo(repo.full_name);
        ghrepo.issues({
            since: (new Date(filter.from)).toISOString()
        }, function(error, issues) {
            _.each(issues, function(issue) {
                if (issue.comments > 0) {
                    processing.comments.push(includeComments(client, repo, issue, filter.user));
                } else {
                    issue.time_entry = 0;
                }
            });
            Promise.all(processing.comments).then(function() {
                repo.issues = issues;
                repo.time_entry = timeEngine.repoTime(issues);
                error ? reject(error) : resolve(issues);
            });
        });
    });
};

var includeComments = (client, repo, issue, user) => {
    return new Promise(function(resolve, reject) {
        var ghissue = client.issue(repo.full_name, issue.number);
        ghissue.comments(function(error, comments) {
            issue.comments = !user ? comments : _.filter(comments, (comment) => {
                return comment.user.login.toLowerCase() === user.toLowerCase()
            });
            issue.time_entry = timeEngine.issueTime(comments);
            error ? reject(error) : resolve(comments);
        });
    });
};

module.exports.query = (client, repos, filter) => {
    _.each(repos, function(repo) {
        processing.issues.push(includeIssues(client, repo, filter));
    });
    return new Promise(function(resolve, reject) {
        Promise.all(processing.issues).then(function(error) {
            resolve(repos);
        });
    });
};
<commit_msg>Refactoring the code<commit_after>'use strict';

var Promise = require("bluebird"),
    _ = require('lodash'),
    mongodb = require('mongodb'),
    timeEngine = require('./timeEngine'),
    processing = {
        issues: [],
        comments: []
    };

var filterIssues = (issues) => {
    return _.filter(issues, function(issue) {
        return issue.time_entry && issue.time_entry.total > 0;
    }) || [];
};

var processComments = (client, repo, issues, user) => {
    _.each(issues, function(issue) {
        issue.comments > 0 && processing.comments.push(includeComments(client, repo, issue, user));
    });
};

var includeIssues = (client, repo, filter) => {
    return new Promise(function(resolve, reject) {
        var ghrepo = client.repo(repo.full_name);
        ghrepo.issues({
            since: (new Date(filter.from)).toISOString()
        }, function(error, issues) {
            processComments(client, repo, issues, filter.user);
            Promise.all(processing.comments).then(function() {
                repo.issues = filterIssues(issues);
                repo.time_entry = timeEngine.repoTime(repo.issues);
                error ? reject(error) : resolve(repo.issues);
            });
        });
    });
};

var includeComments = (client, repo, issue, user) => {
    return new Promise(function(resolve, reject) {
        var ghissue = client.issue(repo.full_name, issue.number);
        ghissue.comments(function(error, comments) {
            issue.comments = !user ? comments : _.filter(comments, (comment) => {
                return comment.user.login.toLowerCase() === user.toLowerCase()
            });
            issue.time_entry = timeEngine.issueTime(comments);
            error ? reject(error) : resolve(comments);
        });
    });
};

module.exports.query = (client, repos, filter) => {
    _.each(repos, function(repo) {
        processing.issues.push(includeIssues(client, repo, filter));
    });
    return new Promise(function(resolve, reject) {
        Promise.all(processing.issues).then(function(error) {
            resolve(repos);
        });
    });
};
<|endoftext|>


<commit_before>import '../../../css/browser/side-bar'

import React, { PropTypes } from 'react'

import { connect } from 'react-redux'
import { FormattedMessage as T, intlShape } from 'react-intl'
import cx from 'classnames'

import SideBarContext from './SideBarContext'
import SideBarTags from './SideBarTags'

import { setWebentityStatus, showAdjustWebentity } from '../../../actions/webentities'
import { getWebEntityActivityStatus } from '../../../utils/status'

class SideBar extends React.Component {
  constructor (props) {
    super(props)

    this.state = {
      tab: 'context'
    }
  }

  renderCrawlingStatus () {
    const { webentity } = this.props

    if (!webentity) {
      return
    }

    return (

<T id="crawling-status" />

        <T id={ 'crawling-status.' + getWebEntityActivityStatus(webentity) } />

    )
  }

  setStatus (status) {
    const { webentity, setWebentityStatus, showAdjustWebentity, serverUrl, corpusId } = this.props

    if (status !== 'DISCOVERED' && status === webentity.status) {
      // Click on current status = set to discovered
      status = 'DISCOVERED'
    }

    if (status === 'IN') {
      // Set to IN = go to "adjust" mode and validation triggers crawling
      showAdjustWebentity(webentity.id, true)
    } else {
      setWebentityStatus(serverUrl, corpusId, status, webentity.id)
    }
  }

  renderStatusButton (status) {
    const { formatMessage } = this.context.intl
    const { webentity } = this.props

    return (
      <button
        className={ cx('btn btn-large btn-default', 'status-' + status.toLowerCase(), { 'active-status': status === webentity.status }) }
        title={ formatMessage({ id: 'corpus-status.' + status }) }
        onClick={ () => this.setStatus(status) }>
        <T id={ 'corpus-status-label.' + status } />
      </button>
    )
  }

  renderTabs () {
    return (

 this.setState({ tab: 'context' }) }>
            <T id="sidebar.tab-context" />

 this.setState({ tab: 'tags' }) }>
            <T id="sidebar.tab-tags" />

        { (this.state.tab === 'context') ? this.renderTabContext() : this.renderTabTags() }

    )
  }

  renderTabContext () {
    return <SideBarContext serverUrl={ this.props.serverUrl } corpusId={ this.props.corpusId } webentity={ this.props.webentity } />
  }

  renderTabTags () {
    return <SideBarTags serverUrl={ this.props.serverUrl } corpusId={ this.props.corpusId } webentity={ this.props.webentity } />
  }

  render () {
    return (

<T id="status" />

          { this.renderStatusButton('IN') }
          { this.renderStatusButton('UNDECIDED') }
          { this.renderStatusButton('OUT') }

        { this.renderCrawlingStatus() }
        { this.renderTabs() }
        { this.props.disabled ?
 :  }

    )
  }
}

SideBar.propTypes = {
  serverUrl: PropTypes.string.isRequired,
  corpusId: PropTypes.string.isRequired,
  webentity: PropTypes.object.isRequired,
  disabled: PropTypes.bool,

  setWebentityStatus: PropTypes.func.isRequired,
  showAdjustWebentity: PropTypes.func.isRequired
}

const mapStateToProps = ({ ui }) => ({ // eslint-disable-line
})

SideBar.contextTypes = {
  intl: intlShape
}

export default connect(mapStateToProps, {
  setWebentityStatus,
  showAdjustWebentity
})(SideBar)
<commit_msg>default to tags tab in sidebar<commit_after>import '../../../css/browser/side-bar'

import React, { PropTypes } from 'react'

import { connect } from 'react-redux'
import { FormattedMessage as T, intlShape } from 'react-intl'
import cx from 'classnames'

import SideBarContext from './SideBarContext'
import SideBarTags from './SideBarTags'

import { setWebentityStatus, showAdjustWebentity } from '../../../actions/webentities'
import { getWebEntityActivityStatus } from '../../../utils/status'

class SideBar extends React.Component {
  constructor (props) {
    super(props)

    this.state = {
      tab: 'tags'
    }
  }

  renderCrawlingStatus () {
    const { webentity } = this.props

    if (!webentity) {
      return
    }

    return (

<T id="crawling-status" />

        <T id={ 'crawling-status.' + getWebEntityActivityStatus(webentity) } />

    )
  }

  setStatus (status) {
    const { webentity, setWebentityStatus, showAdjustWebentity, serverUrl, corpusId } = this.props

    if (status !== 'DISCOVERED' && status === webentity.status) {
      // Click on current status = set to discovered
      status = 'DISCOVERED'
    }

    if (status === 'IN') {
      // Set to IN = go to "adjust" mode and validation triggers crawling
      showAdjustWebentity(webentity.id, true)
    } else {
      setWebentityStatus(serverUrl, corpusId, status, webentity.id)
    }
  }

  renderStatusButton (status) {
    const { formatMessage } = this.context.intl
    const { webentity } = this.props

    return (
      <button
        className={ cx('btn btn-large btn-default', 'status-' + status.toLowerCase(), { 'active-status': status === webentity.status }) }
        title={ formatMessage({ id: 'corpus-status.' + status }) }
        onClick={ () => this.setStatus(status) }>
        <T id={ 'corpus-status-label.' + status } />
      </button>
    )
  }

  renderTabs () {
    return (

 this.setState({ tab: 'context' }) }>
            <T id="sidebar.tab-context" />

 this.setState({ tab: 'tags' }) }>
            <T id="sidebar.tab-tags" />

        { (this.state.tab === 'context') ? this.renderTabContext() : this.renderTabTags() }

    )
  }

  renderTabContext () {
    return <SideBarContext serverUrl={ this.props.serverUrl } corpusId={ this.props.corpusId } webentity={ this.props.webentity } />
  }

  renderTabTags () {
    return <SideBarTags serverUrl={ this.props.serverUrl } corpusId={ this.props.corpusId } webentity={ this.props.webentity } />
  }

  render () {
    return (

<T id="status" />

          { this.renderStatusButton('IN') }
          { this.renderStatusButton('UNDECIDED') }
          { this.renderStatusButton('OUT') }

        { this.renderCrawlingStatus() }
        { this.renderTabs() }
        { this.props.disabled ?
 :  }

    )
  }
}

SideBar.propTypes = {
  serverUrl: PropTypes.string.isRequired,
  corpusId: PropTypes.string.isRequired,
  webentity: PropTypes.object.isRequired,
  disabled: PropTypes.bool,

  setWebentityStatus: PropTypes.func.isRequired,
  showAdjustWebentity: PropTypes.func.isRequired
}

const mapStateToProps = ({ ui }) => ({ // eslint-disable-line
})

SideBar.contextTypes = {
  intl: intlShape
}

export default connect(mapStateToProps, {
  setWebentityStatus,
  showAdjustWebentity
})(SideBar)
<|endoftext|>