$ ( document ) .ready ( function () {If you take this code and load it, you will receive the following:
( function ($) {
$ .fn.editable = function (options) {
var defaults = {
typex: "text" ,
url: "action_ajax.php" ,
actionx: “nothing” ,
id: 0,
style_class: "editable" ,
width: "100px"
};
var options = $ .extend (defaults, options);
return this .each ( function () {
var obj = $ ( this );
obj.addClass (options.style_class);
var text_saved = obj.html ();
var namex = this .id + "editMode" ;
var items = "" ;
obj.click ( function () {
switch (options.typex) {
case "text" : {
var inputx = "<input id = '" + namex + "' type = 'text' style = 'width:" + options.width + "' value = '" + text_saved + "' />" ;
var btnSend = "<input type = 'submit' id = 'btnSave" + this .id + "' value = 'ok' />" ;
var btnCancel = "<input type = 'button' id = 'btnCancel" + this .id + "' value = 'undo' />" ;
items = inputx + btnSend + btnCancel;
break ;
}
}
obj.html (items);
$ ( "#" + namex) .focus (). select ();
$ ( "#btnSave" + this .id, obj) .click ( function () {
$ .ajax ({
type: "GET" ,
data:
{
text_string: $ ( "#" + namex) .val (),
actionx: options.actionx,
idx: options.id
},
url: options.url,
success: function (data) {
if (data> '' ) {
obj.html (data) .css ( 'background-color' , '# 993399' );
} else {
obj.html ( 'Repeat please ...' );
}
text_saved = data;
},
error: function (objHttpRequest, error_str) {
obj.html (error_str);
}
});
})
$ ( "#btnCancel" + this .id, obj) .click ( function () {
obj.hide ();
obj.show (). text (text_saved);
})
return false ;
});
});
};
}) (jQuery);
/ * case events * /
/ * Change Title of Rolic * /
$ ( 'a.editable' ) .each ( function () {
$ ( this ) .editable ({
url: "/ modules/Player/action_ajax.php" ,
actionx: “changeTitle” ,
id: $ ( this ) .attr ( 'title' ),
width: "250px"
});
});
/ * Change Position of Rolic * /
$ ( 'strong.editable' ) .each ( function () {
$ ( this ) .editable ({
url: "/ modules/Player/action_ajax.php" ,
actionx: “changePosition” ,
id: $ ( this ) .attr ( 'title' ), // original position
width: "20px"
});
});
$ ( '.rolicCell' ) .mouseover ( function () {$ ( this ) .addClass ( "highlight" )});
$ ( '.rolicCell' ) .moutout ( function () {$ ( this ) .removeClass ( "highlight" )});
});
* This source code was highlighted with Source Code Highlighter .
header ( 'Content-type: application / html; charset = "windows-1251"' , true );
die ($ newTitle);
$ newTitle = iconv ( 'UTF-8' , 'windows-1251' , $ newTitle); The rest principle to taste. You can use POST instead of GET, but you need to learn these details yourself.
Source: https://habr.com/ru/post/37169/
All Articles