Skip to content

Commit

Permalink
js as static file
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrammatiko committed Oct 16, 2015
1 parent 77b26a0 commit 3eaa6ea
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 67 deletions.
68 changes: 1 addition & 67 deletions libraries/cms/form/field/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,73 +205,7 @@ protected function getInput()

// Include jQuery
JHtml::_('jquery.framework');

// Build the script.
$script = array();
$script[] = ' function jInsertFieldValue(value, id) {';
$script[] = ' var $ = jQuery.noConflict();';
$script[] = ' var old_value = $("#" + id).val();';
$script[] = ' if (old_value != value) {';
$script[] = ' var $elem = $("#" + id);';
$script[] = ' $elem.val(value);';
$script[] = ' $elem.trigger("change");';
$script[] = ' if (typeof($elem.get(0).onchange) === "function") {';
$script[] = ' $elem.get(0).onchange();';
$script[] = ' }';
$script[] = ' jMediaRefreshPreview(id);';
$script[] = ' }';
$script[] = ' }';

$script[] = ' function jMediaRefreshPreview(id) {';
$script[] = ' var $ = jQuery.noConflict();';
$script[] = ' var value = $("#" + id).val();';
$script[] = ' var $img = $("#" + id + "_preview");';
$script[] = ' var basepath = $("#" + id).data("basepath"); console.log($img);';

$script[] = ' if ($img.length) {';
$script[] = ' if (value) {';
$script[] = ' $img.attr("src", basepath + value);';
$script[] = ' $("#" + id + "_preview_empty").hide();';
$script[] = ' $("#" + id + "_preview_img").show()';
$script[] = ' } else { ';
$script[] = ' $img.attr("src", "");';
$script[] = ' $("#" + id + "_preview_empty").show();';
$script[] = ' $("#" + id + "_preview_img").hide();';
$script[] = ' } ';
$script[] = ' } ';
$script[] = ' }';

$script[] = ' function jMediaRefreshPreviewTip(tip)';
$script[] = ' {';
$script[] = ' var $ = jQuery.noConflict();';
$script[] = ' var $tip = $(tip);';
$script[] = ' var $img = $tip.find("img.media-preview");';
$script[] = ' $img.each(function(index, value) {';
$script[] = ' $tip.find("div.tip").css("max-width", "none");';
$script[] = ' var id = $(this).attr("id");';
$script[] = ' id = id.substring(0, id.length - "_preview".length);';
$script[] = ' jMediaRefreshPreview(id);';
$script[] = ' $tip.show(this);';
$script[] = ' });';
$script[] = ' }';

// JQuery for tooltip for INPUT showing whole image path
$script[] = ' function jMediaRefreshImgpathTip(tip, els)';
$script[] = ' {';
$script[] = ' var $ = jQuery.noConflict(); console.log(els);';
$script[] = ' var $tip = $(tip);';
$script[] = ' $tip.css("max-width", "none");';
$script[] = ' var $imgpath = $(els).val();';
$script[] = ' $("#TipImgpath").html($imgpath);';
$script[] = ' if ($imgpath.length) {';
$script[] = ' $tip.show();';
$script[] = ' } else {';
$script[] = ' $tip.hide();';
$script[] = ' }';
$script[] = ' }';

// Add the script to the document head.
JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
JHtml::_('script', 'media/mediafield-mootools.min.js', true, true, false, false, true);

self::$initialised = true;
}
Expand Down
63 changes: 63 additions & 0 deletions media/media/js/mediafield-mootols.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
function jInsertFieldValue(value, id) {
var $ = jQuery.noConflict();
var old_value = $("#" + id).val();
if (old_value != value) {
var $elem = $("#" + id);
$elem.val(value);
$elem.trigger("change");
if (typeof($elem.get(0).onchange) === "function") {
$elem.get(0).onchange();
}
jMediaRefreshPreview(id);
}
}

function jMediaRefreshPreview(id) {
var $ = jQuery.noConflict();
var value = $("#" + id).val();
var $img = $("#" + id + "_preview");
var basepath = $("#" + id).data("basepath");

if ($img.length) {
if (value) {
$img.attr("src", basepath + value);
$("#" + id + "_preview_empty").hide();
$("#" + id + "_preview_img").show()
} else {
$img.attr("src", "");
$("#" + id + "_preview_empty").show();
$("#" + id + "_preview_img").hide();
}
}
}

function jMediaRefreshPreviewTip(tip)
{
var $ = jQuery.noConflict();
var $tip = $(tip);
var $img = $tip.find("img.media-preview");

$img.each(function(index, value) {
$tip.find("div.tip").css("max-width", "none");
var id = $(this).attr("id");
id = id.substring(0, id.length - "_preview".length);
jMediaRefreshPreview(id);
$tip.show(this);
});
}

// JQuery for tooltip for INPUT showing whole image path
function jMediaRefreshImgpathTip(tip, els)
{
var $ = jQuery.noConflict();
var $tip = $(tip);
$tip.css("max-width", "none");
var $imgpath = $(els).val();
$("#TipImgpath").html($imgpath);

if ($imgpath.length) {
$tip.show();
} else {
$tip.hide();
}
}
1 change: 1 addition & 0 deletions media/media/js/mediafield-mootools.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3eaa6ea

Please sign in to comment.