Permalink
Browse files

version 0.2

  • Loading branch information...
jfragoulis committed Nov 5, 2012
1 parent edc18cd commit ecd5ac42e09f025d7b4b75a049eb3a8f5c2ce378
Showing with 26 additions and 27 deletions.
  1. +8 −7 EMetabox.php
  2. +17 −19 assets/jquery.metabox.js
  3. +1 −1 assets/jquery.metabox.min.js
View
@@ -1,8 +1,7 @@
<?php
/**
- * @author Yannis Fragkoulis <yannis.fragkoulis@gmail.com>
- * @version $Id$
+ *
*/
class EMetabox extends CWidget
{
@@ -61,7 +60,7 @@ public function init()
$this->htmlOptions['class'] = 'metabox';
if ($this->loadingIndicator == null)
- $this->loadingIndicator = CHtml::image(self::$_assets . '/loader.gif', 'loading...', array('class' => 'loader hide'));
+ $this->loadingIndicator = CHtml::image(self::$_assets . '/loader.gif', 'loading...');
$this->url = CHtml::normalizeUrl($this->url);
@@ -71,22 +70,24 @@ public function init()
}
/**
- *
+ * Register extension assets
*/
public function run()
{
$id = $this->id;
echo CHtml::tag('div', $this->htmlOptions, $this->initHtml);
- echo $this->loadingIndicator;
- // Register extension assets
+ /* @var $cs CClientScript */
$cs = Yii::app()->getClientScript();
$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', CClientScript::POS_END);
+ $cs->registerScriptFile(self::$_assets . '/jquery.metabox' . $min . '.js');
$cs->registerScript('metabox#' . $id, "$('#{$id}').metabox({$options});", CClientScript::POS_READY);
}
View
@@ -4,11 +4,13 @@
!function( $ ){
- "use strict"
+ "use strict";
var Metabox = function ( element, options ) {
- this.$element = $(element)
- this.options = $.extend({}, $.fn.metabox.defaults, options)
+ this.$element = $(element);
+ this.options = $.extend({}, $.fn.metabox.defaults, options);
+
+ this.options.errorText = this.options.errorText.replace('{url}', this.options.url);
if(this.options.loadingContainer)
this.options.loadingContainer = $(this.options.loadingContainer);
@@ -23,7 +25,7 @@
if(this.options.refreshOnInit)
this.refresh();
- }
+ };
Metabox.prototype = {
@@ -67,13 +69,13 @@
success : function(data) {
$box.$element.removeClass($box.options.loadingClass);
$box.options.loadingContainer.html('');
- $box.options.handleResponse.apply($box, [data])
+ $box.options.handleResponse.apply($box, [data]);
$box.options.afterRefresh.apply($box, [data]);
},
error: function (XHR, textStatus, errorThrown) {
var ret, err;
$box.$element.removeClass($box.options.loadingClass);
- $box.$element.show().next().hide();
+ $box.options.loadingContainer.html($box.options.errorText);
if (XHR.readyState === 0 || XHR.status === 0) {
return;
}
@@ -113,7 +115,7 @@
$.ajax(options);
}
- }
+ };
/* METABOX PLUGIN DEFINITION
@@ -123,17 +125,18 @@
return this.each(function () {
var $this = $(this)
, data = $this.data('metabox')
- , options = typeof option == 'object' && option
- if (!data) $this.data('metabox', (data = new Metabox(this, options)))
+ , options = typeof option == 'object' && option;
+ if (!data) $this.data('metabox', (data = new Metabox(this, options)));
- if (option == 'refresh') data.refresh(ajaxoptions)
+ if (option == 'refresh') data.refresh(ajaxoptions);
})
- }
+ };
$.fn.metabox.defaults = {
loadingText: 'loading...',
loadingClass: 'metabox-loading',
loadingContainer: null,
+ errorText: 'Error loading {url}',
url: null,
data : {},
type : 'GET',
@@ -144,15 +147,10 @@
handleResponse: function(data) {
this.$element.html(data);
},
- afterRefresh: function(data) {}
- }
+ afterRefresh: function(data) {},
+ debug: true
+ };
$.fn.metabox.Constructor = Metabox
- /* METABOX DATA-API
- * =============== */
-
- $(function () {
- })
-
}( window.jQuery );

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

Oops, something went wrong.

0 comments on commit ecd5ac4

Please sign in to comment.