Exemplo n.º 1
0
    protected function getInput()
    {
        $fieldID = str_replace(array('[', ']', 'jformparams'), '', $this->name);
        if (!self::$initialised) {
            $document = JFactory::getDocument();
            $document->addScriptDeclaration('
//;(function($) {
	var minimizeText = "Minimize",
		maximizeText = "Maximize";

	// Generate Unique ID
	function uniqueid() {
		return Math.random().toString(36).substr(2, 9);
	}

	// Update the item count
	function updateItemsCount(container) {
		var count = 0;
		container.find("div.dynoitem").each(function(){
			count++;
		});
		return count;
	}

	// Clear Button - clear the filed
	function clearButton(container){
		container.find(".clearBtn").each(function(){
			jQuery(this).on("click",function(e){
				e.preventDefault();
				jQuery(this).closest(".wrapper").find("input[type=text]").attr("value","");
			});
		});
	}

	// Refresh rows
	function confirm($row, dynoManager) {
		var cnt = updateItemsCount(dynoManager);

		// prepare image fields
		$row.find(".browseField input[type=text]").each(function(){
			var _t =  jQuery(this),
				thisID = _t.attr("id"),
				uniq = uniqueid(),
				thisIDnum = _t.attr("id").match(/\\d+/g);

			_t.attr("id", thisID.replace(thisID, "imgfield_"+uniq));

			// also replace in href
			var thisBtn = _t.closest(".wrapper").find("a.modalBtn"),
				thisBtnHref = thisBtn.attr("href"),
				thisBtnNum = thisBtnHref.split("=").pop();
			if(thisBtnNum)
				thisBtn.attr("href", thisBtnHref.replace(thisBtnNum, "imgfield_"+uniq));
			else
				thisBtn.attr("href", thisBtnHref+"imgfield_"+uniq);
		});

		// enable clear button for new instances
		clearButton(dynoManager);

		// update item counter
		$row.find("span.itemcounter").text(cnt);

		// enable squeeze button for new instances
		//SqueezeBox.assign($$("#hgdynoManager tr:last-child a.modal"), {parse: "rel"});
		if(typeof(SqueezeBox) != "undefined" && SqueezeBox != null)
			SqueezeBox.assign($$(".hgdynoManager tr:last-child a.modal"), {parse: "rel"});

		// enable the resize button for new instances
		$row.find(".resize-dynoitem").on("click", toggleIndividualBox);

		// update newly menu items fields
		var menuItemField = $row.find(".fld.menuitem select"),
			thisName = menuItemField.attr("name"),
			str;
		if(menuItemField.length > 0) {
			str = thisName.replace("[][]", "[" + (cnt - 1) + "][]");
			menuItemField.attr("name", str);
		}

		if(typeof(jQuery.fn.trumbowyg) != "undefined" && jQuery.fn.trumbowyg != null)
			$row.find(".fld.editor textarea").trumbowyg({
				fixedFullWidth: true,
				resetCss: true,
				autogrow: true
			});

		if(typeof(jQuery.fn.minicolors) != "undefined" && jQuery.fn.minicolors != null)
			$row.find(".fld.colorpicker .minicolors").minicolors({
				control: "hue",
				position: "right",
				theme: "bootstrap"
			});

		iosLabels(dynoManager);
		easemdl(dynoManager);
	}

	function updateMenuItems($row) {
		var menuItemFields = $row.find(".fld.menuitem select"),
			boxes = [],
			regex = /\\[([0-9]+)\\]/;
		if(menuItemFields.length > 0) {
		menuItemFields.each(function(i){
			var thisName = jQuery(this).attr("name"),
				matches = thisName.match(regex);
			if (null != matches) {
				boxes.push(matches[1]);
				str = thisName.replace(regex, "[" + (boxes.length - 1) + "]");
				jQuery(this).attr("name", str);
			}
		});
		}
	}

	// Minimize/Maximize Individual Box
	function toggleIndividualBox() {
		var $this = jQuery(this),
			dynoBox = $this.closest("td");
		$this.text(dynoBox.hasClass("minimized") ? minimizeText + " Box" : maximizeText + " Box");
		dynoBox.toggleClass("minimized");
	};

	// Minimize/Maximize All Boxes
	function toggleMasterCollapse() {

		var $this = jQuery(this),
			dynoManager = jQuery(this).closest(".manager_wrap").find("table.hgdynoManager");
			dynoBoxes = dynoManager.find("td"),
			dynoBoxesButtons = dynoBoxes.find(".resize-dynoitem");

		if($this.hasClass("minimized")) {
			$this.text(minimizeText + " All");
			dynoBoxes.removeClass("minimized");
			dynoBoxesButtons.text(minimizeText + " Box");
		} else {
			$this.text(maximizeText + " All");
			dynoBoxes.addClass("minimized");
			dynoBoxesButtons.text(maximizeText + " Box");
		}
		$this.toggleClass("minimized");
	};

	function toggleAllCollapse() {

		var $this = jQuery(this),
			dynoManager = jQuery(this).closest(".manager_wrap").find("table.hgdynoManager");
			dynoBoxes = dynoManager.find("td"),
			dynoBoxesButtons = dynoBoxes.find(".resize-dynoitem");

		if($this.hasClass("minimized")) {
			$this.text(minimizeText + " All");
			dynoBoxes.removeClass("minimized");
			dynoBoxesButtons.text(minimizeText + " Box");
		} else {
			$this.text(maximizeText + " All");
			dynoBoxes.addClass("minimized");
			dynoBoxesButtons.text(maximizeText + " Box");
		}
		$this.toggleClass("minimized");
	}
	function iosLabels(container){
		jQuery(container).find("label.iostoggle").each(function(i,el){
			var $el = jQuery(el),
				$field = $el.prev(".en_stat");
			$el.click(function(e){
				$el.toggleClass("video-enabled");
				if($field.val() == "")
					$field.val("enabled");
				else
					$field.val("");

			});
		});
	}

	function easemdl(container){
		var videoHelp = jQuery("#video_help");
		if(jQuery.fn.easyModal != "undefined" && videoHelp.length) {
			videoHelp.easyModal({ top: 200, overlay : 0.2});
			jQuery(container).find(".open-videohelp").click(function(e){
				e.preventDefault();
				videoHelp.trigger("openModal");
			});
		}
	}
//})(jQuery);
			');
            if (!version_compare(JVERSION, '3.0', 'ge')) {
                $checkJqueryLoaded = false;
                $header = $document->getHeadData();
                foreach ($header['scripts'] as $scriptName => $scriptData) {
                    if (substr_count($scriptName, '/jquery')) {
                        $checkJqueryLoaded = true;
                    }
                }
                //Add js
                if (!$checkJqueryLoaded) {
                    $document->addScript(self::getPath() . 'js/jquery.min.js');
                }
                $document->addScript(self::getPath() . 'js/jquery.noconflict.js');
            }
            // load css
            $document->addStyleSheet(self::getPath() . 'css/manager.css');
            // load scripts
            $document->addScript(self::getPath() . 'js/jquery-ui.min.js');
            $document->addScript(self::getPath() . 'js/jquery.dynotable.js');
            $document->addStyleDeclaration('#hgdynoManager' . $fieldID . ' .chzn-done {display:inline-block !important;} #hgdynoManager' . $fieldID . ' .chzn-done + .chzn-container {display:none !important;}');
            self::$initialised = true;
        }
        $triggerSc = '
;(function($) {
	// when dom ready
	$(document).ready(function() {
		var dynoManager = $("#hgdynoManager' . $fieldID . '"),
			dynoElems = dynoManager.find("td");
		// init dynotable
		dynoManager.dynoTable({
			removeClass: ".removeDynoItem' . $fieldID . '",
			lastRowRemovable: ' . ($this->element['lastrowremovable'] == 'yes' ? 'true' : 'false') . ',
			orderable: ' . ($this->element['dragging'] != 'no' ? 'true' : 'false') . ',
			dragHandleClass: ".dragDynoItem' . $fieldID . '",
			addRowTemplateId: "#addTemplate' . $fieldID . '",
            addRowButtonId: "#addRow' . $fieldID . '",
			onRowRemove: function(){
				var dynoManager = $("#hgdynoManager' . $fieldID . '");
				updateItemsCount($("#hgdynoManager' . $fieldID . '"));
				updateMenuItems($("#hgdynoManager' . $fieldID . '"));
			},
			onRowAdd: function(){
				confirm($("#hgdynoManager' . $fieldID . '").find("tr:last-child"), $("#hgdynoManager' . $fieldID . '"));
				updateItemsCount($("#hgdynoManager' . $fieldID . '"));
			},
			onRowReorder: function(){
				updateItemsCount($("#hgdynoManager' . $fieldID . '"));
			}
		});

		// on click, do the work
		$(".resizeDynoItem' . $fieldID . '").on("click", toggleIndividualBox);
		$("#minimizeAll' . $fieldID . '").on("click", toggleMasterCollapse);

		updateItemsCount(dynoManager);
		clearButton(dynoManager);

		iosLabels(dynoManager);
		easemdl(dynoManager);
	});
})(jQuery);';
        JFactory::getDocument()->addScriptDeclaration($triggerSc);
        $itemName = $this->element['itemnname'] ? $this->element['itemnname'] : 'Item';
        $showPreview = $this->element['showpreview'] == 'no' ? false : true;
        $itemMinimized = $this->element['minimized'];
        $output = '<div class="manager_wrap">';
        $output .= '
	<div class="manager_head clearfix">
		<span id="minimizeAll' . $fieldID . '" class="minimize_all hg_uikit_button ' . ($itemMinimized == 'yes' ? 'minimized' : '') . '">' . ($itemMinimized == 'yes' ? 'Maximize All' : 'Minimize All') . '</span>
		<strong class="manager_label">' . $this->element['label'] . '</strong>
	</div>

	<table class="hgdynoManager" id="hgdynoManager' . $fieldID . '">';
        if ($this->value && is_array($this->value)) {
            //if($this->value) {
            // Get the field options.
            $options = $this->getOptions();
            // print_r($this->value);
            foreach ($this->value['vals'] as $k => $v) {
                // get stored values
                $thevalues = array();
                // assign stored values to each field
                // print_r($this->value);
                foreach ($options as $option) {
                    if ($option->type == 'spacer') {
                        $thevalues[$option->name] = null;
                    } else {
                        if (self::is_multidim_array($this->value[$option->name])) {
                            foreach ($this->value[$option->name] as $mdk => $mdv) {
                                $thevalues[$option->name][$mdk] = isset($this->value[$option->name][$mdk][$k]) ? $this->value[$option->name][$mdk][$k] : null;
                                // echo $this->value[$option->name][$mdk][$k];
                            }
                            // $thevalues[$option->name]['link'] = $this->value[$option->name]['link'][$k];
                        } else {
                            $thevalues[$option->name] = isset($this->value[$option->name][$k]) ? $this->value[$option->name][$k] : null;
                        }
                    }
                    if (isset($this->value['dynotitle'][$k])) {
                        $thevalues['dynotitle'] = $this->value['dynotitle'][$k];
                    }
                }
                // print_r($thevalues);
                // load fields with the stored values
                $output .= '<tr>' . self::getFields($this->name, 'default', $thevalues, $k) . '</tr>';
            }
        } else {
            // load empty fields
            if ($this->element['startempty'] != 'yes') {
                $output .= '<tr>' . self::getFields($this->name, 'default') . '</tr>';
            }
        }
        //load template fields for dynoTable script
        $output .= '<tr id="addTemplate' . $fieldID . '">' . self::getFields($this->name, 'template') . '</tr>';
        $output .= '
	</table>
	<a id="addRow' . $fieldID . '" class="hg_uikit_button addnew">Add New ' . $itemName . '</a>
</div>';
        return $output;
    }
Exemplo n.º 2
0
    protected function getInput()
    {
        if (!self::$initialised) {
            $document = JFactory::getDocument();
            $scripts = '

;(function($) {
	
	function updateItemsCount() {
		var count = 0;
		$("div.dynoitem").each(function(){ 
			count++;
		});
		return count;
	}
	
	function clearButton(){
		$("#hgdyno_manager .clearBtn").each(function(){
			$(this).on("click",function(e){
				e.preventDefault();
				$(this).closest(".wrapper").find("input[type=text]").attr("value","");
			});
		});	
	}

	function confirm($row) {
		var cnt = updateItemsCount()-1;
		
		var findImgFields = $row.find(".browseField input[type=text]");
		findImgFields.each(function(){
			var _t =  $(this),
				thisID = _t.attr("id"),
				thisIDnum = _t.attr("id").match(/\\d+/g);
			_t.attr("id", thisID.replace(thisIDnum, cnt));
			
			// also replace in href
			var thisBtn = _t.closest(".wrapper").find("a.modalBtn"),
				thisBtnHref = thisBtn.attr("href"),
				thisBtnNum = thisBtnHref.split("=").pop().match(/\\d+/g);
			if(thisBtnNum)
				thisBtn.attr("href", thisBtnHref.replace(thisBtnNum, cnt));
			else
				thisBtn.attr("href", thisBtnHref+cnt);
			
		});
		
		clearButton();
		
		SqueezeBox.assign($$("#hgdyno_manager tr:last-child a.modal"), {parse: "rel"});
	}

	$(document).ready(function() {
		
		$("#hgdyno_manager").dynoTable({
			removeClass: ".remove-dynoitem",
			lastRowRemovable: ' . ($this->element['lastrowremovable'] == 'yes' ? 'true' : 'false') . ',
			orderable: ' . ($this->element['dragging'] != 'no' ? 'true' : 'false') . ',
			dragHandleClass: ".drag-dynoitem",
			onRowRemove: updateItemsCount(),
			onRowAdd: function(){
				confirm($("#hgdyno_manager").find("tr:last-child"));
				updateItemsCount();
			},
			onRowReorder: function(){
				updateItemsCount()
			}
		});
		
		
		updateItemsCount();
		clearButton();

	});
	
})(jQuery);
';
            // load script
            $document->addScriptDeclaration($scripts);
            if (!version_compare(JVERSION, '3.0', 'ge')) {
                $checkJqueryLoaded = false;
                $header = $document->getHeadData();
                foreach ($header['scripts'] as $scriptName => $scriptData) {
                    if (substr_count($scriptName, '/jquery')) {
                        $checkJqueryLoaded = true;
                    }
                }
                //Add js
                if (!$checkJqueryLoaded) {
                    $document->addScript(JURI::root() . $this->element['path'] . 'js/jquery.min.js');
                }
                $document->addScript(JURI::root() . $this->element['path'] . 'js/jquery.noconflict.js');
            }
            // load css
            $document->addStyleSheet(JURI::root() . $this->element['path'] . 'css/manager.css');
            // load scripts
            $document->addScript('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js');
            $document->addScript(JURI::root() . $this->element['path'] . 'js/jquery.dynotable.js');
            self::$initialised = true;
        }
        $itemName = $this->element['itemnname'] ? $this->element['itemnname'] : 'Item';
        $showPreview = $this->element['showpreview'] == 'no' ? false : true;
        $output = '
<div class="wrap" id="manager_wrap">
	<table id="hgdyno_manager">';
        if ($this->value) {
            // Get the field options.
            $options = $this->getOptions();
            foreach ($this->value['vals'] as $k => $v) {
                // get stored values
                $thevalues = array();
                // assign stored values to each field
                foreach ($options as $option) {
                    if ($option->type == 'texturl') {
                        $thevalues[$option->name]['link'] = $this->value[$option->name]['link'][$k];
                        $thevalues[$option->name]['target'] = $this->value[$option->name]['target'][$k];
                    } elseif ($option->type == 'spacer') {
                        $thevalues[$option->name] = null;
                    } else {
                        $thevalues[$option->name] = $this->value[$option->name][$k];
                    }
                }
                // load fields with the stored valuyes
                $output .= '<tr>' . self::getFields($this->name, $thevalues, $k) . '</tr>';
            }
        } else {
            // load empty fields
            if ($this->element['startempty'] != 'yes') {
                $output .= '<tr>' . self::getFields($this->name) . '</tr>';
            }
        }
        //load template fields for dynoTable script
        $output .= '<tr id="add-template">' . self::getFields($this->name) . '</tr>';
        $output .= '
	</table>
	<a id="add-row" class="hg_uikit_button addnew">Add New ' . $itemName . '</a>
</div>';
        return $output;
    }
Exemplo n.º 3
0
    protected function getInput()
    {
        $fieldID = str_replace(array('[', ']'), '', $this->name);
        echo $fieldID;
        if (!self::$initialised) {
            $document = JFactory::getDocument();
            $scripts = '

;(function($) {
	var minimizeText = "Minimize",
		maximizeText = "Maximize";
		
	// Generate Unique ID
	function uniqueid() {
		return Math.random().toString(36).substr(2, 9);
	}
	
	// Update the item count
	function updateItemsCount() {
		var count = 0;
		$("div.dynoitem").each(function(){ 
			count++;
		});
		
		return count;
	}
	
	// Clear Button - clear the filed
	function clearButton(){
		$("#hgdyno_manager .clearBtn").each(function(){
			$(this).on("click",function(e){
				e.preventDefault();
				$(this).closest(".wrapper").find("input[type=text]").attr("value","");
			});
		});	
	}
	
	// Refresh rows
	function confirm($row) {
		var cnt = updateItemsCount();
		
		// prepare image fields
		$row.find(".browseField input[type=text]").each(function(){
			var _t =  $(this),
				thisID = _t.attr("id"),
				uniq = uniqueid(),
				thisIDnum = _t.attr("id").match(/\\d+/g);
	
			_t.attr("id", thisID.replace(thisID, "imgfield_"+uniq));
			
			// also replace in href
			var thisBtn = _t.closest(".wrapper").find("a.modalBtn"),
				thisBtnHref = thisBtn.attr("href"),
				thisBtnNum = thisBtnHref.split("=").pop();
			if(thisBtnNum)
				thisBtn.attr("href", thisBtnHref.replace(thisBtnNum, "imgfield_"+uniq));
			else
				thisBtn.attr("href", thisBtnHref+"imgfield_"+uniq);
		});
		
		// enable clear button for new instances
		clearButton();
		
		// update item counter
		$row.find("span.itemcounter").text(cnt);
		
		// enable squeeze button for new instances
		SqueezeBox.assign($$("#hgdyno_manager tr:last-child a.modal"), {parse: "rel"});
		
		// enable the resize button for new instances
		$(".resize-dynoitem").on("click", toggleIndividualBox);
		
		// update newly menu items fields
		var menuItemField = $row.find(".fld.menuitem select"),
			thisName = menuItemField.attr("name"),
			str;
		str = thisName.replace("[][]", "[" + (cnt - 1) + "][]");
		menuItemField.attr("name", str);
	}
	
	function updateMenuItems($row) {
		var menuItemFields = $("#hgdyno_manager .fld.menuitem select"),
			boxes = [],
			regex = /\\[([0-9]+)\\]/;
		
		menuItemFields.each(function(i){
			var thisName = $(this).attr("name"),
				matches = thisName.match(regex);
			if (null != matches) {
				boxes.push(matches[1]);
				str = thisName.replace(regex, "[" + (boxes.length - 1) + "]");
				$(this).attr("name", str);
			}
		});
	}

	
	// Minimize/Maximize Individual Box
	function toggleIndividualBox() {
		var $this = $(this),
			dynoBox = $this.closest("td");
		$this.text(dynoBox.hasClass("minimized") ? minimizeText + " Box" : maximizeText + " Box");
		dynoBox.toggleClass("minimized");
	};
	
	// Minimize/Maximize All Boxes
	function toggleMasterCollapse() {
		var $this = $(this),
			dynoManager = $("#hgdyno_manager"),
			dynoBoxes = dynoManager.find("td"),
			dynoBoxesButtons = dynoBoxes.find(".resize-dynoitem");
		
		if($this.hasClass("minimized")) {
			$this.text(minimizeText + " All");
			dynoBoxes.removeClass("minimized");
			dynoBoxesButtons.text(minimizeText + " Box");	
		} else {
			$this.text(maximizeText + " All");
			dynoBoxes.addClass("minimized");
			dynoBoxesButtons.text(maximizeText + " Box");	
		}
		$this.toggleClass("minimized");
	};

	// when dom ready
	$(document).ready(function() {

		// init dynotable
		$("#hgdyno_manager").dynoTable({
			removeClass: ".remove-dynoitem",
			lastRowRemovable: ' . ($this->element['lastrowremovable'] == 'yes' ? 'true' : 'false') . ',
			orderable: ' . ($this->element['dragging'] != 'no' ? 'true' : 'false') . ',
			dragHandleClass: ".drag-dynoitem",
			onRowRemove: function(){
				updateItemsCount();
				updateMenuItems();
				
			},
			onRowAdd: function(){
				confirm($("#hgdyno_manager").find("tr:last-child"));
				updateItemsCount();
			},
			onRowReorder: function(){
				updateItemsCount()
			}
		});
		
		// on click, do the work
		$(".resize-dynoitem").on("click", toggleIndividualBox);
		$(".minimize_all").click(toggleMasterCollapse);
		
		updateItemsCount();
		clearButton();
	});
	
})(jQuery);
';
            // load script
            $document->addScriptDeclaration($scripts);
            if (!version_compare(JVERSION, '3.0', 'ge')) {
                $checkJqueryLoaded = false;
                $header = $document->getHeadData();
                foreach ($header['scripts'] as $scriptName => $scriptData) {
                    if (substr_count($scriptName, '/jquery')) {
                        $checkJqueryLoaded = true;
                    }
                }
                //Add js
                if (!$checkJqueryLoaded) {
                    $document->addScript(JURI::root() . $this->element['path'] . 'js/jquery.min.js');
                }
                $document->addScript(JURI::root() . $this->element['path'] . 'js/jquery.noconflict.js');
            }
            // load css
            $document->addStyleSheet(JURI::root() . $this->element['path'] . 'css/manager.css');
            // load scripts
            $document->addScript(JURI::root() . $this->element['path'] . 'js/jquery-ui.min.js');
            $document->addScript(JURI::root() . $this->element['path'] . 'js/jquery.dynotable.js');
            self::$initialised = true;
        }
        $itemName = $this->element['itemnname'] ? $this->element['itemnname'] : 'Item';
        $showPreview = $this->element['showpreview'] == 'no' ? false : true;
        $itemMinimized = $this->element['minimized'];
        $output = '
<div class="wrap" id="manager_wrap">
	<div class="manager_head clearfix">
		<span class="minimize_all hg_uikit_button ' . ($itemMinimized == 'yes' ? 'minimized' : '') . '">' . ($itemMinimized == 'yes' ? 'Maximize All' : 'Minimize All') . '</span>
		<strong class="manager_label">' . $this->element['label'] . '</strong>
	</div>
	<table id="hgdyno_manager">';
        if ($this->value && is_array($this->value)) {
            //if($this->value) {
            // Get the field options.
            $options = $this->getOptions();
            // print_r($this->value);
            foreach ($this->value['vals'] as $k => $v) {
                // get stored values
                $thevalues = array();
                // assign stored values to each field
                foreach ($options as $option) {
                    if ($option->type == 'texturl') {
                        $thevalues[$option->name]['link'] = $this->value[$option->name]['link'][$k];
                        $thevalues[$option->name]['target'] = $this->value[$option->name]['target'][$k];
                    } elseif ($option->type == 'spacer') {
                        $thevalues[$option->name] = null;
                    } else {
                        $thevalues[$option->name] = $this->value[$option->name][$k];
                    }
                    if (isset($this->value['dynotitle'][$k])) {
                        $thevalues['dynotitle'] = $this->value['dynotitle'][$k];
                    }
                }
                // load fields with the stored values
                $output .= '<tr>' . self::getFields($this->name, 'default', $thevalues, $k) . '</tr>';
            }
        } else {
            // load empty fields
            if ($this->element['startempty'] != 'yes') {
                $output .= '<tr>' . self::getFields($this->name, 'default') . '</tr>';
            }
        }
        //load template fields for dynoTable script
        $output .= '<tr id="add-template">' . self::getFields($this->name, 'template') . '</tr>';
        $output .= '
	</table>
	<a id="add-row" class="hg_uikit_button addnew">Add New ' . $itemName . '</a>
</div>';
        return $output;
    }