2017 © Pedro Peláez
 

yii2-extension yii2-sir-trevor-js

Yii 2 Sir Trevor JS widget

image

drmabuse/yii2-sir-trevor-js

Yii 2 Sir Trevor JS widget

  • Sunday, August 24, 2014
  • by brewing
  • Repository
  • 7 Watchers
  • 16 Stars
  • 3,752 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 5 Versions
  • 1 % Grown

The README.md

yii2-sir-trevor-js

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Version 0.0.5

a sir-trevor-js module, (*2)

Sir Trevor in action, (*3)

Browser support

Sir Trevor is only tested on the following modern browsers:, (*4)

  • IE10+
  • Chrome 25+
  • Safari 5+
  • Firefox 16+

Dependencies

Sir Trevor requires Underscore (or LoDash), jQuery (or Zepto) and Eventable., (*5)

Contributing

See the roadmap and read a little about the philosophy guiding development., (*6)

Todo

1. create output from Input

Get Started

Installation using composer:, (*7)

composer install drmabuse/yii2-sir-trevor-js:"*"

Basic Usage

<?=
$form->field(
    $model,
    'attributeName')->widget(\drmabuse\sirtrevorjs\SirTrevorWidget::className(),
    [
        'imageUploadUrl' => \yii\helpers\Url::to(['file/sir-trevor-upload']),
        'language'      => 'de',//es,fi,pt,fr,de,cn,
        'assetMode'     => 'min'//dev,
        'element'       => '.sir-trevor'// wil add to the textarea,
        'initJs'        => 'SirTrevor....'//PLZ read before Sir Trevor Api
        'options'       => ['class' => 'mysexyTextarea'],
        'blockOptions'  => Json::encode(
             [
                'el'          => new JsExpression("$('.sir-trevor')"),
                'blockTypes'  => [
                     "Heading",
                     "Text",
                     "List",
                     "Quote",
                     "Image",
                     "Video",
                     "Tweet",
                     "Columns",
                     "Code",
                     "Gallery"
                 ],
                'defaultType' => false
            ]
        )
    ]   
)
?>
//Output
<?php
    use drmabuse\sirtrevorjs\SirTrevorConverter;
    $converter = new SirTrevorConverter();
?>
<?= $converter->toHtml($json) ?>

Advanced Usage

Image Block - Example File Upload Handler

/**
     * Action for file uploads via sir-trevor image block from SirTrevorWidget (input widget)
     *
     * @param $root relative base folder
     */
    public function actionSirTrevorUpload($root)
    {
        $upload         = UploadedFile::getInstanceByName('attachment[file]');
        $model          = new File();
        $name_id        = Inflector::slug(str_replace($upload->extension, '', $upload->name));
        $model->path    = 'images/' . $root . '/' . $model->name_id . '.' . $upload->extension;
        $savePath       = \Yii::getAlias('@backend/web') . '/' . $model->path;

        $response = new Response();
        $response->format = Response::FORMAT_JSON;
        $response->data['message'] = "File";

        if (!is_file($savePath) && is_dir(dirname($savePath))) {
            if ($upload->saveAs($model->path)) {
                $model->mime_type = FileHelper::getMimeType($model->path);
                $model->file_size = $upload->size;
                if ($model->save()) {
                    $items = $this->getItems($this->rootPath);
                    list($width, $height, $type, $attr) = getimagesize($model->path);
                    $response->setStatusCode(200);
                    $response->content = Json::encode(['file' => ['url' => $model->path]]);
                    \Yii::$app->end(0, $response);
                } else {
                    $response->statusText = "Database record could not be saved.";
                }
            } else {
                $response->statusText = "File could not be saved.";
            }
        }else{
            $response->statusText = "File exists or root folder '{$savePath}' not found.";
        }

        $response->setStatusCode(500);
        \Yii::$app->end(0, $response);

    }

Developer Info

If you want to compile/build from the latest javascript sources, use the following commands to get the JavaScript dependencies., (*8)

npm update
bower update

To create the asset files run, (*9)

grunt default

To create a new version, (*10)

grunt bumpup
grunt semantic

The Versions

24/08 2014

dev-develop/compile

dev-develop/compile https://github.com/DrMabuse23/yii2-sir-trevor-js

Yii 2 Sir Trevor JS widget

  Sources   Download

BSD-3-Clause

The Requires

 

yii2 sir trevor js

24/08 2014

dev-master

9999999-dev https://github.com/DrMabuse23/yii2-sir-trevor-js

Yii 2 Sir Trevor JS widget

  Sources   Download

BSD-3-Clause

The Requires

 

yii2 sir trevor js

24/08 2014

dev-testcommit

dev-testcommit https://github.com/DrMabuse23/yii2-sir-trevor-js

Yii 2 Sir Trevor JS widget

  Sources   Download

BSD-3-Clause

The Requires

 

yii2 sir trevor js

26/07 2014

dev-output/widgets

dev-output/widgets https://github.com/DrMabuse23/yii2-sir-trevor-js

Yii 2 Sir Trevor JS widget

  Sources   Download

BSD-3-Clause

The Requires

 

yii2 sir trevor js

24/07 2014

0.0.5

0.0.5.0 https://github.com/DrMabuse23/yii2-sir-trevor-js

Yii 2 Sir Trevor JS widget

  Sources   Download

BSD-3-Clause

The Requires

 

yii2 sir trevor js