<commit_before>/*
** Long Library Name:
**      Adaptation toolkit Module
**
** Acronym and its version:
**      Adaptation toolkit v1.0
**
** Copyright claim:
**      Copyright ( C ) 2013-2014 Vicomtech-IK4 ( http://www.vicomtech.org/ ),
**      all rights reserved.
**
** Authors (in alphabetical order):
**      <NAME> <<EMAIL>>
**      <NAME> <<EMAIL>>,
**      <NAME> <<EMAIL>>,
**
** Description:
**      User interface Adapation Engine is resposible of adapting given N components to the correct
**      layout, taking in a account the context.
**
** Development Environment:
**      The software has-been Implemented in JavaScript, and tested in Chrome and firefox
**      browsers.
**
** Dependencies:
**      As accounts package depends on other libraries, the user must adhere to and
**      keep in place any Licencing terms of those libraries:
**              requirejs v2.1.14 (http://requirejs.org/)
**
** Licenses dependencies:
**      License Agreement for requirejs:
**              BSD 3-Clause license (http://opensource.org/licenses/BSD-3-Clause)
**              MIT license (http://opensource.org/licenses/MIT)
**
*/

define(
  ["mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/pip",
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/menu",
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/horizontal",
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/customGrid",
  /*"mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/explicit",*/
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/accordion",
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/verticalMenu",
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/scrollHorizontal",
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/spinner"],
  function(componentsManager){
    var layoutList   = Array.prototype.slice.apply( arguments );
    var cmps=[];
    //var prev_orientation='';
    var UIAdaptation = function(){
      var layouts = [];
      var actualLayout;
      var layoutIndex=0;
      var prev_orientation=90;
      var activityTimer;
      var This = this;
      var __screen;
      /*
       * STATIC: Layout established by user
       * CUSTOM: Without support of layout system, css support
       * ADAPTABLE: Layout are adaptable to the context
       */
      this.LAYOUTMODE = {CUSTOM:"custom",STATIC:"static",ADAPTABLE:"adaptable"};
      this.layoutMode ="static";
      this.explicitConf = [];

      this.registerLayouts = function () {
        var _this = this;
        $.getJSON('/resources/explicitsCss/rules.json', function(data) {
          _this.explicitConf = data;

        });
        layoutList.forEach(function(layout,i){
          if  (layout.checkForImplementation() || layout.name != "explicit"){
            //console.log('registring layout',layout);
            if (layout.name === "explicit") _this.explicitLayout = layout;
            layouts.push(layout);
          }
          else throw new Error ("Some error registring layout: "+layout.name);
        })


      };
      this.init = function (wcmps,mode){
        var _this = this;

        this.layoutMode = mode;
        cmps = wcmps;

        if (this.layoutMode == this.LAYOUTMODE.ADAPTABLE){
          actualLayout = this.findBestLayout(cmps)[layoutIndex];
          this.layout(cmps,'onLayoutChange');
          layoutIndex++;

        }
        else
        if (this.layoutMode == this.LAYOUTMODE.STATIC){
        //  this.layout(cmps,'onComponentsChange');
        }
      }
      this.useLayout = function (layoutName){
        // find the rule
        if (actualLayout) actualLayout.unload(cmps);
        actualLayout = layouts.filter(function(el){
          if (el.name == layoutName) return true;
          else return false;
        })[0];
        if (!actualLayout) throw new Error ("There is no layout named: "+layoutName);
        else  {
              if (this.layoutMode === this.LAYOUTMODE.STATIC) this.layout(cmps,"onComponentsChange");
              else  this.layout(cmps,"onLayoutChange");
              }
      }

      this.layout = function (_cmps,event){
        // CHECK FOR EXPLICIT RULE FIRST ELSE SWITCH
        var explicitRule = this.checkForExplicitRules(_cmps,event);
        if (explicitRule){
          if (event === "onComponentsChange"){
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            this.explicitLayout.onComponentsChange(_cmps,explicitRule);

          }
          else if (event === "onOrientationChange"){
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            this.explicitLayout.onOrientationChange(_cmps,explicitRule);

          }
          else if (event === "onResizeEvent"){

            this.explicitLayout.onResizeEvent(_cmps,explicitRule);

          }
          else   if (event === "onLayoutChange")
          {
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            this.explicitLayout.onLayoutChangeEvent(_cmps,explicitRule);
          }
          else {
            throw new Error ("Event does not exists");
          }
        }
        else
        switch (this.layoutMode){
          case this.LAYOUTMODE.CUSTOM:
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
          break;
          case this.LAYOUTMODE.STATIC:
          if (!actualLayout) throw new Error ("For using STATIC method first you have to choose one layout");
          if (event === "onComponentsChange"){
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            actualLayout.onComponentsChange(_cmps);
            //  actualLayout.render(_cmps);
          }
          else if (event === "onOrientationChange"){
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            actualLayout.onOrientationChange(_cmps);
            //  actualLayout.render(_cmps);
          }
          else if (event === "onResizeEvent"){
            //mediascape.AdaptationToolkit.componentManager.loadManager.load(cmps);
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            actualLayout.onResizeEvent(_cmps);
            //  actualLayout.render(_cmps);
          }
          else {
            throw new Error ("Event does not exists");
          }
          break;
          case this.LAYOUTMODE.ADAPTABLE:
          if (event === "onLayoutChange")
          {
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            actualLayout.onLayoutChangeEvent(_cmps);
          }
          else if (event === "onComponentsChange"){
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            actualLayout.onComponentsChange(_cmps);
          }
          else if (event === "onOrientationChange"){

            actualLayout.onComponentsChange
          }
          else if (event === "onResizeEvent")
          actualLayout.onResizeEvent(_cmps);

        }

      }

      this.onComponentsChange = function (_cmps,cmds){
          // Filter only showing ones
          actualLayout.unload(cmps);
          cmps = _cmps;
          if (This.layoutMode === This.LAYOUTMODE.ADAPTABLE){
            layoutIndex=0;
            actualLayout = This.findBestLayout(cmps)[layoutIndex];
            This.layout(cmps,'onComponentsChange');
            layoutIndex++;
          }
          else
            This.layout(cmps,'onComponentsChange');
            //mediascape.AdaptationToolkit.uiComponents.infoPanel('Layout info','<p>Components Number: '+cmps.length+'</p><p> Rendering layout: '+actualLayout.name+'</p>','250px','1%','6%');
            This.updateComponentQuery();
      }
      this.onWindowResize = function (event){
        // Filter only showing ones
        //cmps = cmds.filter(function(el){});

       if(prev_orientation!==undefined && prev_orientation!==''){

            if(prev_orientation !== event.srcElement.orientation  ){

                prev_orientation=event.srcElement.orientation;
                clearTimeout(activityTimer);
                console.log (layoutIndex,cmps.length);
                actualLayout.unload(cmps);

                actualLayout = This.findBestLayout(cmps)[0];
                this.layout(cmps,'onLayoutChange');

                this.forceRedraw();

            }
            else{

              if (event.detail !="emulate")
              {
                console.log("RESIZING",event);
                this.layout(cmps,'onResizeEvent');
              }
            }
          }


      else{<commit_msg>Update UIAdaptation.js<commit_after>/*
** Long Library Name:
**      Adaptation toolkit Module
**
** Acronym and its version:
**      Adaptation toolkit v1.0
**
** Copyright claim:
**      Copyright ( C ) 2013-2014 Vicomtech-IK4 ( http://www.vicomtech.org/ ),
**      all rights reserved.
**
** Authors (in alphabetical order):
**      <NAME> <<EMAIL>>
**      <NAME> <<EMAIL>>,
**      <NAME> <<EMAIL>>,
**
** Description:
**      User interface Adapation Engine is resposible of adapting given N components to the correct
**      layout, taking in a account the context.
**
** Development Environment:
**      The software has-been Implemented in JavaScript, and tested in Chrome and firefox
**      browsers.
**
** Dependencies:
**      As accounts package depends on other libraries, the user must adhere to and
**      keep in place any Licencing terms of those libraries:
**              requirejs v2.1.14 (http://requirejs.org/)
**
** Licenses dependencies:
**      License Agreement for requirejs:
**              BSD 3-Clause license (http://opensource.org/licenses/BSD-3-Clause)
**              MIT license (http://opensource.org/licenses/MIT)
**
*/

define(
  ["mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/pip",
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/menu",
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/horizontal",
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/customGrid",
  /*"mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/explicit",*/
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/accordion",
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/verticalMenu",
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/scrollHorizontal",
  "mediascape/AdaptationToolkit/adaptation/UIAdaptation/layouts/spinner"],
  function(componentsManager){
    var layoutList   = Array.prototype.slice.apply( arguments );
    var cmps=[];
    //var prev_orientation='';
    var UIAdaptation = function(){
      var layouts = [];
      var actualLayout;
      var layoutIndex=0;
      var prev_orientation=90;
      var activityTimer;
      var This = this;
      var __screen;
      /*
       * STATIC: Layout established by user
       * CUSTOM: Without support of layout system, css support
       * ADAPTABLE: Layout are adaptable to the context
       */
      this.LAYOUTMODE = {CUSTOM:"custom",STATIC:"static",ADAPTABLE:"adaptable"};
      this.layoutMode ="static";
      this.explicitConf = [];

      this.registerLayouts = function () {
        var _this = this;
        $.getJSON('/resources/explicitsCss/rules.json', function(data) {
          _this.explicitConf = data;

        });
        layoutList.forEach(function(layout,i){
          if  (layout.checkForImplementation() || layout.name != "explicit"){
            //console.log('registring layout',layout);
            if (layout.name === "explicit") _this.explicitLayout = layout;
            layouts.push(layout);
          }
          else throw new Error ("Some error registring layout: "+layout.name);
        })


      };
      this.init = function (wcmps,mode){
        var _this = this;

        this.layoutMode = mode;
        cmps = wcmps;

        if (this.layoutMode == this.LAYOUTMODE.ADAPTABLE){
          actualLayout = this.findBestLayout(cmps)[layoutIndex];
          this.layout(cmps,'onLayoutChange');
          layoutIndex++;

        }
        else
        if (this.layoutMode == this.LAYOUTMODE.STATIC){
        //  this.layout(cmps,'onComponentsChange');
        }
      }
      this.useLayout = function (layoutName){
        // find the rule
        if (actualLayout) actualLayout.unload(cmps);
        actualLayout = layouts.filter(function(el){
          if (el.name == layoutName) return true;
          else return false;
        })[0];
        if (!actualLayout) throw new Error ("There is no layout named: "+layoutName);
        else  {
              if (this.layoutMode === this.LAYOUTMODE.STATIC) this.layout(cmps,"onComponentsChange");
              else  this.layout(cmps,"onLayoutChange");
              }
      }

      this.layout = function (_cmps,event){
        // CHECK FOR EXPLICIT RULE FIRST ELSE SWITCH
        var explicitRule = this.checkForExplicitRules(_cmps,event);
        if (explicitRule){
          if (event === "onComponentsChange"){
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            this.explicitLayout.onComponentsChange(_cmps,explicitRule);

          }
          else if (event === "onOrientationChange"){
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            this.explicitLayout.onOrientationChange(_cmps,explicitRule);

          }
          else if (event === "onResizeEvent"){

            this.explicitLayout.onResizeEvent(_cmps,explicitRule);

          }
          else   if (event === "onLayoutChange")
          {
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            this.explicitLayout.onLayoutChangeEvent(_cmps,explicitRule);
          }
          else {
            throw new Error ("Event does not exists");
          }
        }
        else
        switch (this.layoutMode){
          case this.LAYOUTMODE.CUSTOM:
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
          break;
          case this.LAYOUTMODE.STATIC:
          if (!actualLayout) throw new Error ("For using STATIC method first you have to choose one layout");
          if (event === "onComponentsChange"){
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            actualLayout.onComponentsChange(_cmps);
            //  actualLayout.render(_cmps);
          }
          else if (event === "onOrientationChange"){
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            actualLayout.onOrientationChange(_cmps);
            //  actualLayout.render(_cmps);
          }
          else if (event === "onResizeEvent"){
            //mediascape.AdaptationToolkit.componentManager.loadManager.load(cmps);
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            actualLayout.onResizeEvent(_cmps);
            //  actualLayout.render(_cmps);
          }
          else {
            throw new Error ("Event does not exists");
          }
          break;
          case this.LAYOUTMODE.ADAPTABLE:
          if (event === "onLayoutChange")
          {
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            actualLayout.onLayoutChangeEvent(_cmps);
          }
          else if (event === "onComponentsChange"){
            mediascape.AdaptationToolkit.componentManager.loadManager.unload( mediascape.AdaptationToolkit.componentManager.core.getHiddenComponents(_cmps));
            mediascape.AdaptationToolkit.componentManager.loadManager.load(_cmps);
            actualLayout.onComponentsChange(_cmps);
          }
          else if (event === "onOrientationChange"){

            actualLayout.onComponentsChange
          }
          else if (event === "onResizeEvent")
          actualLayout.onResizeEvent(_cmps);

        }

      }

      this.onComponentsChange = function (_cmps,cmds){
          // Filter only showing ones
          actualLayout.unload(cmps);
          cmps = _cmps;
          if (This.layoutMode === This.LAYOUTMODE.ADAPTABLE){
            layoutIndex=0;
            actualLayout = This.findBestLayout(cmps)[layoutIndex];
            This.layout(cmps,'onComponentsChange');
            layoutIndex++;
          }
          else
            This.layout(cmps,'onComponentsChange');
            //mediascape.AdaptationToolkit.uiComponents.infoPanel('Layout info','<p>Components Number: '+cmps.length+'</p><p> Rendering layout: '+actualLayout.name+'</p>','250px','1%','6%');
            This.updateComponentQuery();
      }
      this.onWindowResize = function (event){
        // Filter only showing ones
        //cmps = cmds.filter(function(el){});

       if(prev_orientation!==undefined && prev_orientation!==''){

            if(prev_orientation !== event.srcElement.orientation  ){

                prev_orientation=event.srcElement.orientation;
                clearTimeout(activityTimer);
                console.log (layoutIndex,cmps.length);
                actualLayout.unload(cmps);

                if (This.layoutMode === This.LAYOUTMODE.ADAPTABLE) 
                    actualLayout = This.findBestLayout(cmps)[0];
                this.layout(cmps,'onLayoutChange');

                this.forceRedraw();

            }
            else{

              if (event.detail !="emulate")
              {
                console.log("RESIZING",event);
                this.layout(cmps,'onResizeEvent');
              }
            }
          }


      else{
{'fraction_non_alphanumeric': 0.11144174973962208, 'fraction_numerical': 0.002777364479492139, 'mean_word_length': 2.588538885922762, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2274448', 'n_tokens_mistral': 5810, 'n_tokens_neox': 5566, 'n_words': 923}