Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Monday, July 13, 2015

Concrete5.7: Dynamically Add The File Selector

The documentation for the newly released Concrete5 version 5.7 may not be complete yet. I haven't found in the documentation a way to dynamically add the file selector wherever I want and how many times I want on a page, but I figured it out, so here it is:


1
2
3
        var selector = 'whatever-you-may-use-here';
        $("#some-container").append('<div class="ccm-file-selector" data-file-selector="' + selector + '"></div>');
        $('[data-file-selector=' + selector + ']').concreteFileSelector({'inputName': 'fID-' + selector, 'chooseText': 'Select an image', 'filters': [{"field":"type","type":1}] });

I hope that this was helpful :)
type:1 at the end is for images.
Other values for the file types can be found in the Type class from the Concrete\Core\File\Type namespace as follows:


1
2
3
4
5
6
7
8
    // File Type Constants
    const T_IMAGE = 1;          //!< @javascript-exported
    const T_VIDEO = 2;          //!< @javascript-exported
    const T_TEXT = 3;           //!< @javascript-exported
    const T_AUDIO = 4;          //!< @javascript-exported
    const T_DOCUMENT = 5;       //!< @javascript-exported
    const T_APPLICATION = 6;    //!< @javascript-exported
    const T_UNKNOWN = 99;       //!< @javascript-exported

Tuesday, December 2, 2014

Some tools that I worked on recently

Two repositories containing two tools that I built today:
1. Upload plugin for JQuery - upload files using ajax. It lets you define the element and the event on which start the upload:
https://github.com/jgrAlex/file-upload-js

2. Uploader module for KohanaFramework
- configure your file properties including options for various sizes and use a single line to make the upload.
https://github.com/jgrAlex/kohana-uploader
I used adapters for this one. For now it only handles images, but if anybody feels like contributing with some more file types you are welcome to do so.

I actually made them to use them together. I hope that they make life easier for whoever wants to use them.