Permalink
Browse files

version 0.3 and 0.4

  • Loading branch information...
1 parent a21c61d commit 5bf7a484b2510f16beb90bddd45b1ba14b6660b1 @jfragoulis committed Jan 2, 2013
Showing with 153 additions and 17 deletions.
  1. +22 −0 CHANGELOG-0.4.txt
  2. +68 −12 EMetabox.php
  3. +9 −4 assets/jquery.metabox.js
  4. +1 −1 assets/jquery.metabox.min.js
  5. +52 −0 assets/metabox.css
  6. +1 −0 assets/metabox.min.css
View
@@ -0,0 +1,22 @@
+Metabox (Yii Frameword Extension) Change Log
+================================
+
+Version 0.4 January 2, 2013
+--------------------------------
+Bug: Use minified version when YII_DEBUG is defined. The opposite should happen.
+Enh: Added custom (default) css, header and footer support
+Enh: Added cssClass propery. Default value is 'metadata'
+Enh: Asset is now calculated with dirname() and is not hardcoded
+Chg: Url parameter is now optional. If null, the current url is being used.
+
+Version 0.3 December 18, 2012
+--------------------------------
+Enh: Added support for custom initial content using begin/end widget.
+
+Version 0.2 November 5, 2012
+--------------------------------
+Enh: Added customizable ajax response callbacks
+
+Version 0.1 Octover 10, 2012
+--------------------------------
+Initial release
View
@@ -1,7 +1,13 @@
<?php
/**
+ * Metabox Yii Extension.
*
+ * Easily draw a div and load remote content into it, refresh manually,
+ * refresh with an internval or timeout.
+ *
+ * @author Yannis Fragkoulis <yannis.fragkoulis@gmail.com>
+ * @version 0.4
*/
class EMetabox extends CWidget
{
@@ -32,9 +38,28 @@ class EMetabox extends CWidget
public $refreshOnInit = false;
/**
- * @var string the initial contents of the div
+ * @var string the box header. Optional.
+ * @since 0.4
+ */
+ public $header;
+
+ /**
+ * @var string the box footer. Optional.
+ * @since 0.4
+ */
+ public $footer;
+
+ /**
+ * @var string the initial contents of the div. Optional.
+ * @since 0.4
+ */
+ public $content;
+
+ /**
+ * @var string the default css class
+ * @since 0.4
*/
- public $initHtml;
+ public $cssClass = 'metabox';
/**
* @var type
@@ -46,55 +71,86 @@ class EMetabox extends CWidget
*/
public function init()
{
- if ($this->url == null)
- throw new CException('Param `url` is not set.');
-
if (self::$_assets == null)
- self::$_assets = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.metabox.assets'), false, 1, YII_DEBUG);
+ self::$_assets = Yii::app()->getAssetManager()->publish(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets', false, 1, YII_DEBUG);
$id = $this->id;
if (!isset($this->htmlOptions['id']))
$this->htmlOptions['id'] = $id;
if (!isset($this->htmlOptions['class']))
- $this->htmlOptions['class'] = 'metabox';
+ $this->htmlOptions['class'] = $this->cssClass;
+ else
+ $this->htmlOptions['class'] = $this->cssClass . ' ' . $this->htmlOptions['class'];
if ($this->loadingIndicator == null)
$this->loadingIndicator = CHtml::image(self::$_assets . '/loader.gif', 'loading...');
$this->url = CHtml::normalizeUrl($this->url);
+ if (!$this->url)
+ $this->url = Yii::app()->getRequest()->getUrl();
+
$this->options['url'] = $this->url;
+ $this->options['cssClass'] = $this->cssClass;
$this->options['loadingText'] = $this->loadingIndicator;
$this->options['refreshOnInit'] = $this->refreshOnInit;
-
+
echo CHtml::openTag('div', $this->htmlOptions);
- echo $this->initHtml;
+ $this->renderHeader();
+ echo CHtml::openTag('div', array('class' => $this->cssClass . '-content'));
+ $this->renderContent();
}
/**
* Register extension assets
*/
public function run()
{
- echo '</div>';
-
+ echo '</div>'; // close content div
+ $this->renderFooter();
+ echo '</div>'; // close metabox div
+
$id = $this->id;
/* @var $cs CClientScript */
$cs = Yii::app()->getClientScript();
- $min = YII_DEBUG ? '.min' : '';
+ $min = YII_DEBUG ? '' : '.min';
// Register jQuery scripts
$cs->registerCoreScript('jquery');
$cs->registerCoreScript('bbq');
$options = CJavaScript::encode($this->options);
$cs->registerScriptFile(self::$_assets . '/jquery.metabox' . $min . '.js');
+ $cs->registerCSSFile(self::$_assets . '/metabox' . $min . '.css');
$cs->registerScript('metabox#' . $id, "$('#{$id}').metabox({$options});", CClientScript::POS_READY);
}
+ protected function renderHeader()
+ {
+ if ($this->header)
+ {
+ echo CHtml::openTag('div', array('class' => $this->cssClass . '-header'));
+ echo $this->header;
+ echo '</div>'; // close header div
+ }
+ }
+
+ protected function renderFooter()
+ {
+ if ($this->footer)
+ {
+ echo CHtml::tag('div', array('class' => $this->cssClass . '-footer'), $this->footer);
+ }
+ }
+
+ protected function renderContent()
+ {
+ echo $this->content;
+ }
+
}
?>
View
@@ -1,21 +1,25 @@
/**
- * Metabox extension
+ * Metabox javascript class.
+ *
+ * @author Yannis Fragkoulis <yannis.fragkoulis@gmail.com>
+ * @version 0.4
*/
!function( $ ){
"use strict";
var Metabox = function ( element, options ) {
- this.$element = $(element);
this.options = $.extend({}, $.fn.metabox.defaults, options);
+ this.$element = $(element);
+ this.$content = $('.' + this.options.cssClass + '-content', element);
this.options.errorText = this.options.errorText.replace('{url}', this.options.url);
if(this.options.loadingContainer)
this.options.loadingContainer = $(this.options.loadingContainer);
else
- this.options.loadingContainer = this.$element;
+ this.options.loadingContainer = this.$content;
if(this.options.refreshTimeout>0)
this.createTimeout();
@@ -137,6 +141,7 @@
loadingClass: 'metabox-loading',
loadingContainer: null,
errorText: 'Error loading {url}',
+ cssClass: 'metabox',
url: null,
data : {},
type : 'GET',
@@ -145,7 +150,7 @@
refreshInterval : 0,
beforeRefresh: function() {},
handleResponse: function(data) {
- this.$element.html(data);
+ this.$content.html(data);
},
afterRefresh: function(data) {},
debug: true

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,52 @@
+.metabox {
+ -webkit-border-radius: 4px;
+ -moz-border-radius: 4px;
+ border-radius: 4px;
+ margin-bottom: 20px;
+ border: 1px solid #ddd;
+}
+
+.metabox-header {
+ border-bottom: 1px solid #CCC;
+ padding: 5px 10px;
+ font-weight: bold;
+ text-transform: uppercase;
+ font-family: monospace;
+ font-size: 1em;
+ letter-spacing: 0.2em;
+}
+
+.metabox-header {
+ background: #F1F1F1;
+ background: -moz-linear-gradient(top, #F1F1F1 0%, #E2E2E2 100%);
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#F1F1F1), color-stop(100%,#E2E2E2));
+ background: -webkit-linear-gradient(top, #F1F1F1 0%,#E2E2E2 100%);
+ background: -o-linear-gradient(top, #F1F1F1 0%,#E2E2E2 100%);
+ background: -ms-linear-gradient(top, #F1F1F1 0%,#E2E2E2 100%);
+ background: linear-gradient(to bottom, #F1F1F1 0%,#E2E2E2 100%);
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f1f1f1', endColorstr='#e2e2e2',GradientType=0 );
+}
+
+.metabox-buttons {
+ float: right;
+}
+
+.metabox-buttons a {
+ margin-left: 5px;
+}
+
+.metabox-buttons a:first-child {
+ margin-left: 0;
+}
+
+.metabox-content {
+ border-top: 1px solid #eee;
+ padding: 10px;
+}
+
+.metabox-footer {
+ padding: 5px;
+ background: #F1F1F1;
+ font-size:small;
+ text-align: right;
+}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 5bf7a48

Please sign in to comment.