2012-10-27 08:00:09 +00:00
//Couldn't use an associative array because javascript sorting is stupid http://dev-answers.blogspot.com/2012/03/javascript-object-keys-being-sorted-in.html
2012-11-16 08:00:21 +00:00
jQuery ( document ) . ready ( function ( $ ) {
var serialize = function ( ) {
var a = [ ] ;
$ ( '#sortable input' ) . each ( function ( ) {
a . push ( $ ( this ) . attr ( 'id' ) ) ;
} ) ;
$ ( '#sorthide' ) . val ( JSON . stringify ( a ) ) ;
2013-04-18 08:00:54 +00:00
} ;
2013-02-22 08:00:24 +00:00
2012-10-27 08:00:09 +00:00
serialize ( ) ;
2013-02-22 08:00:24 +00:00
2012-11-16 08:00:21 +00:00
$ ( '#sortable' )
. on ( 'click' , 'input' , function ( ) {
// the + converts the boolean to either 1 or 0
var c = + $ ( this ) . is ( ':checked' ) ,
old _id = $ ( this ) . attr ( 'id' ) ,
new _id = old _id . slice ( 0 , - 1 ) + c ;
$ ( this ) . attr ( 'id' , new _id ) ;
serialize ( ) ;
} )
. sortable ( {
placeholder : 'ui-state-highlight' ,
update : serialize
} ) ;
2013-02-22 08:00:24 +00:00
2012-11-16 08:00:21 +00:00
$ ( '#toggle_sortable' ) . click ( function ( e ) {
e . preventDefault ( ) ;
2013-04-18 08:00:54 +00:00
$ ( '#sortable_container' ) . slideToggle ( function ( ) {
2012-11-16 08:00:21 +00:00
$ ( '#toggle_sortable' ) . text ( $ ( this ) . is ( ':visible' ) ? 'Collapse' : 'Expand' ) ;
2013-04-18 08:00:54 +00:00
} ) ;
2012-10-27 08:00:09 +00:00
} ) ;
2013-02-22 08:00:24 +00:00
2012-11-16 08:00:21 +00:00
$ ( '#reset_sortable' ) . click ( function ( e ) {
e . preventDefault ( ) ;
2013-04-18 08:00:54 +00:00
$ ( '#sortable' ) . html ( sortable _list _default ) ; // var sortable_list_default is found on edit.php
serialize ( ) ;
2012-10-30 08:00:18 +00:00
} ) ;
2013-04-18 08:00:54 +00:00
} ) ;