Jump to:

23550 Posts in 19336 Topics by 2890 members

General Questions

SilverStripe Forums » General Questions » JS files copied to assets - why?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 2534 Views
  • mjpg
    Avatar
    8 Posts

    JS files copied to assets - why? Link to this post

    Three .js files are being copied to the assets folder - they are:

    base.js /****** FILE: jsparty/prototype.js *****/
    cmsmain.js /****** FILE: cms/javascript/CMSMain.js *****/
    leftandmain.js /****** FILE: jsparty/loader.js *****/ + others

    I don't want users to see these, and I don't know why they are there?

    All I have done to a clean install of 2.3.2 is to create two new folders in assets/Uploads and upload one PDf and one JPG.

    Any ideas? Thanks in advance.

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: JS files copied to assets - why? Link to this post

    silverstripe combines javascript files for the purpose of faster loading.
    see cms/code/LeftAndMain.php, i.e. at around line 260 some js files are combined in 'assets/base.js'.
    the reason silverstripe chooses the assets folder i think is that it's a folder that needs to be writeable by the standard requirements.
    it should be possible do set it to another folder (don't forget to make it writeable using chmod) but you have to take care of other code expecting these files in the assets folder.

  • mjpg
    Avatar
    8 Posts

    Re: JS files copied to assets - why? Link to this post

    Thanks very much for the reply - I understand.

    Do you know why the developers choose to put these files in a folder that users can see?

  • AlexBeka
    Avatar
    Community Member
    21 Posts

    Re: JS files copied to assets - why? Link to this post

    my workaround for this "issue" is to hide files with the extension .js and .html (for the 404 page generated files), and therfore i put the following code at the end of the constructor of AssetTableField.php;

    //hiding .js and .html files which are auto-generated by SS by default in /assets folder
    $this->sourceFilter .= ($this->sourceFilter) ? " AND " : "";   
    $this->sourceFilter .= "(`Filename` NOT LIKE '%.js' AND `Filename` NOT LIKE '%.html')";

    it´s not a special or elegant solution but it solves this issue for me;

  • Web Designer Perth
    Avatar
    Community Member
    49 Posts

    Re: JS files copied to assets - why? Link to this post

    Please will you share exactly where these lines go?

    TIA

  • AlexBeka
    Avatar
    Community Member
    21 Posts

    Re: JS files copied to assets - why? Link to this post

    just put these lines at the end of the constructor (function __construct in /cms/code/AssetTableField.php)

  • Web Designer Perth
    Avatar
    Community Member
    49 Posts

    Re: JS files copied to assets - why? Link to this post

    Thx so far Alex,

    I can see that line but I really don't have a clue where the 'end of the constructor' is

  • AlexBeka
    Avatar
    Community Member
    21 Posts

    Re: JS files copied to assets - why? Link to this post

    well, that is my changed AssetTableField constructor:

    function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
          parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
          
          $SNG_file = singleton('File');
          
          // If search was request, filter the results here
          $SQL_search = (!empty($_REQUEST['FileSearch'])) ? Convert::raw2sql($_REQUEST['FileSearch']) : null;
          if($SQL_search) {
             $searchFilters = array();
             foreach($SNG_file->searchableFields() as $fieldName => $fieldSpec) {
                if(strpos($fieldName, '.') === false) $searchFilters[] = "`$fieldName` LIKE '%{$SQL_search}%'";
             }
             $this->sourceFilter = '(' . implode(' OR ', $searchFilters) . ')';
             $this->searchingFor = $_REQUEST['FileSearch'];
             
             // @todo Integrate search form more closely and don't rely on deprecated
             // $extraLinkParams.
             $this->extraLinkParams = array(
                'FileSearch' => $SQL_search
             );
          }      
          
          //hiding .js and .html files which are auto-generated by SS by default in /assets folder
          $this->sourceFilter .= ($this->sourceFilter) ? " AND " : "";   
          $this->sourceFilter .= "(`Filename` NOT LIKE '%.js' AND `Filename` NOT LIKE '%.html')";
          
          $this->sourceSort = 'Title';
          $this->Markable = true;
       }

    2534 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.